[PATCH 24/42] LIBPCI: new implementation private header file
Daniel Hellstrom
daniel at gaisler.com
Tue Apr 14 11:32:51 UTC 2015
- new implementation private header file
- moved double implementation of pci_dev_create used by read & auto cfg
libraries to common pci_dev_create.c
- moved declaration of pci_bus_cnt to private header file so avoid extern
in .c files
---
cpukit/libpci/Makefile.am | 1 +
cpukit/libpci/pci_cfg_auto.c | 22 ++--------------------
cpukit/libpci/pci_cfg_peripheral.c | 3 +--
cpukit/libpci/pci_cfg_read.c | 22 ++--------------------
cpukit/libpci/pci_cfg_static.c | 5 ++---
cpukit/libpci/pci_dev_create.c | 34 ++++++++++++++++++++++++++++++++++
cpukit/libpci/pci_internal.h | 14 ++++++++++++++
7 files changed, 56 insertions(+), 45 deletions(-)
create mode 100644 cpukit/libpci/pci_dev_create.c
create mode 100644 cpukit/libpci/pci_internal.h
diff --git a/cpukit/libpci/Makefile.am b/cpukit/libpci/Makefile.am
index cff25b3..cf336ed 100644
--- a/cpukit/libpci/Makefile.am
+++ b/cpukit/libpci/Makefile.am
@@ -28,6 +28,7 @@ libpci_a_SOURCES += pci_cfg_print_code.c
libpci_a_SOURCES += pci_cfg_read.c
libpci_a_SOURCES += pci_cfg_static.c
libpci_a_SOURCES += pci_cfg_peripheral.c
+libpci_a_SOURCES += pci_dev_create.c
libpci_a_SOURCES += pci_find.c
libpci_a_SOURCES += pci_find_dev.c
libpci_a_SOURCES += pci_for_each.c
diff --git a/cpukit/libpci/pci_cfg_auto.c b/cpukit/libpci/pci_cfg_auto.c
index b23c0bc..d591977 100644
--- a/cpukit/libpci/pci_cfg_auto.c
+++ b/cpukit/libpci/pci_cfg_auto.c
@@ -19,6 +19,8 @@
#include <pci/access.h>
#include <pci/cfg.h>
+#include "pci_internal.h"
+
/* #define DEBUG */
#ifdef DEBUG
@@ -38,9 +40,6 @@
#define PCI_CFG_W16(dev, args...) pci_cfg_w16(dev, args)
#define PCI_CFG_W32(dev, args...) pci_cfg_w32(dev, args)
-/* Number of PCI buses */
-extern int pci_bus_cnt;
-
int pci_config_auto_initialized = 0;
/* Configuration setup */
@@ -268,23 +267,6 @@ static void pci_dev_free(struct pci_dev *dev)
}
#endif
-static struct pci_dev *pci_dev_create(int isbus)
-{
- void *ptr;
- int size;
-
- if (isbus)
- size = sizeof(struct pci_bus);
- else
- size = sizeof(struct pci_dev);
-
- ptr = malloc(size);
- if (!ptr)
- rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
- memset(ptr, 0, size);
- return ptr;
-}
-
static void pci_find_devs(struct pci_bus *bus)
{
uint32_t id, tmp;
diff --git a/cpukit/libpci/pci_cfg_peripheral.c b/cpukit/libpci/pci_cfg_peripheral.c
index e6c69b6..c2ab7ec 100644
--- a/cpukit/libpci/pci_cfg_peripheral.c
+++ b/cpukit/libpci/pci_cfg_peripheral.c
@@ -18,8 +18,7 @@
#include <pci/cfg.h>
-/* Number of buses */
-extern int pci_bus_cnt;
+#include "pci_internal.h"
/* Assume that user has defined static setup array in pci_hb */
int pci_config_peripheral(void)
diff --git a/cpukit/libpci/pci_cfg_read.c b/cpukit/libpci/pci_cfg_read.c
index a2154d2..b1ea070 100644
--- a/cpukit/libpci/pci_cfg_read.c
+++ b/cpukit/libpci/pci_cfg_read.c
@@ -14,6 +14,8 @@
#include <pci/cfg.h>
#include <pci/access.h>
+#include "pci_internal.h"
+
/* PCI Library
* (For debugging it might be good to use other functions or the driver's
* directly)
@@ -31,29 +33,9 @@
#define DBG(args...)
#endif
-/* Number of buses */
-extern int pci_bus_cnt;
-
/* The Host Bridge bus is initialized here */
extern struct pci_bus pci_hb;
-static struct pci_dev *pci_dev_create(int isbus)
-{
- void *ptr;
- int size;
-
- if (isbus)
- size = sizeof(struct pci_bus);
- else
- size = sizeof(struct pci_dev);
-
- ptr = malloc(size);
- if (!ptr)
- rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
- memset(ptr, 0, size);
- return ptr;
-}
-
/* Check if address is accessible from host */
static int pci_read_addressable(struct pci_dev *dev, struct pci_res *res)
{
diff --git a/cpukit/libpci/pci_cfg_static.c b/cpukit/libpci/pci_cfg_static.c
index 5ec2242..9974eb9 100644
--- a/cpukit/libpci/pci_cfg_static.c
+++ b/cpukit/libpci/pci_cfg_static.c
@@ -20,6 +20,8 @@
#include <pci/access.h>
#include <pci/cfg.h>
+#include "pci_internal.h"
+
#define PCI_CFG_R8(dev, args...) pci_cfg_r8(dev, args)
#define PCI_CFG_R16(dev, args...) pci_cfg_r16(dev, args)
#define PCI_CFG_R32(dev, args...) pci_cfg_r32(dev, args)
@@ -27,9 +29,6 @@
#define PCI_CFG_W16(dev, args...) pci_cfg_w16(dev, args)
#define PCI_CFG_W32(dev, args...) pci_cfg_w32(dev, args)
-/* Number of buses */
-extern int pci_bus_cnt;
-
/* Enumrate one bus if device is a bridge, and all it's subordinate buses */
static int pci_init_dev(struct pci_dev *dev, void *unused)
{
diff --git a/cpukit/libpci/pci_dev_create.c b/cpukit/libpci/pci_dev_create.c
new file mode 100644
index 0000000..a79e429
--- /dev/null
+++ b/cpukit/libpci/pci_dev_create.c
@@ -0,0 +1,34 @@
+/* Device allocator helper used by PCI Auto/Read Configuration Library
+ *
+ * COPYRIGHT (c) 2010 Cobham Gaisler AB.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <rtems.h>
+#include <stdlib.h>
+#include <rtems/bspIo.h>
+
+#include <pci.h>
+#include <pci/cfg.h>
+
+#include "pci_internal.h"
+
+struct pci_dev *pci_dev_create(int isbus)
+{
+ void *ptr;
+ int size;
+
+ if (isbus)
+ size = sizeof(struct pci_bus);
+ else
+ size = sizeof(struct pci_dev);
+
+ ptr = malloc(size);
+ if (!ptr)
+ rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
+ memset(ptr, 0, size);
+ return ptr;
+}
diff --git a/cpukit/libpci/pci_internal.h b/cpukit/libpci/pci_internal.h
new file mode 100644
index 0000000..b45ef56
--- /dev/null
+++ b/cpukit/libpci/pci_internal.h
@@ -0,0 +1,14 @@
+/* Private libpci declarations
+ *
+ * COPYRIGHT (c) 2015 Cobham Gaisler AB.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+/* Number of buses */
+extern int pci_bus_cnt;
+
+/* Allocate a PCI device for a standard device or a bridge device */
+struct pci_dev *pci_dev_create(int isbus);
--
1.7.0.4
More information about the devel
mailing list