grub/grub-core/bus/pci.c

138 lines
3.4 KiB
C
Raw Normal View History

/* pci.c - Generic PCI interfaces. */
/*
* GRUB -- GRand Unified Bootloader
2010-01-03 Robert Millan <rmh.grub@aybabtu.com> * boot/i386/pc/boot.S: Update copyright year. * boot/i386/pc/cdboot.S: Likewise. * boot/i386/pc/diskboot.S: Likewise. * boot/i386/pc/lnxboot.S: Likewise. * boot/i386/pc/pxeboot.S: Likewise. * bus/pci.c: Likewise. * commands/cmp.c: Likewise. * commands/help.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/play.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/ls.c: Likewise. * commands/test.c: Likewise. * disk/dmraid_nvidia.c: Likewise. * disk/i386/pc/biosdisk.c: Likewise. * disk/ieee1275/nand.c: Likewise. * disk/ieee1275/ofdisk.c: Likewise. * disk/lvm.c: Likewise. * disk/raid.c: Likewise. * disk/raid6_recover.c: Likewise. * disk/scsi.c: Likewise. * fs/affs.c: Likewise. * fs/cpio.c: Likewise. * fs/ext2.c: Likewise. * fs/hfs.c: Likewise. * fs/iso9660.c: Likewise. * fs/ntfs.c: Likewise. * fs/sfs.c: Likewise. * fs/udf.c: Likewise. * fs/ufs.c: Likewise. * fs/xfs.c: Likewise. * gencmdlist.sh: Likewise. * genmk.rb: Likewise. * include/grub/disk.h: Likewise. * include/grub/efi/api.h: Likewise. * include/grub/efi/efi.h: Likewise. * include/grub/efi/pe32.h: Likewise. * include/grub/elf.h: Likewise. * include/grub/fs.h: Likewise. * include/grub/i386/at_keyboard.h: Likewise. * include/grub/i386/pc/memory.h: Likewise. * include/grub/i386/pc/vbe.h: Likewise. * include/grub/i386/pci.h: Likewise. * include/grub/i386/tsc.h: Likewise. * include/grub/ieee1275/ieee1275.h: Likewise. * include/grub/ntfs.h: Likewise. * include/grub/sparc64/ieee1275/ieee1275.h: Likewise. * include/grub/sparc64/libgcc.h: Likewise. * include/grub/symbol.h: Likewise. * include/grub/types.h: Likewise. * include/multiboot2.h: Likewise. * io/gzio.c: Likewise. * kern/device.c: Likewise. * kern/disk.c: Likewise. * kern/efi/efi.c: Likewise. * kern/efi/mm.c: Likewise. * kern/elf.c: Likewise. * kern/file.c: Likewise. * kern/i386/dl.c: Likewise. * kern/i386/pc/init.c: Likewise. * kern/i386/pc/startup.S: Likewise. * kern/ieee1275/ieee1275.c: Likewise. * kern/ieee1275/init.c: Likewise. * kern/main.c: Likewise. * kern/mm.c: Likewise. * kern/powerpc/dl.c: Likewise. * kern/sparc64/dl.c: Likewise. * kern/x86_64/dl.c: Likewise. * lib/hexdump.c: Likewise. * loader/efi/appleloader.c: Likewise. * loader/i386/ieee1275/linux.c: Likewise. * loader/i386/pc/chainloader.c: Likewise. * loader/i386/pc/linux.c: Likewise. * loader/i386/pc/multiboot2.c: Likewise. * loader/ieee1275/multiboot2.c: Likewise. * loader/multiboot2.c: Likewise. * loader/multiboot_loader.c: Likewise. * loader/powerpc/ieee1275/linux.c: Likewise. * normal/completion.c: Likewise. * normal/menu_entry.c: Likewise. * partmap/apple.c: Likewise. * util/grub.d/10_hurd.in: Likewise. * util/hostfs.c: Likewise. * video/readers/png.c: Likewise.
2010-01-03 22:05:07 +00:00
* Copyright (C) 2007,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/pci.h>
#include <grub/mm.h>
#include <grub/mm_private.h>
#include <grub/cache.h>
GRUB_MOD_LICENSE ("GPLv3+");
/* FIXME: correctly support 64-bit architectures. */
/* #if GRUB_TARGET_SIZEOF_VOID_P == 4 */
struct grub_pci_dma_chunk *
grub_memalign_dma32 (grub_size_t align, grub_size_t size)
{
void *ret = grub_memalign (align, size);
if (!ret)
return 0;
grub_arch_sync_dma_caches (ret, size);
return ret;
}
/* FIXME: evil. */
void
grub_dma_free (struct grub_pci_dma_chunk *ch)
{
grub_size_t size = (((struct grub_mm_header *) ch) - 1)->size * GRUB_MM_ALIGN;
grub_arch_sync_dma_caches (ch, size);
grub_free (ch);
}
/* #endif */
#ifdef GRUB_MACHINE_MIPS_YEELOONG
volatile void *
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
{
return (void *) ((((grub_uint32_t) ch) & 0x1fffffff) | 0xa0000000);
}
grub_uint32_t
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
{
return (((grub_uint32_t) ch) & 0x1fffffff) | 0x80000000;
}
#else
volatile void *
grub_dma_get_virt (struct grub_pci_dma_chunk *ch)
{
return (void *) ch;
}
grub_uint32_t
grub_dma_get_phys (struct grub_pci_dma_chunk *ch)
{
2010-06-02 Aleš Nesrsta <starous@volny.cz> Finally make USB usable. * bus/usb/ohci.c (grub_ohci_reg_t): Add missing values. (GRUB_OHCI_RHUB_PORT_POWER_MASK): New macro. (GRUB_OHCI_RHUB_PORT_ALL_POWERED): Likewise. (GRUB_OHCI_REG_FRAME_INTERVAL_FSMPS_MASK): Likewise. (GRUB_OHCI_REG_FRAME_INTERVAL_FSMPS_SHIFT): Likewise. (GRUB_OHCI_REG_FRAME_INTERVAL_FI_SHIFT): Likewise. (GRUB_OHCI_FSMPS): Likewise. (GRUB_OHCI_PERIODIC_START): Likewise. (GRUB_OHCI_FRAME_INTERVAL): Likewise. (GRUB_OHCI_SET_PORT_ENABLE): Likewise. (GRUB_OHCI_CLEAR_PORT_ENABLE): Likewise. (GRUB_OHCI_SET_PORT_RESET): Likewise. (GRUB_OHCI_SET_PORT_RESET_STATUS_CHANGE): Likewise. * bus/usb/ohci.c (grub_ohci_pci_iter): Various important fixups. (grub_ohci_transaction): Likewise. (grub_ohci_transfer): Improve condition detection algorithms. Handle toggle property. Program the transactions correctly. Improve error handling. Various important fixups. (grub_ohci_portstatus): Put register writes in right order. * bus/usb/uhci.c (grub_free_queue): Compute last_trans. (grub_uhci_transfer): Don't show "failed" message on success. * bus/usb/usb.c (grub_usb_set_configuration): Zero-fill whole "toggle" array. (grub_usb_device_initialize): Read first 8 bytes of descriptor to determine its size. * bus/usb/usbtrans.c (grub_usb_control_msg): Use descdev.maxsize0 even before initialization is completed. Use IN direction for empty transfers. Use last_trans and compute toggle. * include/grub/usbtrans.h (grub_usb_transfer): New field last_trans. (GRUB_USB_FEATURE_ENDP_HALT): Correct the value. (GRUB_USB_FEATURE_DEV_REMOTE_WU): Likewise. (GRUB_USB_FEATURE_TEST_MODE): Likewise. * include/grub/usb.h (grub_usb_err_t): New value GRUB_USB_ERR_UNRECOVERABLE. (grub_usb_device): Increase toggle to 256. (grub_usbms_subclass_t): New values GRUB_USBMS_SUBCLASS_RBC, GRUB_USBMS_SUBCLASS_MMC2, GRUB_USBMS_SUBCLASS_UFI and GRUB_USBMS_SUBCLASS_SFF8070. * include/grub/scsicmd.h (grub_scsi_test_unit_ready): New structure. (grub_scsi_inquiry): New member page and alloc_length. (grub_scsi_request_sense): New structure. (grub_scsi_request_sense_data): Likewise. (grub_scsi_read_capacity): New fields logical_block_addr, PMI and control. * disk/scsi.c (grub_scsi_request_sense): New function. (grub_scsi_test_unit_ready): Likewise. (grub_scsi_inquiry): Fill new fields. (grub_scsi_read_capacity): Likewise. (grub_scsi_read10): Add request sense at the end. (grub_scsi_read12): Likewise. (grub_scsi_write10): Likewise. (grub_scsi_write12): Likewise. (grub_scsi_open): Add Test Unit Ready. * disk/usbms.c (grub_usbms_finddevs): Check configcnt. Support additional subclasses. Con't clear halt yet. Activate the proper config. Calculate LUNs correctly. (grub_usbms_transfer): Various important fixups. 2010-06-02 Vladimir Serbinenko <phcoder@gmail.com> * bus/pci.c (grub_pci_iterate) [GRUB_MACHINE_MIPS_YEELOONG]: Skip ghosts. * bus/usb/ohci.c (grub_ohci_portstatus): Handle R/WC correctly. (grub_ohci_fini_hw): New function. (grub_ohci_restore_hw): Likewise. (GRUB_MOD_INIT(ohci)): Register preboot hook. (GRUB_MOD_FINI(ohci)): Shutdown OHCI. * term/usb_keyboard.c: Remove include of grub/machine/console.h. 2010-06-02 Vladimir Serbinenko <phcoder@gmail.com> Dedicated DMA allocations. * bus/pci.c (grub_memalign_dma32): New function (grub_dma_free): Likewise. (grub_dma_get_virt): Likewise. (grub_dma_get_phys): Likewise. * bus/usb/ohci.c (grub_ohci): New members hcca_addr and hcca_chunk. (grub_ohci_pci_iter): Use dma32_alloc. (grub_ohci_transfer): Likewise. * bus/usb/usbtrans.c (grub_usb_control_msg): Likewise. (grub_usb_bulk_readwrite): Likewise. * include/grub/pci.h: Add declarations. 2010-06-02 Vladimir Serbinenko <phcoder@gmail.com> CS5536 support. * bus/cs5536.c: New file. * bus/usb/ohci.c (grub_ohci_pci_iter): Check for CS5536. * conf/i386.rmk (pkglib_MODULES): Add cs5536.mod. (cs5536_mod_SOURCES): New variable. (cs5536_mod_CFLAGS): Likewise. (cs5536_mod_LDFLAGS): Likewise. * conf/mips-yeeloong.rmk (kernel_img_HEADERS): Add cs5536.h and machine/pci.h. (kernel_img_SOURCES): Add bus/cs5536.c. (pkglib_MODULES): Add usb.mod, usbtest.mod, ohci.mod, usbms.mod and usb_keyboard.mod. (usb_mod_SOURCES): New variable. (usb_mod_CFLAGS): New variable. (usb_mod_LDFLAGS): New variable. (usbtest_mod_SOURCES): New variable. (usbtest_mod_CFLAGS): New variable. (usbtest_mod_LDFLAGS): New variable. (ohci_mod_SOURCES): New variable. (ohci_mod_CFLAGS): New variable. (ohci_mod_LDFLAGS): New variable. (usbms_mod_SOURCES): New variable. (usbms_mod_CFLAGS): New variable. (usbms_mod_LDFLAGS): New variable. (usb_keyboard_mod_SOURCES): New variable. (usb_keyboard_mod_CFLAGS): New variable. (usb_keyboard_mod_LDFLAGS): New variable. * include/grub/smbus.h: New file. * include/grub/cs5536.h: New file. Also-By: Vladimir Serbinenko <phcoder@gmail.com>
2010-06-02 15:16:20 +00:00
return (grub_uint32_t) (grub_addr_t) ch;
}
#endif
grub_pci_address_t
2009-10-14 08:11:59 +00:00
grub_pci_make_address (grub_pci_device_t dev, int reg)
{
2009-10-14 08:11:59 +00:00
return (1 << 31) | (dev.bus << 16) | (dev.device << 11)
2009-12-22 14:09:25 +00:00
| (dev.function << 8) | reg;
}
void
grub_pci_iterate (grub_pci_iteratefunc_t hook)
{
2009-10-14 08:11:59 +00:00
grub_pci_device_t dev;
grub_pci_address_t addr;
grub_pci_id_t id;
grub_uint32_t hdr;
2009-11-02 22:42:07 +00:00
for (dev.bus = 0; dev.bus < GRUB_PCI_NUM_BUS; dev.bus++)
{
2009-11-02 22:42:07 +00:00
for (dev.device = 0; dev.device < GRUB_PCI_NUM_DEVICES; dev.device++)
{
2009-10-14 08:11:59 +00:00
for (dev.function = 0; dev.function < 8; dev.function++)
{
2009-12-22 14:09:25 +00:00
addr = grub_pci_make_address (dev, GRUB_PCI_REG_PCI_ID);
id = grub_pci_read (addr);
/* Check if there is a device present. */
if (id >> 16 == 0xFFFF)
{
if (dev.function == 0)
/* Devices are required to implement function 0, so if
it's missing then there is no device here. */
break;
else
continue;
}
#ifdef GRUB_MACHINE_MIPS_YEELOONG
/* Skip ghosts. */
if (id == GRUB_YEELOONG_OHCI_PCIID
&& dev.function == GRUB_YEELOONG_OHCI_GHOST_FUNCTION)
continue;
if (id == GRUB_YEELOONG_EHCI_PCIID
&& dev.function == GRUB_YEELOONG_EHCI_GHOST_FUNCTION)
continue;
#endif
2009-10-14 08:11:59 +00:00
if (hook (dev, id))
return;
/* Probe only func = 0 if the device if not multifunction */
2009-10-14 08:11:59 +00:00
if (dev.function == 0)
{
2009-12-22 14:09:25 +00:00
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CACHELINE);
hdr = grub_pci_read (addr);
if (!(hdr & 0x800000))
break;
}
}
}
}
}