]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/sylixos-device.c
libpci: Add separate file for bit manipulation functions
[pciutils.git] / lib / sylixos-device.c
index 4bc207427a69a1509dab88a3e1eb44b90201a99a..170ae02bf644841a25a3c2cc8e29f52a180cc95b 100644 (file)
@@ -1,9 +1,11 @@
 /*
- *  The PCI Library -- Direct Configuration access via SylixOS Ports
+ *     The PCI Library -- Direct Configuration access via SylixOS Ports
  *
- *  Copyright (c) 2018 YuJian.Gong <gongyujian@acoinfo.com>
+ *     Copyright (c) 2018 YuJian.Gong <gongyujian@acoinfo.com>
  *
- *  Can be freely distributed and used under the terms of the GNU GPL.
+ *     Can be freely distributed and used under the terms of the GNU GPL v2+.
+ *
+ *     SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #define _GNU_SOURCE
 
 #include "internal.h"
 
-#define PCI_VENDOR_ID_IS_INVALID(vendor) (((vendor) == 0xffff) || ((vendor) == 0x0000))
-
-typedef struct {
-  struct pci_access *a;
-  byte *busmap;
-  int bus;
-} pci_dev_scan;
-
-static int
-sylixos_pci_traversal (int (*function)(), void *arg, int min_bus, int max_bus)
-{
-  int bus, dev, func;
-  u8 header;
-  u16 vendor;
-
-  if (!function || (min_bus < 0) || (max_bus < 0))
-    return PX_ERROR;
-
-  min_bus = (min_bus > (PCI_MAX_BUS - 1)) ? (PCI_MAX_BUS - 1) : min_bus;
-  max_bus = (max_bus > (PCI_MAX_BUS - 1)) ? (PCI_MAX_BUS - 1) : max_bus;
-
-  for (bus = min_bus; bus <= max_bus; bus++)
-    {
-      for (dev = 0; dev < PCI_MAX_SLOTS; dev++)
-       {
-         for (func = 0; func < PCI_MAX_FUNCTIONS; func++)
-           {
-             pciConfigInWord(bus, dev, func, PCI_VENDOR_ID, &vendor);
-             if (PCI_VENDOR_ID_IS_INVALID(vendor))
-               {
-                 if (func == 0)
-                   break;
-                 continue;
-               }
-
-             if (function(bus, dev, func, arg) != ERROR_NONE)
-               goto  __out;
-
-             if (func == 0)
-               {
-                 pciConfigInByte(bus, dev, func, PCI_HEADER_TYPE, &header);
-                 if ((header & PCI_HEADER_MULTI_FUNC) != PCI_HEADER_MULTI_FUNC)
-                   break;
-               }
-           }
-       }
-    }
-
-__out:
-  return ERROR_NONE;
-}
-
-static int
-pci_dev_list_create (int  bus, int  dev, int  func, void *arg)
-{
-  pci_dev_scan *f = (pci_dev_scan *)arg;
-  struct pci_dev *d;
-  u32 vd;
-
-  f->busmap[bus] = 1;
-  d = pci_alloc_dev(f->a);
-  d->bus = bus;
-  d->dev = dev;
-  d->func = func;
-
-  vd = pci_read_long(d, PCI_VENDOR_ID);
-  d->vendor_id = vd & 0xffff;
-  d->device_id = vd >> 16U;
-  d->known_fields = PCI_FILL_IDENT;
-  d->hdrtype = pci_read_byte(d, PCI_HEADER_TYPE) & 0x7f;
-  pci_link_dev(f->a, d);
-
-  return ERROR_NONE;
-}
-
-static void
-pci_generic_scan_bus_tbl(struct pci_access *a, byte *busmap, int bus)
-{
-  pci_dev_scan f;
-
-  f.a = a;
-  f.busmap = busmap;
-  f.bus = bus;
-
-  sylixos_pci_traversal(pci_dev_list_create, &f, bus, PCI_MAX_BUS);
-}
-
 static void
 sylixos_scan(struct pci_access *a)
 {
-  int se;
   u8 busmap[256];
-  char *env;
+  int bus;
 
   memset(busmap, 0, sizeof(busmap));
 
-  env = getenv(PCI_SCAN_FUNC);
-  if (!env)
-    {
-      pci_generic_scan_bus(a, busmap, 0);
-      return;
-    }
-
-  se = atoi(env);
-  if (se)
-    pci_generic_scan_bus_tbl(a, busmap, 0);
-  else
-    pci_generic_scan_bus(a, busmap, 0);
+  for (bus = 0; bus < PCI_MAX_BUS; bus++)
+    if (!busmap[bus])
+      pci_generic_scan_bus(a, busmap, 0, bus);
 }
 
 static void
@@ -147,15 +52,13 @@ sylixos_detect(struct pci_access *a)
 }
 
 static void
-sylixos_init(struct pci_access *a)
+sylixos_init(struct pci_access *a UNUSED)
 {
-  a->fd = -1;
 }
 
 static void
-sylixos_cleanup(struct pci_access *a)
+sylixos_cleanup(struct pci_access *a UNUSED)
 {
-    a->fd = -1;
 }
 
 static int