Subversion Repositories Kolibri OS

Rev

Rev 1404 | Rev 1963 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <ddk.h>
  3. #include <linux/kernel.h>
  4. #include <errno-base.h>
  5. #include <linux/mutex.h>
  6. #include <pci.h>
  7. #include <syscall.h>
  8.  
  9. static LIST_HEAD(devices);
  10.  
  11. static pci_dev_t* pci_scan_device(u32_t bus, int devfn);
  12.  
  13.  
  14. /* PCI control bits.  Shares IORESOURCE_BITS with above PCI ROM.  */
  15. #define IORESOURCE_PCI_FIXED            (1<<4)  /* Do not move resource */
  16.  
  17. #define LEGACY_IO_RESOURCE      (IORESOURCE_IO | IORESOURCE_PCI_FIXED)
  18.  
  19. /*
  20.  * Translate the low bits of the PCI base
  21.  * to the resource type
  22.  */
  23. static inline unsigned int pci_calc_resource_flags(unsigned int flags)
  24. {
  25.     if (flags & PCI_BASE_ADDRESS_SPACE_IO)
  26.         return IORESOURCE_IO;
  27.  
  28.     if (flags & PCI_BASE_ADDRESS_MEM_PREFETCH)
  29.         return IORESOURCE_MEM | IORESOURCE_PREFETCH;
  30.  
  31.     return IORESOURCE_MEM;
  32. }
  33.  
  34.  
  35. static u32_t pci_size(u32_t base, u32_t maxbase, u32_t mask)
  36. {
  37.     u32_t size = mask & maxbase;      /* Find the significant bits */
  38.  
  39.     if (!size)
  40.         return 0;
  41.  
  42.     /* Get the lowest of them to find the decode size, and
  43.        from that the extent.  */
  44.     size = (size & ~(size-1)) - 1;
  45.  
  46.     /* base == maxbase can be valid only if the BAR has
  47.        already been programmed with all 1s.  */
  48.     if (base == maxbase && ((base | size) & mask) != mask)
  49.         return 0;
  50.  
  51.     return size;
  52. }
  53.  
  54. static u64_t pci_size64(u64_t base, u64_t maxbase, u64_t mask)
  55. {
  56.     u64_t size = mask & maxbase;      /* Find the significant bits */
  57.  
  58.     if (!size)
  59.         return 0;
  60.  
  61.     /* Get the lowest of them to find the decode size, and
  62.        from that the extent.  */
  63.     size = (size & ~(size-1)) - 1;
  64.  
  65.     /* base == maxbase can be valid only if the BAR has
  66.        already been programmed with all 1s.  */
  67.     if (base == maxbase && ((base | size) & mask) != mask)
  68.         return 0;
  69.  
  70.     return size;
  71. }
  72.  
  73. static inline int is_64bit_memory(u32_t mask)
  74. {
  75.     if ((mask & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK)) ==
  76.         (PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64))
  77.         return 1;
  78.     return 0;
  79. }
  80.  
  81. static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
  82. {
  83.     u32_t  pos, reg, next;
  84.     u32_t  l, sz;
  85.     struct resource *res;
  86.  
  87.     for(pos=0; pos < howmany; pos = next)
  88.     {
  89.         u64_t  l64;
  90.         u64_t  sz64;
  91.         u32_t  raw_sz;
  92.  
  93.         next = pos + 1;
  94.  
  95.         res  = &dev->resource[pos];
  96.  
  97.         reg = PCI_BASE_ADDRESS_0 + (pos << 2);
  98.         l = PciRead32(dev->busnr, dev->devfn, reg);
  99.         PciWrite32(dev->busnr, dev->devfn, reg, ~0);
  100.         sz = PciRead32(dev->busnr, dev->devfn, reg);
  101.         PciWrite32(dev->busnr, dev->devfn, reg, l);
  102.  
  103.         if (!sz || sz == 0xffffffff)
  104.             continue;
  105.  
  106.         if (l == 0xffffffff)
  107.             l = 0;
  108.  
  109.         raw_sz = sz;
  110.         if ((l & PCI_BASE_ADDRESS_SPACE) ==
  111.                         PCI_BASE_ADDRESS_SPACE_MEMORY)
  112.         {
  113.             sz = pci_size(l, sz, (u32_t)PCI_BASE_ADDRESS_MEM_MASK);
  114.             /*
  115.              * For 64bit prefetchable memory sz could be 0, if the
  116.              * real size is bigger than 4G, so we need to check
  117.              * szhi for that.
  118.              */
  119.             if (!is_64bit_memory(l) && !sz)
  120.                     continue;
  121.             res->start = l & PCI_BASE_ADDRESS_MEM_MASK;
  122.             res->flags |= l & ~PCI_BASE_ADDRESS_MEM_MASK;
  123.         }
  124.         else {
  125.             sz = pci_size(l, sz, PCI_BASE_ADDRESS_IO_MASK & 0xffff);
  126.             if (!sz)
  127.                 continue;
  128.             res->start = l & PCI_BASE_ADDRESS_IO_MASK;
  129.             res->flags |= l & ~PCI_BASE_ADDRESS_IO_MASK;
  130.         }
  131.         res->end = res->start + (unsigned long) sz;
  132.         res->flags |= pci_calc_resource_flags(l);
  133.         if (is_64bit_memory(l))
  134.         {
  135.             u32_t szhi, lhi;
  136.  
  137.             lhi = PciRead32(dev->busnr, dev->devfn, reg+4);
  138.             PciWrite32(dev->busnr, dev->devfn, reg+4, ~0);
  139.             szhi = PciRead32(dev->busnr, dev->devfn, reg+4);
  140.             PciWrite32(dev->busnr, dev->devfn, reg+4, lhi);
  141.             sz64 = ((u64_t)szhi << 32) | raw_sz;
  142.             l64 = ((u64_t)lhi << 32) | l;
  143.             sz64 = pci_size64(l64, sz64, PCI_BASE_ADDRESS_MEM_MASK);
  144.             next++;
  145.  
  146. #if BITS_PER_LONG == 64
  147.             if (!sz64) {
  148.                 res->start = 0;
  149.                 res->end = 0;
  150.                 res->flags = 0;
  151.                 continue;
  152.             }
  153.             res->start = l64 & PCI_BASE_ADDRESS_MEM_MASK;
  154.             res->end = res->start + sz64;
  155. #else
  156.             if (sz64 > 0x100000000ULL) {
  157.                 printk(KERN_ERR "PCI: Unable to handle 64-bit "
  158.                                 "BAR for device %s\n", pci_name(dev));
  159.                 res->start = 0;
  160.                 res->flags = 0;
  161.             }
  162.             else if (lhi)
  163.             {
  164.                 /* 64-bit wide address, treat as disabled */
  165.                 PciWrite32(dev->busnr, dev->devfn, reg,
  166.                         l & ~(u32_t)PCI_BASE_ADDRESS_MEM_MASK);
  167.                 PciWrite32(dev->busnr, dev->devfn, reg+4, 0);
  168.                 res->start = 0;
  169.                 res->end = sz;
  170.             }
  171. #endif
  172.         }
  173.     }
  174.  
  175.     if ( rom )
  176.     {
  177.         dev->rom_base_reg = rom;
  178.         res = &dev->resource[PCI_ROM_RESOURCE];
  179.  
  180.         l = PciRead32(dev->busnr, dev->devfn, rom);
  181.         PciWrite32(dev->busnr, dev->devfn, rom, ~PCI_ROM_ADDRESS_ENABLE);
  182.         sz = PciRead32(dev->busnr, dev->devfn, rom);
  183.         PciWrite32(dev->busnr, dev->devfn, rom, l);
  184.  
  185.         if (l == 0xffffffff)
  186.             l = 0;
  187.  
  188.         if (sz && sz != 0xffffffff)
  189.         {
  190.             sz = pci_size(l, sz, (u32_t)PCI_ROM_ADDRESS_MASK);
  191.  
  192.             if (sz)
  193.             {
  194.                 res->flags = (l & IORESOURCE_ROM_ENABLE) |
  195.                                   IORESOURCE_MEM | IORESOURCE_PREFETCH |
  196.                                   IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
  197.                 res->start = l & PCI_ROM_ADDRESS_MASK;
  198.                 res->end = res->start + (unsigned long) sz;
  199.             }
  200.         }
  201.     }
  202. }
  203.  
  204. static void pci_read_irq(struct pci_dev *dev)
  205. {
  206.     u8_t irq;
  207.  
  208.     irq = PciRead8(dev->busnr, dev->devfn, PCI_INTERRUPT_PIN);
  209.     dev->pin = irq;
  210.     if (irq)
  211.         PciRead8(dev->busnr, dev->devfn, PCI_INTERRUPT_LINE);
  212.     dev->irq = irq;
  213. };
  214.  
  215.  
  216. static int pci_setup_device(struct pci_dev *dev)
  217. {
  218.     u32_t  class;
  219.  
  220.     class = PciRead32(dev->busnr, dev->devfn, PCI_CLASS_REVISION);
  221.     dev->revision = class & 0xff;
  222.     class >>= 8;                                /* upper 3 bytes */
  223.     dev->class = class;
  224.  
  225.     /* "Unknown power state" */
  226. //    dev->current_state = PCI_UNKNOWN;
  227.  
  228.     /* Early fixups, before probing the BARs */
  229.  //   pci_fixup_device(pci_fixup_early, dev);
  230.     class = dev->class >> 8;
  231.  
  232.     switch (dev->hdr_type)
  233.     {
  234.         case PCI_HEADER_TYPE_NORMAL:                /* standard header */
  235.             if (class == PCI_CLASS_BRIDGE_PCI)
  236.                 goto bad;
  237.             pci_read_irq(dev);
  238.             pci_read_bases(dev, 6, PCI_ROM_ADDRESS);
  239.             dev->subsystem_vendor = PciRead16(dev->busnr, dev->devfn,PCI_SUBSYSTEM_VENDOR_ID);
  240.             dev->subsystem_device = PciRead16(dev->busnr, dev->devfn, PCI_SUBSYSTEM_ID);
  241.  
  242.             /*
  243.              *      Do the ugly legacy mode stuff here rather than broken chip
  244.              *      quirk code. Legacy mode ATA controllers have fixed
  245.              *      addresses. These are not always echoed in BAR0-3, and
  246.              *      BAR0-3 in a few cases contain junk!
  247.              */
  248.             if (class == PCI_CLASS_STORAGE_IDE)
  249.             {
  250.                 u8_t progif;
  251.  
  252.                 progif = PciRead8(dev->busnr, dev->devfn,PCI_CLASS_PROG);
  253.                 if ((progif & 1) == 0)
  254.                 {
  255.                     dev->resource[0].start = 0x1F0;
  256.                     dev->resource[0].end = 0x1F7;
  257.                     dev->resource[0].flags = LEGACY_IO_RESOURCE;
  258.                     dev->resource[1].start = 0x3F6;
  259.                     dev->resource[1].end = 0x3F6;
  260.                     dev->resource[1].flags = LEGACY_IO_RESOURCE;
  261.                 }
  262.                 if ((progif & 4) == 0)
  263.                 {
  264.                     dev->resource[2].start = 0x170;
  265.                     dev->resource[2].end = 0x177;
  266.                     dev->resource[2].flags = LEGACY_IO_RESOURCE;
  267.                     dev->resource[3].start = 0x376;
  268.                     dev->resource[3].end = 0x376;
  269.                     dev->resource[3].flags = LEGACY_IO_RESOURCE;
  270.                 };
  271.             }
  272.             break;
  273.  
  274.         case PCI_HEADER_TYPE_BRIDGE:                /* bridge header */
  275.                 if (class != PCI_CLASS_BRIDGE_PCI)
  276.                         goto bad;
  277.                 /* The PCI-to-PCI bridge spec requires that subtractive
  278.                    decoding (i.e. transparent) bridge must have programming
  279.                    interface code of 0x01. */
  280.                 pci_read_irq(dev);
  281.                 dev->transparent = ((dev->class & 0xff) == 1);
  282.                 pci_read_bases(dev, 2, PCI_ROM_ADDRESS1);
  283.                 break;
  284.  
  285.         case PCI_HEADER_TYPE_CARDBUS:               /* CardBus bridge header */
  286.                 if (class != PCI_CLASS_BRIDGE_CARDBUS)
  287.                         goto bad;
  288.                 pci_read_irq(dev);
  289.                 pci_read_bases(dev, 1, 0);
  290.                 dev->subsystem_vendor = PciRead16(dev->busnr,
  291.                                                   dev->devfn,
  292.                                                   PCI_CB_SUBSYSTEM_VENDOR_ID);
  293.  
  294.                 dev->subsystem_device = PciRead16(dev->busnr,
  295.                                                   dev->devfn,
  296.                                                   PCI_CB_SUBSYSTEM_ID);
  297.                 break;
  298.  
  299.         default:                                    /* unknown header */
  300.                 printk(KERN_ERR "PCI: device %s has unknown header type %02x, ignoring.\n",
  301.                         pci_name(dev), dev->hdr_type);
  302.                 return -1;
  303.  
  304.         bad:
  305.                 printk(KERN_ERR "PCI: %s: class %x doesn't match header type %02x. Ignoring class.\n",
  306.                        pci_name(dev), class, dev->hdr_type);
  307.                 dev->class = PCI_CLASS_NOT_DEFINED;
  308.     }
  309.  
  310.     /* We found a fine healthy device, go go go... */
  311.  
  312.     return 0;
  313. };
  314.  
  315. static pci_dev_t* pci_scan_device(u32_t bus, int devfn)
  316. {
  317.     pci_dev_t  *dev;
  318.  
  319.     u32_t   id;
  320.     u8_t    hdr;
  321.  
  322.     int     timeout = 10;
  323.  
  324.     id = PciRead32(bus,devfn, PCI_VENDOR_ID);
  325.  
  326.     /* some broken boards return 0 or ~0 if a slot is empty: */
  327.     if (id == 0xffffffff || id == 0x00000000 ||
  328.         id == 0x0000ffff || id == 0xffff0000)
  329.         return NULL;
  330.  
  331.     while (id == 0xffff0001)
  332.     {
  333.  
  334.         delay(timeout/10);
  335.         timeout *= 2;
  336.  
  337.         id = PciRead32(bus, devfn, PCI_VENDOR_ID);
  338.  
  339.         /* Card hasn't responded in 60 seconds?  Must be stuck. */
  340.         if (timeout > 60 * 100)
  341.         {
  342.             printk(KERN_WARNING "Device %04x:%02x:%02x.%d not "
  343.                    "responding\n", bus,PCI_SLOT(devfn),PCI_FUNC(devfn));
  344.             return NULL;
  345.         }
  346.     };
  347.  
  348.     hdr = PciRead8(bus, devfn, PCI_HEADER_TYPE);
  349.  
  350.     dev = (pci_dev_t*)kzalloc(sizeof(pci_dev_t), 0);
  351.  
  352.     INIT_LIST_HEAD(&dev->link);
  353.  
  354.     if(unlikely(dev == NULL))
  355.         return NULL;
  356.  
  357.     dev->pci_dev.busnr      = bus;
  358.     dev->pci_dev.devfn    = devfn;
  359.     dev->pci_dev.hdr_type = hdr & 0x7f;
  360.     dev->pci_dev.multifunction    = !!(hdr & 0x80);
  361.     dev->pci_dev.vendor   = id & 0xffff;
  362.     dev->pci_dev.device   = (id >> 16) & 0xffff;
  363.  
  364.     pci_setup_device(&dev->pci_dev);
  365.  
  366.     return dev;
  367.  
  368. };
  369.  
  370. int pci_scan_slot(u32_t bus, int devfn)
  371. {
  372.     int  func, nr = 0;
  373.  
  374.     for (func = 0; func < 8; func++, devfn++)
  375.     {
  376.         pci_dev_t  *dev;
  377.  
  378.         dev = pci_scan_device(bus, devfn);
  379.         if( dev )
  380.         {
  381.             list_add(&dev->link, &devices);
  382.  
  383.             nr++;
  384.  
  385.             /*
  386.              * If this is a single function device,
  387.              * don't scan past the first function.
  388.              */
  389.             if (!dev->pci_dev.multifunction)
  390.             {
  391.                 if (func > 0) {
  392.                     dev->pci_dev.multifunction = 1;
  393.                 }
  394.                 else {
  395.                     break;
  396.                 }
  397.              }
  398.         }
  399.         else {
  400.             if (func == 0)
  401.                 break;
  402.         }
  403.     };
  404.  
  405.     return nr;
  406. };
  407.  
  408.  
  409. void pci_scan_bus(u32_t bus)
  410. {
  411.     u32_t devfn;
  412.     pci_dev_t *dev;
  413.  
  414.  
  415.     for (devfn = 0; devfn < 0x100; devfn += 8)
  416.         pci_scan_slot(bus, devfn);
  417.  
  418. }
  419.  
  420. int enum_pci_devices()
  421. {
  422.     pci_dev_t  *dev;
  423.     u32_t       last_bus;
  424.     u32_t       bus = 0 , devfn = 0;
  425.  
  426.   //  list_initialize(&devices);
  427.  
  428.     last_bus = PciApi(1);
  429.  
  430.  
  431.     if( unlikely(last_bus == -1))
  432.         return -1;
  433.  
  434.     for(;bus <= last_bus; bus++)
  435.         pci_scan_bus(bus);
  436.  
  437. //    for(dev = (dev_t*)devices.next;
  438. //        &dev->link != &devices;
  439. //        dev = (dev_t*)dev->link.next)
  440. //    {
  441. //        dbgprintf("PCI device %x:%x bus:%x devfn:%x\n",
  442. //                dev->pci_dev.vendor,
  443. //                dev->pci_dev.device,
  444. //                dev->pci_dev.bus,
  445. //                dev->pci_dev.devfn);
  446. //
  447. //    }
  448.     return 0;
  449. }
  450.  
  451. #define PCI_FIND_CAP_TTL    48
  452.  
  453. static int __pci_find_next_cap_ttl(unsigned int bus, unsigned int devfn,
  454.                    u8 pos, int cap, int *ttl)
  455. {
  456.     u8 id;
  457.  
  458.     while ((*ttl)--) {
  459.         pos = PciRead8(bus, devfn, pos);
  460.         if (pos < 0x40)
  461.             break;
  462.         pos &= ~3;
  463.         id = PciRead8(bus, devfn, pos + PCI_CAP_LIST_ID);
  464.         if (id == 0xff)
  465.             break;
  466.         if (id == cap)
  467.             return pos;
  468.         pos += PCI_CAP_LIST_NEXT;
  469.     }
  470.     return 0;
  471. }
  472.  
  473. static int __pci_find_next_cap(unsigned int bus, unsigned int devfn,
  474.                    u8 pos, int cap)
  475. {
  476.     int ttl = PCI_FIND_CAP_TTL;
  477.  
  478.     return __pci_find_next_cap_ttl(bus, devfn, pos, cap, &ttl);
  479. }
  480.  
  481. static int __pci_bus_find_cap_start(unsigned int bus,
  482.                     unsigned int devfn, u8 hdr_type)
  483. {
  484.     u16 status;
  485.  
  486.     status = PciRead16(bus, devfn, PCI_STATUS);
  487.     if (!(status & PCI_STATUS_CAP_LIST))
  488.         return 0;
  489.  
  490.     switch (hdr_type) {
  491.     case PCI_HEADER_TYPE_NORMAL:
  492.     case PCI_HEADER_TYPE_BRIDGE:
  493.         return PCI_CAPABILITY_LIST;
  494.     case PCI_HEADER_TYPE_CARDBUS:
  495.         return PCI_CB_CAPABILITY_LIST;
  496.     default:
  497.         return 0;
  498.     }
  499.  
  500.     return 0;
  501. }
  502.  
  503.  
  504. int pci_find_capability(struct pci_dev *dev, int cap)
  505. {
  506.     int pos;
  507.  
  508.     pos = __pci_bus_find_cap_start(dev->busnr, dev->devfn, dev->hdr_type);
  509.     if (pos)
  510.         pos = __pci_find_next_cap(dev->busnr, dev->devfn, pos, cap);
  511.  
  512.     return pos;
  513. }
  514.  
  515.  
  516.  
  517. int pcibios_enable_resources(struct pci_dev *dev, int mask)
  518. {
  519.     u16_t cmd, old_cmd;
  520.     int  idx;
  521.     struct resource *r;
  522.  
  523.     cmd = PciRead16(dev->busnr, dev->devfn, PCI_COMMAND);
  524.     old_cmd = cmd;
  525.     for (idx = 0; idx < PCI_NUM_RESOURCES; idx++)
  526.     {
  527.         /* Only set up the requested stuff */
  528.         if (!(mask & (1 << idx)))
  529.                 continue;
  530.  
  531.         r = &dev->resource[idx];
  532.         if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
  533.                 continue;
  534.         if ((idx == PCI_ROM_RESOURCE) &&
  535.                         (!(r->flags & IORESOURCE_ROM_ENABLE)))
  536.                 continue;
  537.         if (!r->start && r->end) {
  538.                 printk(KERN_ERR "PCI: Device %s not available "
  539.                         "because of resource %d collisions\n",
  540.                         pci_name(dev), idx);
  541.                 return -EINVAL;
  542.         }
  543.         if (r->flags & IORESOURCE_IO)
  544.                 cmd |= PCI_COMMAND_IO;
  545.         if (r->flags & IORESOURCE_MEM)
  546.                 cmd |= PCI_COMMAND_MEMORY;
  547.     }
  548.     if (cmd != old_cmd) {
  549.         printk("PCI: Enabling device %s (%04x -> %04x)\n",
  550.                 pci_name(dev), old_cmd, cmd);
  551.         PciWrite16(dev->busnr, dev->devfn, PCI_COMMAND, cmd);
  552.     }
  553.     return 0;
  554. }
  555.  
  556.  
  557. int pcibios_enable_device(struct pci_dev *dev, int mask)
  558. {
  559.         int err;
  560.  
  561.         if ((err = pcibios_enable_resources(dev, mask)) < 0)
  562.                 return err;
  563.  
  564. //        if (!dev->msi_enabled)
  565. //                return pcibios_enable_irq(dev);
  566.         return 0;
  567. }
  568.  
  569.  
  570. static int do_pci_enable_device(struct pci_dev *dev, int bars)
  571. {
  572.         int err;
  573.  
  574. //        err = pci_set_power_state(dev, PCI_D0);
  575. //        if (err < 0 && err != -EIO)
  576. //                return err;
  577.         err = pcibios_enable_device(dev, bars);
  578. //        if (err < 0)
  579. //                return err;
  580. //        pci_fixup_device(pci_fixup_enable, dev);
  581.  
  582.         return 0;
  583. }
  584.  
  585.  
  586. static int __pci_enable_device_flags(struct pci_dev *dev,
  587.                                      resource_size_t flags)
  588. {
  589.         int err;
  590.         int i, bars = 0;
  591.  
  592. //        if (atomic_add_return(1, &dev->enable_cnt) > 1)
  593. //                return 0;               /* already enabled */
  594.  
  595.         for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
  596.                 if (dev->resource[i].flags & flags)
  597.                         bars |= (1 << i);
  598.  
  599.         err = do_pci_enable_device(dev, bars);
  600. //        if (err < 0)
  601. //                atomic_dec(&dev->enable_cnt);
  602.         return err;
  603. }
  604.  
  605.  
  606. /**
  607.  * pci_enable_device - Initialize device before it's used by a driver.
  608.  * @dev: PCI device to be initialized
  609.  *
  610.  *  Initialize device before it's used by a driver. Ask low-level code
  611.  *  to enable I/O and memory. Wake up the device if it was suspended.
  612.  *  Beware, this function can fail.
  613.  *
  614.  *  Note we don't actually enable the device many times if we call
  615.  *  this function repeatedly (we just increment the count).
  616.  */
  617. int pci_enable_device(struct pci_dev *dev)
  618. {
  619.         return __pci_enable_device_flags(dev, IORESOURCE_MEM | IORESOURCE_IO);
  620. }
  621.  
  622.  
  623.  
  624. struct pci_device_id* find_pci_device(pci_dev_t* pdev, struct pci_device_id *idlist)
  625. {
  626.     pci_dev_t *dev;
  627.     struct pci_device_id *ent;
  628.  
  629.     for(dev = (pci_dev_t*)devices.next;
  630.         &dev->link != &devices;
  631.         dev = (pci_dev_t*)dev->link.next)
  632.     {
  633.         if( dev->pci_dev.vendor != idlist->vendor )
  634.             continue;
  635.  
  636.         for(ent = idlist; ent->vendor != 0; ent++)
  637.         {
  638.             if(unlikely(ent->device == dev->pci_dev.device))
  639.             {
  640.                 pdev->pci_dev = dev->pci_dev;
  641.                 return  ent;
  642.             }
  643.         };
  644.     }
  645.     return NULL;
  646. };
  647.  
  648.  
  649.  
  650. /**
  651.  * pci_map_rom - map a PCI ROM to kernel space
  652.  * @pdev: pointer to pci device struct
  653.  * @size: pointer to receive size of pci window over ROM
  654.  * @return: kernel virtual pointer to image of ROM
  655.  *
  656.  * Map a PCI ROM into kernel space. If ROM is boot video ROM,
  657.  * the shadow BIOS copy will be returned instead of the
  658.  * actual ROM.
  659.  */
  660.  
  661. #define legacyBIOSLocation 0xC0000
  662. #define OS_BASE   0x80000000
  663.  
  664. void *pci_map_rom(struct pci_dev *pdev, size_t *size)
  665. {
  666.     struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];
  667.     u32_t start;
  668.     void  *rom;
  669.  
  670. #if 0
  671. #endif
  672.  
  673.     unsigned char tmp[32];
  674.     rom = NULL;
  675.  
  676.     dbgprintf("Getting BIOS copy from legacy VBIOS location\n");
  677.     memcpy(tmp,(char*)(OS_BASE+legacyBIOSLocation), 32);
  678.     *size = tmp[2] * 512;
  679.     if (*size > 0x10000 )
  680.     {
  681.         *size = 0;
  682.         dbgprintf("Invalid BIOS length field\n");
  683.     }
  684.     else
  685.         rom = (void*)( OS_BASE+legacyBIOSLocation);
  686.  
  687.     return rom;
  688. }
  689.  
  690.  
  691. int
  692. pci_set_dma_mask(struct pci_dev *dev, u64 mask)
  693. {
  694. //        if (!pci_dma_supported(dev, mask))
  695. //                return -EIO;
  696.  
  697.         dev->dma_mask = mask;
  698.  
  699.         return 0;
  700. }
  701.  
  702.