hw/net/can/flexcan: Wire clock control module via link property
When wiring struct FlexcanState to the clock control module, it is currently necessary to reach into its private data. Moreover, when forgetting to wire the clock control module, QEMU will crash after the guest has already started. Fix both by letting struct FlexcanState expose a link property whose sanity is checked at realize time. Suggested-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Bernhard Beschow <shentey@gmail.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Acked-by: Pavel Pisa <pisa@fel.cvut.cz> Tested-by: Pavel Pisa <pisa@fel.cvut.cz> Message-ID: <20260702184038.178196-2-shentey@gmail.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
This commit is contained in:
committed by
Philippe Mathieu-Daudé
parent
399ba75fbe
commit
2afca7a592
@@ -391,7 +391,8 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
|
||||
{ FSL_IMX6_CAN2_ADDR, FSL_IMX6_FLEXCAN2_IRQ },
|
||||
};
|
||||
|
||||
s->flexcan[i].ccm = IMX_CCM(&s->ccm);
|
||||
object_property_set_link(OBJECT(&s->flexcan[i]), "clock-control-module",
|
||||
OBJECT(&s->ccm), &error_abort);
|
||||
object_property_set_link(OBJECT(&s->flexcan[i]), "canbus",
|
||||
OBJECT(s->canbus[i]), &error_abort);
|
||||
|
||||
|
||||
@@ -333,8 +333,6 @@ static uint32_t flexcan_get_bitrate(FlexcanState *s)
|
||||
|
||||
uint32_t pe_freq, s_freq, bitrate;
|
||||
|
||||
assert(s->ccm);
|
||||
|
||||
/* s_freq: CAN clock from CCM divided by the prescaler */
|
||||
pe_freq = imx_ccm_get_clock_frequency(s->ccm, CLK_CAN);
|
||||
s_freq = pe_freq / (1 + conf_presdiv);
|
||||
@@ -1346,6 +1344,12 @@ static void flexcan_realize(DeviceState *dev, Error **errp)
|
||||
}
|
||||
}
|
||||
|
||||
if (!s->ccm) {
|
||||
error_setg(errp, "%s 'clock-control-module' link property not set",
|
||||
dev->canonical_path);
|
||||
return;
|
||||
}
|
||||
|
||||
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
|
||||
sysbus_init_irq(SYS_BUS_DEVICE(SYS_BUS_DEVICE(dev)), &s->irq);
|
||||
}
|
||||
@@ -1366,6 +1370,8 @@ static const VMStateDescription vmstate_can = {
|
||||
static const Property flexcan_properties[] = {
|
||||
DEFINE_PROP_LINK("canbus", FlexcanState, canbus, TYPE_CAN_BUS,
|
||||
CanBusState *),
|
||||
DEFINE_PROP_LINK("clock-control-module", FlexcanState, ccm, TYPE_IMX_CCM,
|
||||
IMXCCMState *),
|
||||
};
|
||||
|
||||
static void flexcan_class_init(ObjectClass *klass, const void *data)
|
||||
|
||||
Reference in New Issue
Block a user