[PATCH 3/3] grlib: Add ambapp_common_info to derived types
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Sep 18 08:00:46 UTC 2020
This avoids a cast in DEV_TO_COMMON().
---
bsps/include/grlib/ambapp.h | 38 ++++++++++++---------------
bsps/shared/grlib/amba/ambapp.c | 14 +++++-----
bsps/shared/grlib/amba/ambapp_freq.c | 2 +-
bsps/shared/grlib/ascs/grascs.c | 2 +-
bsps/shared/grlib/can/satcan.c | 2 +-
bsps/shared/grlib/drvmgr/ambapp_bus.c | 20 +++++++-------
bsps/shared/grlib/pci/grpci.c | 2 +-
bsps/shared/grlib/pci/grpci2.c | 4 +--
bsps/shared/grlib/pci/pcif.c | 2 +-
bsps/shared/grlib/slink/grslink.c | 2 +-
bsps/shared/grlib/spw/grspw_pkt.c | 2 +-
bsps/shared/grlib/stat/l4stat.c | 2 +-
bsps/sparc/leon3/console/console.c | 2 +-
bsps/sparc/leon3/net/leon_open_eth.c | 2 +-
14 files changed, 46 insertions(+), 50 deletions(-)
diff --git a/bsps/include/grlib/ambapp.h b/bsps/include/grlib/ambapp.h
index 9202669ec0..3c3d3e9e3e 100644
--- a/bsps/include/grlib/ambapp.h
+++ b/bsps/include/grlib/ambapp.h
@@ -35,18 +35,6 @@ extern "C" {
/* Max supported AHB buses */
#define AHB_BUS_MAX 6
-struct ambapp_dev {
- struct ambapp_dev *next; /* Next */
- struct ambapp_dev *prev; /* Previous Device. If (this ==
- * rev->child) prev is bus bridge */
- struct ambapp_dev *children; /* Points to first device on sub-bus */
- void *owner; /* Owner of this AMBA device */
- unsigned char dev_type; /* AHB MST, AHB SLV or APB SLV*/
- unsigned char vendor; /* Vendor ID */
- unsigned short device; /* Device ID */
- int devinfo[0]; /* Device info (APB/AHB dep. on type) */
-};
-
#define AMBAPP_FLAG_FFACT_DIR 0x100 /* Frequency factor direction, 0=down, 1=up */
#define AMBAPP_FLAG_FFACT 0x0f0 /* Frequency factor against top bus */
#define AMBAPP_FLAG_MBUS 0x00c
@@ -55,7 +43,7 @@ struct ambapp_dev {
/* Get APB or AHB information from a AMBA device */
#define DEV_TO_APB(adev) ((struct ambapp_apb_info *)((adev)->devinfo))
#define DEV_TO_AHB(adev) ((struct ambapp_ahb_info *)((adev)->devinfo))
-#define DEV_TO_COMMON(adev) ((struct ambapp_common_info *)((adev)->devinfo))
+#define DEV_TO_COMMON(adev) (((adev)->devinfo))
struct ambapp_common_info {
unsigned char irq;
@@ -64,10 +52,7 @@ struct ambapp_common_info {
};
struct ambapp_apb_info {
- /* COMMON */
- unsigned char irq;
- unsigned char ver;
- unsigned char ahbidx; /* AHB Bus Index */
+ struct ambapp_common_info common;
/* APB SPECIFIC */
unsigned int start;
@@ -75,10 +60,7 @@ struct ambapp_apb_info {
};
struct ambapp_ahb_info {
- /* COMMON */
- unsigned char irq;
- unsigned char ver;
- unsigned char ahbidx; /* AHB Bus Index */
+ struct ambapp_common_info common;
/* AHB SPECIFIC */
unsigned int start[4];
@@ -88,6 +70,20 @@ struct ambapp_ahb_info {
unsigned int custom[3];
};
+struct ambapp_dev {
+ struct ambapp_dev *next; /* Next */
+ struct ambapp_dev *prev; /* Previous Device. If (this ==
+ * rev->child) prev is bus bridge */
+ struct ambapp_dev *children; /* Points to first device on sub-bus */
+ void *owner; /* Owner of this AMBA device */
+ unsigned char dev_type; /* AHB MST, AHB SLV or APB SLV*/
+ unsigned char vendor; /* Vendor ID */
+ unsigned short device; /* Device ID */
+
+ /* Device info (APB/AHB dep. on type) */
+ struct ambapp_common_info devinfo[0];
+};
+
/* Describes a complete AMBA Core. Each device may consist of 3 interfaces */
struct ambapp_core {
char irq; /* irq=-1 indicate no IRQ */
diff --git a/bsps/shared/grlib/amba/ambapp.c b/bsps/shared/grlib/amba/ambapp.c
index 69018f47e7..e87c86a586 100644
--- a/bsps/shared/grlib/amba/ambapp.c
+++ b/bsps/shared/grlib/amba/ambapp.c
@@ -71,9 +71,9 @@ static void ambapp_ahb_dev_init(
dev->vendor = ambapp_pnp_vendor(ahb->id);
dev->device = ambapp_pnp_device(ahb->id);
ahb_info = DEV_TO_AHB(dev);
- ahb_info->ver = ambapp_pnp_ver(ahb->id);
- ahb_info->irq = ambapp_pnp_irq(ahb->id);
- ahb_info->ahbidx = ahbidx;
+ ahb_info->common.ver = ambapp_pnp_ver(ahb->id);
+ ahb_info->common.irq = ambapp_pnp_irq(ahb->id);
+ ahb_info->common.ahbidx = ahbidx;
ahb_info->custom[0] = (unsigned int)ahb->custom[0];
ahb_info->custom[1] = (unsigned int)ahb->custom[1];
ahb_info->custom[2] = (unsigned int)ahb->custom[2];
@@ -116,9 +116,9 @@ static void ambapp_apb_dev_init(
dev->vendor = ambapp_pnp_vendor(apb->id);
dev->device = ambapp_pnp_device(apb->id);
apb_info = DEV_TO_APB(dev);
- apb_info->ver = ambapp_pnp_ver(apb->id);
- apb_info->irq = ambapp_pnp_irq(apb->id);
- apb_info->ahbidx = ahbidx;
+ apb_info->common.ver = ambapp_pnp_ver(apb->id);
+ apb_info->common.irq = ambapp_pnp_irq(apb->id);
+ apb_info->common.ahbidx = ahbidx;
apb_info->start = ambapp_pnp_apb_start(apb->iobar, base);
apb_info->mask = ambapp_pnp_apb_mask(apb->iobar);
}
@@ -223,7 +223,7 @@ static int ambapp_scan2(
/* Is it a AHB/AHB Bridge ? */
if (((dev->device == GAISLER_AHB2AHB) &&
- (dev->vendor == VENDOR_GAISLER) && (ahb_info->ver > 0)) ||
+ (dev->vendor == VENDOR_GAISLER) && (ahb_info->common.ver > 0)) ||
((dev->device == GAISLER_L2CACHE) &&
(dev->vendor == VENDOR_GAISLER)) ||
((dev->device == GAISLER_GRIOMMU) &&
diff --git a/bsps/shared/grlib/amba/ambapp_freq.c b/bsps/shared/grlib/amba/ambapp_freq.c
index 9e6e9c1765..07d8be5b39 100644
--- a/bsps/shared/grlib/amba/ambapp_freq.c
+++ b/bsps/shared/grlib/amba/ambapp_freq.c
@@ -54,7 +54,7 @@ static unsigned int ambapp_freq_calc(
else
freq_hz = freq_hz / ffact;
}
- return ambapp_freq_calc(abus, ahb->ahbidx, freq_hz, inverse);
+ return ambapp_freq_calc(abus, ahb->common.ahbidx, freq_hz, inverse);
} else {
/* Unknown bridge, impossible to calc frequency */
return 0;
diff --git a/bsps/shared/grlib/ascs/grascs.c b/bsps/shared/grlib/ascs/grascs.c
index 030faaa44c..200cf67409 100644
--- a/bsps/shared/grlib/ascs/grascs.c
+++ b/bsps/shared/grlib/ascs/grascs.c
@@ -74,7 +74,7 @@ static int ASCS_get_addr(int *base, int *irq) {
if(ambapp_find_apbslv(&ambapp_plb, VENDOR_GAISLER, GAISLER_ASCS, &core) == 1) {
*base = core.start;
- *irq = core.irq;
+ *irq = core.common.irq;
DBG("ASCS_get_addr: Registerd ASCS core at 0x%x with irq %i\n",core.start, core.irq);
return 0;
}
diff --git a/bsps/shared/grlib/can/satcan.c b/bsps/shared/grlib/can/satcan.c
index ff54128332..c3fdc158e3 100644
--- a/bsps/shared/grlib/can/satcan.c
+++ b/bsps/shared/grlib/can/satcan.c
@@ -665,7 +665,7 @@ static rtems_device_driver satcan_initialize(rtems_device_major_number major, rt
priv->dmamode = SATCAN_DMA_MODE_SYSTEM;
/* Register interrupt handler */
- rtems_interrupt_handler_install(d.irq, "satcan",
+ rtems_interrupt_handler_install(d.common.irq, "satcan",
RTEMS_INTERRUPT_SHARED,
satcan_interrupt_handler, NULL);
diff --git a/bsps/shared/grlib/drvmgr/ambapp_bus.c b/bsps/shared/grlib/drvmgr/ambapp_bus.c
index 931d5d2a61..3c38fc16e0 100644
--- a/bsps/shared/grlib/drvmgr/ambapp_bus.c
+++ b/bsps/shared/grlib/drvmgr/ambapp_bus.c
@@ -418,17 +418,17 @@ static void ambapp_dev_info(
str1 = str2 = str3 = "";
if (core->ahb_mst) {
str1 = "AHBMST ";
- ver = core->ahb_mst->ver;
+ ver = core->ahb_mst->common.ver;
ambapp_bus_freq_get(dev, DEV_AHB_MST, &ahbmst_freq);
}
if (core->ahb_slv) {
str2 = "AHBSLV ";
- ver = core->ahb_slv->ver;
+ ver = core->ahb_slv->common.ver;
ambapp_bus_freq_get(dev, DEV_AHB_SLV, &ahbslv_freq);
}
if (core->apb_slv) {
str3 = "APBSLV";
- ver = core->apb_slv->ver;
+ ver = core->apb_slv->common.ver;
ambapp_bus_freq_get(dev, DEV_APB_SLV, &apbslv_freq);
}
@@ -505,7 +505,7 @@ static int ambapp_dev_fixup(struct drvmgr_dev *dev, struct amba_dev_info *pnp)
int core;
devs_to_register[0] = dev;
- subcores = (pnp->info.ahb_slv->ver & 0x7) + 1;
+ subcores = (pnp->info.ahb_slv->common.ver & 0x7) + 1;
for(core = 1; core < subcores; core++) {
drvmgr_alloc_dev(&newdev, sizeof(*pnpinfo));
memcpy(newdev, dev, sizeof(*newdev));
@@ -599,22 +599,22 @@ static void ambapp_core_register(
pnpinfo->info.ahb_mst = (struct ambapp_ahb_info *)
ahb_mst->devinfo;
ambapp_alloc_dev(ahb_mst, (void *)newdev);
- if ( pnpinfo->info.ahb_mst->irq )
- pnpinfo->info.irq = pnpinfo->info.ahb_mst->irq;
+ if ( pnpinfo->info.ahb_mst->common.irq )
+ pnpinfo->info.irq = pnpinfo->info.ahb_mst->common.irq;
}
if ( ahb_slv ) {
pnpinfo->info.ahb_slv = (struct ambapp_ahb_info *)
ahb_slv->devinfo;
ambapp_alloc_dev(ahb_slv, (void *)newdev);
- if ( pnpinfo->info.ahb_slv->irq )
- pnpinfo->info.irq = pnpinfo->info.ahb_slv->irq;
+ if ( pnpinfo->info.ahb_slv->common.irq )
+ pnpinfo->info.irq = pnpinfo->info.ahb_slv->common.irq;
}
if ( apb_slv ) {
pnpinfo->info.apb_slv = (struct ambapp_apb_info *)
apb_slv->devinfo;
ambapp_alloc_dev(apb_slv, (void *)newdev);
- if ( pnpinfo->info.apb_slv->irq )
- pnpinfo->info.irq = pnpinfo->info.apb_slv->irq;
+ if ( pnpinfo->info.apb_slv->common.irq )
+ pnpinfo->info.irq = pnpinfo->info.apb_slv->common.irq;
}
if ( pnpinfo->info.irq == 0 )
pnpinfo->info.irq = -1; /* indicate no IRQ */
diff --git a/bsps/shared/grlib/pci/grpci.c b/bsps/shared/grlib/pci/grpci.c
index fc2f06a063..75eacbf272 100644
--- a/bsps/shared/grlib/pci/grpci.c
+++ b/bsps/shared/grlib/pci/grpci.c
@@ -513,7 +513,7 @@ static int grpci_init(struct grpci_priv *priv)
ahb = ainfo->info.ahb_slv;
/* Found PCI core, init private structure */
- priv->irq = apb->irq;
+ priv->irq = apb->common.irq;
priv->regs = (struct grpci_regs *)apb->start;
priv->bt_enabled = DEFAULT_BT_ENABLED;
diff --git a/bsps/shared/grlib/pci/grpci2.c b/bsps/shared/grlib/pci/grpci2.c
index 21c09f47a5..7e3a414839 100644
--- a/bsps/shared/grlib/pci/grpci2.c
+++ b/bsps/shared/grlib/pci/grpci2.c
@@ -730,8 +730,8 @@ static int grpci2_init(struct grpci2_priv *priv)
ahb = ainfo->info.ahb_slv;
/* Found PCI core, init private structure */
- priv->irq = apb->irq;
- priv->ver = apb->ver;
+ priv->irq = apb->common.irq;
+ priv->ver = apb->common.ver;
priv->regs = (struct grpci2_regs *)apb->start;
priv->bt_enabled = DEFAULT_BT_ENABLED;
priv->irq_mode = (priv->regs->sts_cap & STS_IRQMODE) >> STS_IRQMODE_BIT;
diff --git a/bsps/shared/grlib/pci/pcif.c b/bsps/shared/grlib/pci/pcif.c
index 17708a9c0b..9be45ba189 100644
--- a/bsps/shared/grlib/pci/pcif.c
+++ b/bsps/shared/grlib/pci/pcif.c
@@ -426,7 +426,7 @@ static int pcif_init(struct pcif_priv *priv)
ahb = ainfo->info.ahb_slv;
/* Found PCI core, init private structure */
- priv->irq = apb->irq;
+ priv->irq = apb->common.irq;
priv->regs = (struct pcif_regs *)apb->start;
/* Calculate the PCI windows
diff --git a/bsps/shared/grlib/slink/grslink.c b/bsps/shared/grlib/slink/grslink.c
index 8cf532c14f..3ed3e3c370 100644
--- a/bsps/shared/grlib/slink/grslink.c
+++ b/bsps/shared/grlib/slink/grslink.c
@@ -183,7 +183,7 @@ static int SLINK_getaddr(int *base, int *irq)
if (ambapp_find_apbslv(&ambapp_plb,VENDOR_GAISLER,GAISLER_SLINK,&c) == 1) {
*base = c.start;
- *irq = c.irq;
+ *irq = c.common.irq;
return 0;
}
return -1;
diff --git a/bsps/shared/grlib/spw/grspw_pkt.c b/bsps/shared/grlib/spw/grspw_pkt.c
index 56b39d78db..2cc4e886d6 100644
--- a/bsps/shared/grlib/spw/grspw_pkt.c
+++ b/bsps/shared/grlib/spw/grspw_pkt.c
@@ -3101,7 +3101,7 @@ static int grspw2_init3(struct drvmgr_dev *dev)
priv->hwsup.irq_num = 0;
/* Construct hardware version identification */
- priv->hwsup.hw_version = pnpinfo->device << 16 | pnpinfo->apb_slv->ver;
+ priv->hwsup.hw_version = pnpinfo->device << 16 | pnpinfo->apb_slv->common.ver;
if ((pnpinfo->device == GAISLER_SPW2) ||
(pnpinfo->device == GAISLER_SPW2_DMA)) {
diff --git a/bsps/shared/grlib/stat/l4stat.c b/bsps/shared/grlib/stat/l4stat.c
index ee4ae7d6a4..d6e5712b00 100644
--- a/bsps/shared/grlib/stat/l4stat.c
+++ b/bsps/shared/grlib/stat/l4stat.c
@@ -292,7 +292,7 @@ STATIC int l4stat_init(struct l4stat_priv *priv)
dev_id = ainfo->id.device;
/* Check if rev 1 of core (only rev 0 supported) */
- if (apb->ver != 0) {
+ if (apb->common.ver != 0) {
DBG("L4STAT rev 0 only supported.\n");
return L4STAT_ERR_ERROR;
}
diff --git a/bsps/sparc/leon3/console/console.c b/bsps/sparc/leon3/console/console.c
index 3522dc7529..9fb1f54828 100644
--- a/bsps/sparc/leon3/console/console.c
+++ b/bsps/sparc/leon3/console/console.c
@@ -62,7 +62,7 @@ static int find_matching_apbuart(struct ambapp_dev *dev, int index, void *arg)
/* Extract needed information of one APBUART */
apbuarts[uarts].regs = (struct apbuart_regs *)apb->start;
- apbuarts[uarts].irq = apb->irq;
+ apbuarts[uarts].irq = apb->common.irq;
/* Get APBUART core frequency, it is assumed that it is the same
* as Bus frequency where the UART is situated
*/
diff --git a/bsps/sparc/leon3/net/leon_open_eth.c b/bsps/sparc/leon3/net/leon_open_eth.c
index 5b9794cb89..2b386f8e9a 100644
--- a/bsps/sparc/leon3/net/leon_open_eth.c
+++ b/bsps/sparc/leon3/net/leon_open_eth.c
@@ -53,7 +53,7 @@ int rtems_leon_open_eth_driver_attach(
{
ahb = DEV_TO_AHB(adev);
base_addr = ahb->start[0];
- eth_irq = ahb->irq;
+ eth_irq = ahb->common.irq;
/* clear control register and reset NIC */
*(volatile int *) base_addr = 0;
--
2.26.2
More information about the devel
mailing list