diff mbox series

[v3,06/14] tpm-sysbus: add plug handler for TPM on SysBus

Message ID 20231029060404.71196-7-j@getutm.app
State New
Headers show
Series tpm: introduce TPM CRB SysBus device | expand

Commit Message

Joelle van Dyne Oct. 29, 2023, 6:03 a.m. UTC
TPM needs to know its own base address in order to generate its DSDT
device entry.

Signed-off-by: Joelle van Dyne <j@getutm.app>
---
 include/sysemu/tpm.h |  4 ++++
 hw/tpm/tpm-sysbus.c  | 33 +++++++++++++++++++++++++++++++++
 hw/tpm/meson.build   |  1 +
 3 files changed, 38 insertions(+)
 create mode 100644 hw/tpm/tpm-sysbus.c

Comments

Stefan Berger Oct. 30, 2023, 4:52 p.m. UTC | #1
On 10/29/23 02:03, Joelle van Dyne wrote:
> TPM needs to know its own base address in order to generate its DSDT
> device entry.
>
> Signed-off-by: Joelle van Dyne <j@getutm.app>
> ---
>   include/sysemu/tpm.h |  4 ++++
>   hw/tpm/tpm-sysbus.c  | 33 +++++++++++++++++++++++++++++++++
>   hw/tpm/meson.build   |  1 +
>   3 files changed, 38 insertions(+)
>   create mode 100644 hw/tpm/tpm-sysbus.c
>
> diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h
> index 1ee568b3b6..ffd300e607 100644
> --- a/include/sysemu/tpm.h
> +++ b/include/sysemu/tpm.h
> @@ -12,6 +12,8 @@
>   #ifndef QEMU_TPM_H
>   #define QEMU_TPM_H
>
> +#include "qemu/osdep.h"
> +#include "exec/hwaddr.h"
>   #include "qapi/qapi-types-tpm.h"
>   #include "qom/object.h"
>
> @@ -78,6 +80,8 @@ static inline TPMVersion tpm_get_version(TPMIf *ti)
>       return TPM_IF_GET_CLASS(ti)->get_version(ti);
>   }
>
> +void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base);
> +
>   #else /* CONFIG_TPM */
>
>   #define tpm_init()  (0)
> diff --git a/hw/tpm/tpm-sysbus.c b/hw/tpm/tpm-sysbus.c
> new file mode 100644
> index 0000000000..ef0592b837
> --- /dev/null
> +++ b/hw/tpm/tpm-sysbus.c
> @@ -0,0 +1,33 @@

A header in this new file would be good. Otherwise LGTM.

   Stefan

> +#include "sysemu/tpm.h"
> +#include "hw/platform-bus.h"
> +#include "hw/sysbus.h"
> +#include "qapi/error.h"
Joelle van Dyne Oct. 30, 2023, 4:55 p.m. UTC | #2
I was debating what to add. I couldn't find a project-wide template
for what the header should be and I couldn't copy/paste from where I
copied the code from (virt.c) because it names a specific author that
I'm not sure wrote this code... Any advice?

On Mon, Oct 30, 2023 at 9:52 AM Stefan Berger <stefanb@linux.ibm.com> wrote:
>
>
> On 10/29/23 02:03, Joelle van Dyne wrote:
> > TPM needs to know its own base address in order to generate its DSDT
> > device entry.
> >
> > Signed-off-by: Joelle van Dyne <j@getutm.app>
> > ---
> >   include/sysemu/tpm.h |  4 ++++
> >   hw/tpm/tpm-sysbus.c  | 33 +++++++++++++++++++++++++++++++++
> >   hw/tpm/meson.build   |  1 +
> >   3 files changed, 38 insertions(+)
> >   create mode 100644 hw/tpm/tpm-sysbus.c
> >
> > diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h
> > index 1ee568b3b6..ffd300e607 100644
> > --- a/include/sysemu/tpm.h
> > +++ b/include/sysemu/tpm.h
> > @@ -12,6 +12,8 @@
> >   #ifndef QEMU_TPM_H
> >   #define QEMU_TPM_H
> >
> > +#include "qemu/osdep.h"
> > +#include "exec/hwaddr.h"
> >   #include "qapi/qapi-types-tpm.h"
> >   #include "qom/object.h"
> >
> > @@ -78,6 +80,8 @@ static inline TPMVersion tpm_get_version(TPMIf *ti)
> >       return TPM_IF_GET_CLASS(ti)->get_version(ti);
> >   }
> >
> > +void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base);
> > +
> >   #else /* CONFIG_TPM */
> >
> >   #define tpm_init()  (0)
> > diff --git a/hw/tpm/tpm-sysbus.c b/hw/tpm/tpm-sysbus.c
> > new file mode 100644
> > index 0000000000..ef0592b837
> > --- /dev/null
> > +++ b/hw/tpm/tpm-sysbus.c
> > @@ -0,0 +1,33 @@
>
> A header in this new file would be good. Otherwise LGTM.
>
>    Stefan
>
> > +#include "sysemu/tpm.h"
> > +#include "hw/platform-bus.h"
> > +#include "hw/sysbus.h"
> > +#include "qapi/error.h"
>
>
>
Stefan Berger Oct. 30, 2023, 5:01 p.m. UTC | #3
On 10/30/23 12:55, Joelle van Dyne wrote:
> I was debating what to add. I couldn't find a project-wide template
> for what the header should be and I couldn't copy/paste from where I
> copied the code from (virt.c) because it names a specific author that
> I'm not sure wrote this code... Any advice?

I would follow the files in hw/tpm/*.c and use those as templates with

- name of file and short description

- Copyright

- Author(s)

- 2 sentences about the license

- Maybe a longer description.


>
> On Mon, Oct 30, 2023 at 9:52 AM Stefan Berger <stefanb@linux.ibm.com> wrote:
>>
>> On 10/29/23 02:03, Joelle van Dyne wrote:
>>> TPM needs to know its own base address in order to generate its DSDT
>>> device entry.
>>>
>>> Signed-off-by: Joelle van Dyne <j@getutm.app>
>>> ---
>>>    include/sysemu/tpm.h |  4 ++++
>>>    hw/tpm/tpm-sysbus.c  | 33 +++++++++++++++++++++++++++++++++
>>>    hw/tpm/meson.build   |  1 +
>>>    3 files changed, 38 insertions(+)
>>>    create mode 100644 hw/tpm/tpm-sysbus.c
>>>
>>> diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h
>>> index 1ee568b3b6..ffd300e607 100644
>>> --- a/include/sysemu/tpm.h
>>> +++ b/include/sysemu/tpm.h
>>> @@ -12,6 +12,8 @@
>>>    #ifndef QEMU_TPM_H
>>>    #define QEMU_TPM_H
>>>
>>> +#include "qemu/osdep.h"
>>> +#include "exec/hwaddr.h"
>>>    #include "qapi/qapi-types-tpm.h"
>>>    #include "qom/object.h"
>>>
>>> @@ -78,6 +80,8 @@ static inline TPMVersion tpm_get_version(TPMIf *ti)
>>>        return TPM_IF_GET_CLASS(ti)->get_version(ti);
>>>    }
>>>
>>> +void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base);
>>> +
>>>    #else /* CONFIG_TPM */
>>>
>>>    #define tpm_init()  (0)
>>> diff --git a/hw/tpm/tpm-sysbus.c b/hw/tpm/tpm-sysbus.c
>>> new file mode 100644
>>> index 0000000000..ef0592b837
>>> --- /dev/null
>>> +++ b/hw/tpm/tpm-sysbus.c
>>> @@ -0,0 +1,33 @@
>> A header in this new file would be good. Otherwise LGTM.
>>
>>     Stefan
>>
>>> +#include "sysemu/tpm.h"
>>> +#include "hw/platform-bus.h"
>>> +#include "hw/sysbus.h"
>>> +#include "qapi/error.h"
>>
>>
diff mbox series

Patch

diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h
index 1ee568b3b6..ffd300e607 100644
--- a/include/sysemu/tpm.h
+++ b/include/sysemu/tpm.h
@@ -12,6 +12,8 @@ 
 #ifndef QEMU_TPM_H
 #define QEMU_TPM_H
 
+#include "qemu/osdep.h"
+#include "exec/hwaddr.h"
 #include "qapi/qapi-types-tpm.h"
 #include "qom/object.h"
 
@@ -78,6 +80,8 @@  static inline TPMVersion tpm_get_version(TPMIf *ti)
     return TPM_IF_GET_CLASS(ti)->get_version(ti);
 }
 
+void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base);
+
 #else /* CONFIG_TPM */
 
 #define tpm_init()  (0)
diff --git a/hw/tpm/tpm-sysbus.c b/hw/tpm/tpm-sysbus.c
new file mode 100644
index 0000000000..ef0592b837
--- /dev/null
+++ b/hw/tpm/tpm-sysbus.c
@@ -0,0 +1,33 @@ 
+#include "sysemu/tpm.h"
+#include "hw/platform-bus.h"
+#include "hw/sysbus.h"
+#include "qapi/error.h"
+
+void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base)
+{
+    PlatformBusDevice *pbusdev = PLATFORM_BUS_DEVICE(pbus);
+    SysBusDevice *sbdev = SYS_BUS_DEVICE(tpmif);
+    MemoryRegion *sbdev_mr;
+    hwaddr tpm_base;
+    uint64_t tpm_size;
+
+    /* exit early if TPM is not a sysbus device */
+    if (!object_dynamic_cast(OBJECT(tpmif), TYPE_SYS_BUS_DEVICE)) {
+        return;
+    }
+
+    assert(object_dynamic_cast(pbus, TYPE_PLATFORM_BUS_DEVICE));
+
+    tpm_base = platform_bus_get_mmio_addr(pbusdev, sbdev, 0);
+    assert(tpm_base != -1);
+
+    tpm_base += pbus_base;
+
+    sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
+    tpm_size = memory_region_size(sbdev_mr);
+
+    object_property_set_uint(OBJECT(sbdev), "x-baseaddr",
+                             tpm_base, &error_abort);
+    object_property_set_uint(OBJECT(sbdev), "x-size",
+                             tpm_size, &error_abort);
+}
diff --git a/hw/tpm/meson.build b/hw/tpm/meson.build
index cb8204d5bc..3060ac05e8 100644
--- a/hw/tpm/meson.build
+++ b/hw/tpm/meson.build
@@ -1,6 +1,7 @@ 
 system_ss.add(when: 'CONFIG_TPM_TIS', if_true: files('tpm_tis_common.c'))
 system_ss.add(when: 'CONFIG_TPM_TIS_ISA', if_true: files('tpm_tis_isa.c'))
 system_ss.add(when: 'CONFIG_TPM_TIS_SYSBUS', if_true: files('tpm_tis_sysbus.c'))
+system_ss.add(when: 'CONFIG_TPM_TIS_SYSBUS', if_true: files('tpm-sysbus.c'))
 system_ss.add(when: 'CONFIG_TPM_TIS_I2C', if_true: files('tpm_tis_i2c.c'))
 system_ss.add(when: 'CONFIG_TPM_CRB', if_true: files('tpm_crb.c'))
 system_ss.add(when: 'CONFIG_TPM_CRB', if_true: files('tpm_crb_common.c'))