From f4bf22c8e5093fa65b0c95467c918a2812daef66 Mon Sep 17 00:00:00 2001 From: Daniel Hellstrom Date: Wed, 8 Apr 2015 10:51:45 +0200 Subject: LIBPCI: new implementation private header file - 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 (limited to 'cpukit/libpci') diff --git a/cpukit/libpci/Makefile.am b/cpukit/libpci/Makefile.am index cff25b35c0..cf336ed094 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 b23c0bce3d..d591977ab0 100644 --- a/cpukit/libpci/pci_cfg_auto.c +++ b/cpukit/libpci/pci_cfg_auto.c @@ -19,6 +19,8 @@ #include #include +#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 e6c69b68ba..c2ab7ecd5d 100644 --- a/cpukit/libpci/pci_cfg_peripheral.c +++ b/cpukit/libpci/pci_cfg_peripheral.c @@ -18,8 +18,7 @@ #include -/* 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 a2154d2abe..b1ea0709aa 100644 --- a/cpukit/libpci/pci_cfg_read.c +++ b/cpukit/libpci/pci_cfg_read.c @@ -14,6 +14,8 @@ #include #include +#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 5ec224238d..9974eb9b40 100644 --- a/cpukit/libpci/pci_cfg_static.c +++ b/cpukit/libpci/pci_cfg_static.c @@ -20,6 +20,8 @@ #include #include +#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 0000000000..a79e42939e --- /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 +#include +#include + +#include +#include + +#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 0000000000..b45ef561f3 --- /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); -- cgit v1.2.3