From: Andre Przywara <andre.przywara@arm.com> To: Will Deacon <will@kernel.org>, Julien Thierry <julien.thierry.kdev@gmail.com> Cc: Sami Mujawar <sami.mujawar@arm.com>, Alexandru Elisei <alexandru.elisei@arm.com>, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH kvmtool] rtc: Generate fdt node for the real-time clock Date: Thu, 14 May 2020 10:45:53 +0100 [thread overview] Message-ID: <20200514094553.135663-1-andre.przywara@arm.com> (raw) On arm and arm64 we expose the Motorola RTC emulation to the guest, but never advertised this in the device tree. EDK-2 seems to rely on this device, but on its hardcoded address. To make this more future-proof, add a DT node with the address in it. EDK-2 can then read the proper address from there, and we can change this address later (with the flexible memory layout). Please note that an arm64 Linux kernel is not ready to use this device, there are some include files missing under arch/arm64 to compile the driver. I hacked this up in the kernel, just to verify this DT snippet is correct, but don't see much value in enabling this properly in Linux. Signed-off-by: Andre Przywara <andre.przywara@arm.com> --- hw/rtc.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/hw/rtc.c b/hw/rtc.c index c1fa72f2..5483879f 100644 --- a/hw/rtc.c +++ b/hw/rtc.c @@ -130,24 +130,56 @@ static struct ioport_operations cmos_ram_index_ioport_ops = { .io_out = cmos_ram_index_out, }; +#ifdef CONFIG_HAS_LIBFDT +static void generate_rtc_fdt_node(void *fdt, + struct device_header *dev_hdr, + void (*generate_irq_prop)(void *fdt, + u8 irq, + enum irq_type)) +{ + u64 reg_prop[2] = { cpu_to_fdt64(0x70), cpu_to_fdt64(2) }; + + _FDT(fdt_begin_node(fdt, "rtc")); + _FDT(fdt_property_string(fdt, "compatible", "motorola,mc146818")); + _FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop))); + _FDT(fdt_end_node(fdt)); +} +#else +#define generate_rtc_fdt_node NULL +#endif + +struct device_header rtc_dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = generate_rtc_fdt_node, +}; + int rtc__init(struct kvm *kvm) { - int r = 0; + int r; + + r = device__register(&rtc_dev_hdr); + if (r < 0) + return r; /* PORT 0070-007F - CMOS RAM/RTC (REAL TIME CLOCK) */ r = ioport__register(kvm, 0x0070, &cmos_ram_index_ioport_ops, 1, NULL); if (r < 0) - return r; + goto out_device; r = ioport__register(kvm, 0x0071, &cmos_ram_data_ioport_ops, 1, NULL); - if (r < 0) { - ioport__unregister(kvm, 0x0071); - return r; - } + if (r < 0) + goto out_ioport; /* Set the VRT bit in Register D to indicate valid RAM and time */ rtc.cmos_data[RTC_REG_D] = RTC_REG_D_VRT; + return r; + +out_ioport: + ioport__unregister(kvm, 0x0070); +out_device: + device__unregister(&rtc_dev_hdr); + return r; } dev_init(rtc__init); -- 2.17.1
WARNING: multiple messages have this Message-ID (diff)
From: Andre Przywara <andre.przywara@arm.com> To: Will Deacon <will@kernel.org>, Julien Thierry <julien.thierry.kdev@gmail.com> Cc: Sami Mujawar <sami.mujawar@arm.com>, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH kvmtool] rtc: Generate fdt node for the real-time clock Date: Thu, 14 May 2020 10:45:53 +0100 [thread overview] Message-ID: <20200514094553.135663-1-andre.przywara@arm.com> (raw) On arm and arm64 we expose the Motorola RTC emulation to the guest, but never advertised this in the device tree. EDK-2 seems to rely on this device, but on its hardcoded address. To make this more future-proof, add a DT node with the address in it. EDK-2 can then read the proper address from there, and we can change this address later (with the flexible memory layout). Please note that an arm64 Linux kernel is not ready to use this device, there are some include files missing under arch/arm64 to compile the driver. I hacked this up in the kernel, just to verify this DT snippet is correct, but don't see much value in enabling this properly in Linux. Signed-off-by: Andre Przywara <andre.przywara@arm.com> --- hw/rtc.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/hw/rtc.c b/hw/rtc.c index c1fa72f2..5483879f 100644 --- a/hw/rtc.c +++ b/hw/rtc.c @@ -130,24 +130,56 @@ static struct ioport_operations cmos_ram_index_ioport_ops = { .io_out = cmos_ram_index_out, }; +#ifdef CONFIG_HAS_LIBFDT +static void generate_rtc_fdt_node(void *fdt, + struct device_header *dev_hdr, + void (*generate_irq_prop)(void *fdt, + u8 irq, + enum irq_type)) +{ + u64 reg_prop[2] = { cpu_to_fdt64(0x70), cpu_to_fdt64(2) }; + + _FDT(fdt_begin_node(fdt, "rtc")); + _FDT(fdt_property_string(fdt, "compatible", "motorola,mc146818")); + _FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop))); + _FDT(fdt_end_node(fdt)); +} +#else +#define generate_rtc_fdt_node NULL +#endif + +struct device_header rtc_dev_hdr = { + .bus_type = DEVICE_BUS_IOPORT, + .data = generate_rtc_fdt_node, +}; + int rtc__init(struct kvm *kvm) { - int r = 0; + int r; + + r = device__register(&rtc_dev_hdr); + if (r < 0) + return r; /* PORT 0070-007F - CMOS RAM/RTC (REAL TIME CLOCK) */ r = ioport__register(kvm, 0x0070, &cmos_ram_index_ioport_ops, 1, NULL); if (r < 0) - return r; + goto out_device; r = ioport__register(kvm, 0x0071, &cmos_ram_data_ioport_ops, 1, NULL); - if (r < 0) { - ioport__unregister(kvm, 0x0071); - return r; - } + if (r < 0) + goto out_ioport; /* Set the VRT bit in Register D to indicate valid RAM and time */ rtc.cmos_data[RTC_REG_D] = RTC_REG_D_VRT; + return r; + +out_ioport: + ioport__unregister(kvm, 0x0070); +out_device: + device__unregister(&rtc_dev_hdr); + return r; } dev_init(rtc__init); -- 2.17.1 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
next reply other threads:[~2020-05-14 9:46 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-05-14 9:45 Andre Przywara [this message] 2020-05-14 9:45 ` [PATCH kvmtool] rtc: Generate fdt node for the real-time clock Andre Przywara 2020-05-14 12:20 ` Mark Rutland 2020-05-14 12:20 ` Mark Rutland 2020-05-14 13:11 ` André Przywara 2020-05-14 13:11 ` André Przywara 2020-05-19 16:46 ` Will Deacon 2020-05-19 16:46 ` Will Deacon
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200514094553.135663-1-andre.przywara@arm.com \ --to=andre.przywara@arm.com \ --cc=alexandru.elisei@arm.com \ --cc=julien.thierry.kdev@gmail.com \ --cc=kvm@vger.kernel.org \ --cc=kvmarm@lists.cs.columbia.edu \ --cc=sami.mujawar@arm.com \ --cc=will@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.