home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lxapi32.zip / PCI / pcisetup.c < prev   
C/C++ Source or Header  |  2002-04-26  |  3KB  |  84 lines

  1. /* $Id: pcisetup.c,v 1.2 2002/04/26 23:09:36 smilcke Exp $ */
  2.  
  3. /*
  4.  * pcisetup.c
  5.  * Autor:    Automatic generation from CnvPciID.CMD
  6.  * All code from setup-res.c, setup-bus.c and setup-irq.c
  7.  *
  8. */
  9.  
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/mm.h>
  13. #include <linux/pci.h>
  14. #include <linux/init.h>
  15.  
  16. /******************************************************************************/
  17. /* from setup-res.c                                                           */
  18. /******************************************************************************/
  19. //----------------------------- pci_claim_resource -----------------------------
  20. int __init pci_claim_resource(struct pci_dev *dev,int resource)
  21. {
  22.  struct resource *res=&dev->resource[resource];
  23.  struct resource *root=pci_find_parent_resource(dev,res);
  24.  int err=-EINVAL;
  25.  if(root!=NULL)
  26.   err=request_resource(root,res);
  27.  return err;
  28. }
  29.  
  30. //-------------------------- pci_assign_bus_resource ---------------------------
  31. static int pci_assign_bus_resource(const struct pci_bus *bus
  32.                                    ,struct pci_dev *dev
  33.                                    ,struct resource *res
  34.                                    ,unsigned long size
  35.                                    ,unsigned long min
  36.                                    ,unsigned int type_mask
  37.                                    ,int resno)
  38. {
  39.  int i;
  40.  type_mask|=IORESOURCE_IO | IORESOURCE_MEM;
  41.  for(i=0;i<4;i++)
  42.  {
  43.   struct resource *r=bus->resource[i];
  44.   if(!r)
  45.    continue;
  46.   // type_mask must match
  47.   if((res->flags ^ r->flags) & type_mask)
  48.    continue;
  49.   // We cannot allocate a non-prefetching resource from a pre-fetching area
  50.   if((r->flags & IORESOURCE_PREFETCH) && !(res->flags & IORESOURCE_PREFETCH))
  51.    continue;
  52.   // Ok, try it out ...
  53.   if(allocate_resource(r,res,size,min,-1,size,pcibios_align_resource,dev)<0)
  54.    continue;
  55.   // Update PCI config space
  56.   pcibios_update_resource(dev,r,res,resno);
  57.   return 0;
  58.  }
  59.  return -EBUSY;
  60. }
  61.  
  62. //---------------------------- pci_assign_resource -----------------------------
  63. int pci_assign_resource(struct pci_dev *dev,int i)
  64. {
  65.  const struct pci_bus *bus=dev->bus;
  66.  struct resource *res=dev->resource+i;
  67.  unsigned long size,min;
  68.  size=res->end-res->start+1;
  69.  min=(res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM;
  70.  if(pci_assign_bus_resource(bus,dev,res,size,min,IORESOURCE_PREFETCH,i)<0)
  71.  {
  72.   // That failed
  73.   // But a prefetching area can handle a non-prefetching
  74.   // window (it will just not perform as well).
  75.   if(!(res->flags & IORESOURCE_PREFETCH) || pci_assign_bus_resource(bus,dev,res,size,min,0,i)<0)
  76.   {
  77.    CPK(printk(KERN_ERR "PCI: Failed to allocate resource %d(%lx-%lx) for %s\n",
  78.           i, res->start, res->end, dev->slot_name));
  79.    return -EBUSY;
  80.   }
  81.  }
  82. // DBGC((KERN_ERR "  got res[%lx:%lx] for resource %d of %s\n", res->start,res->end, i, dev->name));
  83.  return 0;
  84. }