[syslinux] [PATCH] pci: Introduce slot and function information

Sebastian Herbszt herbszt at gmx.de
Sun Aug 3 15:47:58 PDT 2008


H. Peter Anvin wrote:

I did convert ethersel and pcitest to the new structures.
New comments below.

> diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c
> index 1c3f526..298c4db 100644
> --- a/com32/lib/pci/scan.c
> +++ b/com32/lib/pci/scan.c

[snip]

> @@ -329,45 +303,32 @@ struct match *find_pci_device(struct pci_device_list * pci_device_list,
> }
> 
> /* scanning the pci bus to find pci devices */
> -int pci_scan(struct pci_bus_list * pci_bus_list, struct pci_device_list * pci_device_list)
> +struct pci_domain *pci_scan(void)
> {
> -  unsigned int bus, dev, func, maxfunc;
> -  uint32_t did, sid;
> -  uint8_t hdrtype, rid;
> +  struct pci_domain *domain = NULL;
> +  struct pci_bus    *bus    = NULL;
> +  struct pci_slot   *slot   = NULL;
> +  struct pci_device *func   = NULL;
> +  unsigned int nbus, ndev, nfunc, maxfunc;
> +  uint32_t did, sid, rcid;
> +  uint8_t hdrtype;
>   pciaddr_t a;
>   int cfgtype;
> 
> -  pci_device_list->count = 0;
> -
> -#ifdef DEBUG
> -  outl(~0, 0xcf8);
> -  printf("Poking at port CF8 = %#08x\n", inl(0xcf8));
> -  outl(0, 0xcf8);
> -#endif
> -
>   cfgtype = pci_set_config_type(PCI_CFG_AUTO);
>   (void)cfgtype;
> 
>   dprintf("PCI configuration type %d\n", cfgtype);
>   dprintf("Scanning PCI Buses\n");
> 
> -  /* We try to detect 256 buses */
> -  for (bus = 0; bus < MAX_PCI_BUSES; bus++) {
> -
> +  for (nbus = 0; nbus < MAX_PCI_BUSSES; nbus++) {
>     dprintf("Probing bus 0x%02x... \n", bus);

should be "nbus" not "bus"

"bus" should be set to NULL else it won't be reinitialized with zalloc
on second run since it's non NULL

> -    pci_bus_list->pci_bus[bus].id = bus;
> -    pci_bus_list->pci_bus[bus].pci_device_count = 0;
> -    pci_bus_list->count = 0;;
> -
> -    for (dev = 0; dev < MAX_PCI_DEVICES ; dev++) {
> +    for (ndev = 0; ndev < MAX_PCI_DEVICES ; ndev++) {

"slot" should be set to NULL here too

>       maxfunc = 1; /* Assume a single-function device */
> -      for (func = 0; func < maxfunc; func++) {
> - struct pci_device *pci_device =
> -   &pci_device_list->pci_device[pci_device_list->count];
> -
> - a = pci_mkaddr(bus, dev, func, 0);
> 
> +      for (nfunc = 0; nfunc < maxfunc; nfunc++) {

"func" gets zalloc'ed below so it's ok here

> + a = pci_mkaddr(nbus, ndev, nfunc, 0);
>  did = pci_readl(a);
> 
>  if (did == 0xffffffff || did == 0xffff0000 ||
> @@ -379,36 +340,79 @@ int pci_scan(struct pci_bus_list * pci_bus_list, struct pci_device_list * pci_de
>  if (hdrtype & 0x80)
>    maxfunc = MAX_PCI_FUNC; /* Multifunction device */
> 
> - rid = pci_readb(a + 0x08);
> - sid = pci_readl(a + 0x2c);
> + rcid = pci_readl(a + 0x08);
> + sid  = pci_readl(a + 0x2c);
> 
> - pci_device->addr = a;
> - pci_device->product = did >> 16;
> - pci_device->sub_product = sid >> 16;
> - pci_device->vendor = (did << 16) >> 16;
> - pci_device->sub_vendor = (sid << 16) >> 16;
> - pci_device->revision = rid;
> - pci_device_list->count++;
> - pci_device++;
> + if (!domain) {
> +   domain = zalloc(sizeof *domain);
> +   if (!domain)
> +     goto bail;
> + }
> + if (!bus) {
> +   bus = zalloc(sizeof *bus);
> +   if (!bus)
> +     goto bail;
> +   domain->bus[nbus] = bus;
> + }
> + if (!slot) {
> +   slot = zalloc(sizeof *slot);
> +   if (!slot)
> +     goto bail;
> +   bus->slot[ndev] = slot;
> + }
> + func = zalloc(sizeof *func);
> + if (!func)
> +   goto bail;
> +
> + slot->func[nfunc] = func;
> +
> + func->vid_did   = did;
> + func->svid_sdid = sid;
> + func->rid_class = rcid;
> 
>  dprintf
>    ("Scanning: BUS %02x DID %08x (%04x:%04x) SID %08x RID %02x\n",
>     bus, did, did >> 16, (did << 16) >> 16,
> -    sid, rid);
> - /* Adding the detected pci device to the bus */
> - pci_bus_list->pci_bus[bus].
> -   pci_device[pci_bus_list->pci_bus[bus].
> -      pci_device_count] = pci_device;
> - pci_bus_list->pci_bus[bus].pci_device_count++;
> +    sid, rcid & 0xff);
>       }
>     }
>   }
> 
> -  /* Detecting pci buses that have pci devices connected */
> -  for (bus = 0; bus < MAX_PCI_BUSES; bus++) {
> -    if (pci_bus_list->pci_bus[bus].pci_device_count > 0) {
> -      pci_bus_list->count++;
> +  return domain;
> +
> + bail:
> +  free_pci_domain(domain);
> +  return NULL;
> +}
> +

- Sebastian




More information about the Syslinux mailing list