📄 pci.c
字号:
* Inputs: N/A* Returns: true.*********************************************************************/bool pciDisableBrokenAgentDetection (PCI_HOST host){ unsigned int regData; GT_REG_READ (pci_arbiter_control[host], ®Data); regData = regData & 0xfffffffd; GT_REG_WRITE (pci_arbiter_control[host], regData); return true;}/********************************************************************* pciP2PConfig - This function set the PCI_n P2P configurate.* For more information on the P2P read PCI spec.** Inputs: unsigned int SecondBusLow - Secondery PCI interface Bus Range Lower* Boundry.* unsigned int SecondBusHigh - Secondry PCI interface Bus Range upper* Boundry.* unsigned int busNum - The CPI bus number to which the PCI interface* is connected.* unsigned int devNum - The PCI interface's device number.** Returns: true.*********************************************************************/bool pciP2PConfig (PCI_HOST host, unsigned int SecondBusLow, unsigned int SecondBusHigh, unsigned int busNum, unsigned int devNum){ unsigned int regData; regData = (SecondBusLow & 0xff) | ((SecondBusHigh & 0xff) << 8) | ((busNum & 0xff) << 16) | ((devNum & 0x1f) << 24); GT_REG_WRITE (pci_p2p_configuration[host], regData); return true;}/********************************************************************* pciSetRegionSnoopMode - This function modifys one of the 4 regions which* supports Cache Coherency in the PCI_n interface.* Inputs: region - One of the four regions.* snoopType - There is four optional Types:* 1. No Snoop.* 2. Snoop to WT region.* 3. Snoop to WB region.* 4. Snoop & Invalidate to WB region.* baseAddress - Base Address of this region.* regionLength - Region length.* Returns: false if one of the parameters is wrong otherwise return true.*********************************************************************/bool pciSetRegionSnoopMode (PCI_HOST host, PCI_SNOOP_REGION region, PCI_SNOOP_TYPE snoopType, unsigned int baseAddress, unsigned int regionLength){ unsigned int snoopXbaseAddress; unsigned int snoopXtopAddress; unsigned int data; unsigned int snoopHigh = baseAddress + regionLength; if ((region > PCI_SNOOP_REGION3) || (snoopType > PCI_SNOOP_WB)) return false; snoopXbaseAddress = pci_snoop_control_base_0_low[host] + 0x10 * region; snoopXtopAddress = pci_snoop_control_top_0[host] + 0x10 * region; if (regionLength == 0) { /* closing the region */ GT_REG_WRITE (snoopXbaseAddress, 0x0000ffff); GT_REG_WRITE (snoopXtopAddress, 0); return true; } baseAddress = baseAddress & 0xfff00000; /* Granularity of 1MByte */ data = (baseAddress >> 20) | snoopType << 12; GT_REG_WRITE (snoopXbaseAddress, data); snoopHigh = (snoopHigh & 0xfff00000) >> 20; GT_REG_WRITE (snoopXtopAddress, snoopHigh - 1); return true;}static int gt_read_config_dword (struct pci_controller *hose, pci_dev_t dev, int offset, u32 * value){ int bus = PCI_BUS (dev); if ((bus == local_buses[0]) || (bus == local_buses[1])) { *value = pciReadConfigReg ((PCI_HOST) hose->cfg_addr, offset, PCI_DEV (dev)); } else { *value = pciOverBridgeReadConfigReg ((PCI_HOST) hose-> cfg_addr, offset, PCI_DEV (dev), bus); } return 0;}static int gt_write_config_dword (struct pci_controller *hose, pci_dev_t dev, int offset, u32 value){ int bus = PCI_BUS (dev); if ((bus == local_buses[0]) || (bus == local_buses[1])) { pciWriteConfigReg ((PCI_HOST) hose->cfg_addr, offset, PCI_DEV (dev), value); } else { pciOverBridgeWriteConfigReg ((PCI_HOST) hose->cfg_addr, offset, PCI_DEV (dev), bus, value); } return 0;}static void gt_setup_ide (struct pci_controller *hose, pci_dev_t dev, struct pci_config_table *entry){ static const int ide_bar[] = { 8, 4, 8, 4, 0, 0 }; u32 bar_response, bar_value; int bar; for (bar = 0; bar < 6; bar++) { /*ronen different function for 3rd bank. */ unsigned int offset = (bar < 2) ? bar * 8 : 0x100 + (bar - 2) * 8; pci_hose_write_config_dword (hose, dev, PCI_BASE_ADDRESS_0 + offset, 0x0); pci_hose_read_config_dword (hose, dev, PCI_BASE_ADDRESS_0 + offset, &bar_response); pciauto_region_allocate (bar_response & PCI_BASE_ADDRESS_SPACE_IO ? hose-> pci_io : hose->pci_mem, ide_bar[bar], &bar_value); pci_hose_write_config_dword (hose, dev, PCI_BASE_ADDRESS_0 + bar * 4, bar_value); }}#ifdef CONFIG_USE_CPCIDVIstatic void gt_setup_cpcidvi (struct pci_controller *hose, pci_dev_t dev, struct pci_config_table *entry){ u32 bar_value, pci_response; pci_hose_read_config_dword (hose, dev, PCI_COMMAND, &pci_response); pci_hose_write_config_dword (hose, dev, PCI_BASE_ADDRESS_0, 0xffffffff); pci_hose_read_config_dword (hose, dev, PCI_BASE_ADDRESS_0, &pci_response); pciauto_region_allocate (hose->pci_mem, 0x01000000, &bar_value); pci_hose_write_config_dword (hose, dev, PCI_BASE_ADDRESS_0, (bar_value & 0xffffff00)); pci_hose_write_config_dword (hose, dev, PCI_ROM_ADDRESS, 0x0); pciauto_region_allocate (hose->pci_mem, 0x40000, &bar_value); pci_hose_write_config_dword (hose, dev, PCI_ROM_ADDRESS, (bar_value & 0xffffff00) | 0x01); gt_cpcidvi_rom.base = bar_value & 0xffffff00; gt_cpcidvi_rom.init = 1;}unsigned char gt_cpcidvi_in8(unsigned int offset){ unsigned char data; if (gt_cpcidvi_rom.init == 0) { return(0); } data = in8((offset & 0x04) + 0x3f000 + gt_cpcidvi_rom.base); return(data);}void gt_cpcidvi_out8(unsigned int offset, unsigned char data){ unsigned int off; if (gt_cpcidvi_rom.init == 0) { return; } off = data; off = ((off << 3) & 0x7f8) + (offset & 0x4) + 0x3e000 + gt_cpcidvi_rom.base; in8(off); return;}#endif/* TODO BJW: Change this for DB64360. This was pulled from the EV64260 *//* and is curently not called *. */#if 0static void gt_fixup_irq (struct pci_controller *hose, pci_dev_t dev){ unsigned char pin, irq; pci_read_config_byte (dev, PCI_INTERRUPT_PIN, &pin); if (pin == 1) { /* only allow INT A */ irq = pci_irq_swizzle[(PCI_HOST) hose-> cfg_addr][PCI_DEV (dev)]; if (irq) pci_write_config_byte (dev, PCI_INTERRUPT_LINE, irq); }}#endifstruct pci_config_table gt_config_table[] = {#ifdef CONFIG_USE_CPCIDVI {PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_69030, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, gt_setup_cpcidvi},#endif {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, gt_setup_ide}, {}};struct pci_controller pci0_hose = {/* fixup_irq: gt_fixup_irq, */ config_table:gt_config_table,};struct pci_controller pci1_hose = {/* fixup_irq: gt_fixup_irq, */ config_table:gt_config_table,};void pci_init_board (void){ unsigned int command;#ifdef CONFIG_PCI_PNP unsigned int bar;#endif#ifdef DEBUG gt_pci_bus_mode_display (PCI_HOST0);#endif#ifdef CONFIG_USE_CPCIDVI gt_cpcidvi_rom.init = 0; gt_cpcidvi_rom.base = 0;#endif pci0_hose.config_table = gt_config_table; pci1_hose.config_table = gt_config_table;#ifdef CONFIG_USE_CPCIDVI gt_config_table[0].config_device = gt_setup_cpcidvi;#endif gt_config_table[1].config_device = gt_setup_ide; pci0_hose.first_busno = 0; pci0_hose.last_busno = 0xff; local_buses[0] = pci0_hose.first_busno; /* PCI memory space */ pci_set_region (pci0_hose.regions + 0, CFG_PCI0_0_MEM_SPACE, CFG_PCI0_0_MEM_SPACE, CFG_PCI0_MEM_SIZE, PCI_REGION_MEM); /* PCI I/O space */ pci_set_region (pci0_hose.regions + 1, CFG_PCI0_IO_SPACE_PCI, CFG_PCI0_IO_SPACE, CFG_PCI0_IO_SIZE, PCI_REGION_IO); pci_set_ops (&pci0_hose, pci_hose_read_config_byte_via_dword, pci_hose_read_config_word_via_dword, gt_read_config_dword, pci_hose_write_config_byte_via_dword, pci_hose_write_config_word_via_dword, gt_write_config_dword); pci0_hose.region_count = 2; pci0_hose.cfg_addr = (unsigned int *) PCI_HOST0; pci_register_hose (&pci0_hose); pciArbiterEnable (PCI_HOST0); pciParkingDisable (PCI_HOST0, 1, 1, 1, 1, 1, 1, 1); command = pciReadConfigReg (PCI_HOST0, PCI_COMMAND, SELF); command |= PCI_COMMAND_MASTER; pciWriteConfigReg (PCI_HOST0, PCI_COMMAND, SELF, command); command = pciReadConfigReg (PCI_HOST0, PCI_COMMAND, SELF); command |= PCI_COMMAND_MEMORY; pciWriteConfigReg (PCI_HOST0, PCI_COMMAND, SELF, command);#ifdef CONFIG_PCI_PNP pciauto_config_init(&pci0_hose); pciauto_region_allocate(pci0_hose.pci_io, 0x400, &bar);#endif#ifdef CONFIG_PCI_SCAN_SHOW printf("PCI: Bus Dev VenId DevId Class Int\n");#endif pci0_hose.last_busno = pci_hose_scan_bus (&pci0_hose, pci0_hose.first_busno);#ifdef DEBUG gt_pci_bus_mode_display (PCI_HOST1);#endif pci1_hose.first_busno = pci0_hose.last_busno + 1; pci1_hose.last_busno = 0xff; pci1_hose.current_busno = pci1_hose.first_busno; local_buses[1] = pci1_hose.first_busno; /* PCI memory space */ pci_set_region (pci1_hose.regions + 0, CFG_PCI1_0_MEM_SPACE, CFG_PCI1_0_MEM_SPACE, CFG_PCI1_MEM_SIZE, PCI_REGION_MEM); /* PCI I/O space */ pci_set_region (pci1_hose.regions + 1, CFG_PCI1_IO_SPACE_PCI, CFG_PCI1_IO_SPACE, CFG_PCI1_IO_SIZE, PCI_REGION_IO); pci_set_ops (&pci1_hose, pci_hose_read_config_byte_via_dword, pci_hose_read_config_word_via_dword, gt_read_config_dword, pci_hose_write_config_byte_via_dword, pci_hose_write_config_word_via_dword, gt_write_config_dword); pci1_hose.region_count = 2; pci1_hose.cfg_addr = (unsigned int *) PCI_HOST1; pci_register_hose (&pci1_hose); pciArbiterEnable (PCI_HOST1); pciParkingDisable (PCI_HOST1, 1, 1, 1, 1, 1, 1, 1); command = pciReadConfigReg (PCI_HOST1, PCI_COMMAND, SELF); command |= PCI_COMMAND_MASTER; pciWriteConfigReg (PCI_HOST1, PCI_COMMAND, SELF, command);#ifdef CONFIG_PCI_PNP pciauto_config_init(&pci1_hose); pciauto_region_allocate(pci1_hose.pci_io, 0x400, &bar);#endif pci1_hose.last_busno = pci_hose_scan_bus (&pci1_hose, pci1_hose.first_busno); command = pciReadConfigReg (PCI_HOST1, PCI_COMMAND, SELF); command |= PCI_COMMAND_MEMORY; pciWriteConfigReg (PCI_HOST1, PCI_COMMAND, SELF, command);}#endif /* of CONFIG_PCI */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -