Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:57

0001 /* PCI Initialization */
0002 
0003 /*
0004  * Authorship
0005  * ----------
0006  * This software ('mvme3100' RTEMS BSP) was created by
0007  *
0008  *     Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
0009  *     Stanford Linear Accelerator Center, Stanford University.
0010  *
0011  * Acknowledgement of sponsorship
0012  * ------------------------------
0013  * The 'mvme3100' BSP was produced by
0014  *     the Stanford Linear Accelerator Center, Stanford University,
0015  *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
0016  *
0017  * Government disclaimer of liability
0018  * ----------------------------------
0019  * Neither the United States nor the United States Department of Energy,
0020  * nor any of their employees, makes any warranty, express or implied, or
0021  * assumes any legal liability or responsibility for the accuracy,
0022  * completeness, or usefulness of any data, apparatus, product, or process
0023  * disclosed, or represents that its use would not infringe privately owned
0024  * rights.
0025  *
0026  * Stanford disclaimer of liability
0027  * --------------------------------
0028  * Stanford University makes no representations or warranties, express or
0029  * implied, nor assumes any liability for the use of this software.
0030  *
0031  * Stanford disclaimer of copyright
0032  * --------------------------------
0033  * Stanford University, owner of the copyright, hereby disclaims its
0034  * copyright and all other rights in this software.  Hence, anyone may
0035  * freely use it for any purpose without restriction.
0036  *
0037  * Maintenance of notices
0038  * ----------------------
0039  * In the interest of clarity regarding the origin and status of this
0040  * SLAC software, this and all the preceding Stanford University notices
0041  * are to remain affixed to any copy or derivative of this software made
0042  * or distributed by the recipient and are to be affixed to any copy of
0043  * software made or distributed by the recipient that contains a copy or
0044  * derivative of this software.
0045  *
0046  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
0047  */
0048 
0049 #include <bsp.h>
0050 #include <bsp/pci.h>
0051 #include <bsp/irq.h>
0052 #include <bsp/openpic.h>
0053 #include <inttypes.h>
0054 
0055 /* Motload configures PCI interrupts to start at 16 and up but
0056  * we'd rather have them starting at 0.
0057  * Use this callback to fix them up.
0058  */
0059 static int
0060 fixup_irq_line(int bus, int slot, int fun, void *uarg)
0061 {
0062 unsigned char line;
0063     pci_read_config_byte( bus, slot, fun, PCI_INTERRUPT_LINE, &line);
0064     if ( line >= BSP_EXT_IRQ_NUMBER ) {
0065         pci_write_config_byte( bus, slot, fun, PCI_INTERRUPT_LINE, line - BSP_EXT_IRQ_NUMBER );
0066     }
0067 
0068     return 0;
0069 }
0070 
0071 void BSP_motload_pci_fixup(void)
0072 {
0073   BSP_pciScan(0, fixup_irq_line, 0);
0074 }
0075 
0076 void detect_host_bridge(void)
0077 {
0078   OpenPIC = (volatile struct OpenPIC *) (BSP_8540_CCSR_BASE + BSP_OPEN_PIC_BASE_OFFSET);
0079 }
0080 
0081 static int
0082 dump_dev_cb(
0083    int bus,
0084    int dev,
0085    int fun,
0086    void *uarg
0087 )
0088 {
0089   uint16_t vi,di;
0090   uint16_t cd,st;
0091   uint32_t b1,b2;
0092   uint8_t  il,ip;
0093 
0094     pci_read_config_word (bus, dev, fun, PCI_VENDOR_ID,      &vi);
0095     pci_read_config_word (bus, dev, fun, PCI_DEVICE_ID,      &di);
0096     pci_read_config_word (bus, dev, fun, PCI_COMMAND,        &cd);
0097     pci_read_config_word (bus, dev, fun, PCI_STATUS,         &st);
0098     pci_read_config_dword(bus, dev, fun, PCI_BASE_ADDRESS_0, &b1);
0099     pci_read_config_dword(bus, dev, fun, PCI_BASE_ADDRESS_1, &b2);
0100     pci_read_config_byte (bus, dev, fun, PCI_INTERRUPT_LINE, &il);
0101     pci_read_config_byte (bus, dev, fun, PCI_INTERRUPT_PIN,  &ip);
0102 
0103     printk("%3d:0x%02x:%d    0x%04x-0x%04x:  0x%04x 0x%04x 0x%08" PRIx32 " 0x%08" PRIx32 "       %d -> %3d (=0x%02x)\n",
0104         bus, dev, fun, vi, di, cd, st, b1, b2, ip, il, il);
0105     return 0;
0106 }
0107 
0108 void
0109 BSP_pciConfigDump_early(void)
0110 {
0111     printk("BUS:SLOT:FUN  VENDOR-DEV_ID: COMMAND STATUS BASE_ADDR0 BASE_ADDR1 IRQ_PIN -> IRQ_LINE\n");
0112     BSP_pciScan(0, dump_dev_cb, 0);
0113 }