Skip to content

Commit e6f79ac

Browse files
committed
hw/arm/mps2-tz.c: Add extra data parameter to MakeDevFn
The mps2-tz boards use a data-driven structure to create the devices that sit behind peripheral protection controllers. Currently the functions which create these devices are passed an 'opaque' pointer which is always the address within the machine struct of the device to create, and some "all devices need this" information like irqs and addresses. If a specific device needs more information than this, it is currently not possible to pass that through from the PPCInfo data structure. Add support for passing an extra data parameter, so that we can more flexibly handle the needs of specific device types. To provide some type-safety we make this extra parameter a pointer to a union (which initially has no members). In particular, we would like to be able to indicate which of the i2c controllers are for on-board devices only and which are connected to the external 'shield' expansion port; a subsequent patch will use this mechanism for that purpose. Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-id: [email protected]
1 parent 1518562 commit e6f79ac

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

hw/arm/mps2-tz.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
373373
}
374374
}
375375

376+
/* Union describing the device-specific extra data we pass to the devfn. */
377+
typedef union PPCExtraData {
378+
} PPCExtraData;
379+
376380
/* Most of the devices in the AN505 FPGA image sit behind
377381
* Peripheral Protection Controllers. These data structures
378382
* define the layout of which devices sit behind which PPCs.
@@ -382,7 +386,8 @@ static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
382386
*/
383387
typedef MemoryRegion *MakeDevFn(MPS2TZMachineState *mms, void *opaque,
384388
const char *name, hwaddr size,
385-
const int *irqs);
389+
const int *irqs,
390+
const PPCExtraData *extradata);
386391

387392
typedef struct PPCPortInfo {
388393
const char *name;
@@ -391,6 +396,7 @@ typedef struct PPCPortInfo {
391396
hwaddr addr;
392397
hwaddr size;
393398
int irqs[3]; /* currently no device needs more IRQ lines than this */
399+
PPCExtraData extradata; /* to pass device-specific info to the devfn */
394400
} PPCPortInfo;
395401

396402
typedef struct PPCInfo {
@@ -401,7 +407,8 @@ typedef struct PPCInfo {
401407
static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
402408
void *opaque,
403409
const char *name, hwaddr size,
404-
const int *irqs)
410+
const int *irqs,
411+
const PPCExtraData *extradata)
405412
{
406413
/* Initialize, configure and realize a TYPE_UNIMPLEMENTED_DEVICE,
407414
* and return a pointer to its MemoryRegion.
@@ -417,7 +424,7 @@ static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
417424

418425
static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
419426
const char *name, hwaddr size,
420-
const int *irqs)
427+
const int *irqs, const PPCExtraData *extradata)
421428
{
422429
/* The irq[] array is tx, rx, combined, in that order */
423430
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
@@ -441,7 +448,7 @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
441448

442449
static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
443450
const char *name, hwaddr size,
444-
const int *irqs)
451+
const int *irqs, const PPCExtraData *extradata)
445452
{
446453
MPS2SCC *scc = opaque;
447454
DeviceState *sccdev;
@@ -465,7 +472,7 @@ static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
465472

466473
static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
467474
const char *name, hwaddr size,
468-
const int *irqs)
475+
const int *irqs, const PPCExtraData *extradata)
469476
{
470477
MPS2FPGAIO *fpgaio = opaque;
471478
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
@@ -480,7 +487,8 @@ static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
480487

481488
static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
482489
const char *name, hwaddr size,
483-
const int *irqs)
490+
const int *irqs,
491+
const PPCExtraData *extradata)
484492
{
485493
SysBusDevice *s;
486494
NICInfo *nd = &nd_table[0];
@@ -500,7 +508,8 @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
500508

501509
static MemoryRegion *make_eth_usb(MPS2TZMachineState *mms, void *opaque,
502510
const char *name, hwaddr size,
503-
const int *irqs)
511+
const int *irqs,
512+
const PPCExtraData *extradata)
504513
{
505514
/*
506515
* The AN524 makes the ethernet and USB share a PPC port.
@@ -543,7 +552,7 @@ static MemoryRegion *make_eth_usb(MPS2TZMachineState *mms, void *opaque,
543552

544553
static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
545554
const char *name, hwaddr size,
546-
const int *irqs)
555+
const int *irqs, const PPCExtraData *extradata)
547556
{
548557
TZMPC *mpc = opaque;
549558
int i = mpc - &mms->mpc[0];
@@ -615,7 +624,7 @@ static void remap_irq_fn(void *opaque, int n, int level)
615624

616625
static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
617626
const char *name, hwaddr size,
618-
const int *irqs)
627+
const int *irqs, const PPCExtraData *extradata)
619628
{
620629
/* The irq[] array is DMACINTR, DMACINTERR, DMACINTTC, in that order */
621630
PL080State *dma = opaque;
@@ -672,7 +681,7 @@ static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
672681

673682
static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
674683
const char *name, hwaddr size,
675-
const int *irqs)
684+
const int *irqs, const PPCExtraData *extradata)
676685
{
677686
/*
678687
* The AN505 has five PL022 SPI controllers.
@@ -694,7 +703,7 @@ static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
694703

695704
static MemoryRegion *make_i2c(MPS2TZMachineState *mms, void *opaque,
696705
const char *name, hwaddr size,
697-
const int *irqs)
706+
const int *irqs, const PPCExtraData *extradata)
698707
{
699708
ArmSbconI2CState *i2c = opaque;
700709
SysBusDevice *s;
@@ -707,7 +716,7 @@ static MemoryRegion *make_i2c(MPS2TZMachineState *mms, void *opaque,
707716

708717
static MemoryRegion *make_rtc(MPS2TZMachineState *mms, void *opaque,
709718
const char *name, hwaddr size,
710-
const int *irqs)
719+
const int *irqs, const PPCExtraData *extradata)
711720
{
712721
PL031State *pl031 = opaque;
713722
SysBusDevice *s;
@@ -1084,7 +1093,7 @@ static void mps2tz_common_init(MachineState *machine)
10841093
}
10851094

10861095
mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size,
1087-
pinfo->irqs);
1096+
pinfo->irqs, &pinfo->extradata);
10881097
portname = g_strdup_printf("port[%d]", port);
10891098
object_property_set_link(OBJECT(ppc), portname, OBJECT(mr),
10901099
&error_fatal);

0 commit comments

Comments
 (0)