grlib: Add ambapp_common_info to derived types

This avoids a cast in DEV_TO_COMMON().
This commit is contained in:
Sebastian Huber
2020-09-18 10:00:46 +02:00
parent c15c520b96
commit f9c8e14dcb
14 changed files with 46 additions and 50 deletions

View File

@@ -35,6 +35,41 @@ extern "C" {
/* Max supported AHB buses */
#define AHB_BUS_MAX 6
#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
#define AMBAPP_FLAG_SBUS 0x003
/* 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) (((adev)->devinfo))
struct ambapp_common_info {
unsigned char irq;
unsigned char ver;
unsigned char ahbidx; /* AHB Bus Index */
};
struct ambapp_apb_info {
struct ambapp_common_info common;
/* APB SPECIFIC */
unsigned int start;
unsigned int mask;
};
struct ambapp_ahb_info {
struct ambapp_common_info common;
/* AHB SPECIFIC */
unsigned int start[4];
unsigned int mask[4];
char type[4]; /* type[N] Determine type of start[N]-mask[N],
* 2=AHB Memory Space, 3=AHB I/O Space */
unsigned int custom[3];
};
struct ambapp_dev {
struct ambapp_dev *next; /* Next */
struct ambapp_dev *prev; /* Previous Device. If (this ==
@@ -44,48 +79,9 @@ struct ambapp_dev {
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
#define AMBAPP_FLAG_SBUS 0x003
/* 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))
struct ambapp_common_info {
unsigned char irq;
unsigned char ver;
unsigned char ahbidx; /* AHB Bus Index */
};
struct ambapp_apb_info {
/* COMMON */
unsigned char irq;
unsigned char ver;
unsigned char ahbidx; /* AHB Bus Index */
/* APB SPECIFIC */
unsigned int start;
unsigned int mask;
};
struct ambapp_ahb_info {
/* COMMON */
unsigned char irq;
unsigned char ver;
unsigned char ahbidx; /* AHB Bus Index */
/* AHB SPECIFIC */
unsigned int start[4];
unsigned int mask[4];
char type[4]; /* type[N] Determine type of start[N]-mask[N],
* 2=AHB Memory Space, 3=AHB I/O Space */
unsigned int custom[3];
/* 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 */

View File

@@ -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) &&

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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)) {

View File

@@ -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;
}

View File

@@ -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
*/

View File

@@ -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;