diff mbox series

[RFC,6/6] hw/ppc/pnv_homer: add python interface support for homer/occ common area

Message ID 20190807071445.4109-7-bala24@linux.ibm.com
State New
Headers show
Series Enhancing Qemu MMIO emulation with scripting interface | expand

Commit Message

Balamuruhan S Aug. 7, 2019, 7:14 a.m. UTC
use python interface APIs in homer/occ common area emulation to
interact with scripts if provided else fallback to normal flow,
it shows how simple to use the interface to call python methods
with any number of arguments in any script placed in common
-module-path provided in qemu commandline.

Signed-off-by: Balamuruhan S <bala24@linux.ibm.com>
---
 hw/ppc/pnv_homer.c      | 20 ++++++++++++++++++++
 hw/ppc/pnv_xscom.c      |  9 +++++----
 include/sysemu/sysemu.h |  4 ++++
 vl.c                    | 24 ++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 4 deletions(-)

Comments

Philippe Mathieu-Daudé Aug. 7, 2019, 10:27 a.m. UTC | #1
On 8/7/19 9:14 AM, Balamuruhan S wrote:
> use python interface APIs in homer/occ common area emulation to
> interact with scripts if provided else fallback to normal flow,
> it shows how simple to use the interface to call python methods
> with any number of arguments in any script placed in common
> -module-path provided in qemu commandline.
> 
> Signed-off-by: Balamuruhan S <bala24@linux.ibm.com>
> ---
>  hw/ppc/pnv_homer.c      | 20 ++++++++++++++++++++
>  hw/ppc/pnv_xscom.c      |  9 +++++----
>  include/sysemu/sysemu.h |  4 ++++
>  vl.c                    | 24 ++++++++++++++++++++++++
>  4 files changed, 53 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/ppc/pnv_homer.c b/hw/ppc/pnv_homer.c
> index 73a94856d0..6ae5e74f19 100644
> --- a/hw/ppc/pnv_homer.c
> +++ b/hw/ppc/pnv_homer.c
> @@ -16,7 +16,9 @@
>   * You should have received a copy of the GNU Lesser General Public
>   * License along with this library; if not, see <http://www.gnu.org/licenses/>.
>   */
> +#include "sysemu/python_api.h"
>  #include "qemu/osdep.h"
> +#include "sysemu/sysemu.h"
>  #include "sysemu/hw_accel.h"
>  #include "sysemu/cpus.h"
>  #include "hw/ppc/pnv.h"
> @@ -37,6 +39,15 @@ static bool core_max_array(hwaddr addr)
>  
>  static uint64_t homer_read(void *opaque, hwaddr addr, unsigned width)
>  {
> +    if (homer_module && homer) {
> +        uint64_t homer_ret;
> +        char **address = g_malloc(sizeof(uint64_t));
> +        python_args_init_cast_long(address, addr, 0);
> +        homer_ret = python_callback_int(module_path, homer_module, homer, address, 1);
> +        python_args_clean(address, 1);
> +        g_free(address);

Maybe the heap overhead can be simplified alloc'ing in the PnvChip
structure.

> +        return homer_ret;
> +    }
>      switch (addr) {
>          case 0xe2006:  /* max pstate ultra turbo */
>          case 0xe2018:  /* pstate id for 0 */
> @@ -106,6 +117,15 @@ const MemoryRegionOps pnv_homer_ops = {
>  
>  static uint64_t occ_common_area_read(void *opaque, hwaddr addr, unsigned width)
>  {
> +    if (occ_module && occ) {
> +        uint64_t occ_ret;
> +        char **address = g_malloc(sizeof(uint64_t));
> +        python_args_init_cast_long(address, addr, 0);
> +        occ_ret = python_callback_int(module_path, occ_module, occ, address, 1);
> +        python_args_clean(address, 1);
> +        g_free(address);
> +        return occ_ret;
> +    }
>      switch (addr) {
>          /*
>           * occ-sensor sanity check that asserts the sensor
> diff --git a/hw/ppc/pnv_xscom.c b/hw/ppc/pnv_xscom.c
> index 18a780bcdf..5e41b7c953 100644
> --- a/hw/ppc/pnv_xscom.c
> +++ b/hw/ppc/pnv_xscom.c
> @@ -179,13 +179,14 @@ static uint64_t xscom_read(void *opaque, hwaddr addr, unsigned width)
>      MemTxResult result;
>  
>      if (xscom_module && xscom_readp) {
> -        char **args = g_malloc(2 * sizeof(uint64_t));
> +        char **args = g_malloc(3 * sizeof(uint64_t));
>          PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
>          python_args_init_cast_long(args, pcba, 0);
> -        python_args_init_cast_int(args, pcc->chip_type, 1);
> +        python_args_init_cast_int(args, chip->chip_num, 1);
> +        python_args_init_cast_int(args, pcc->chip_type, 2);
>          val = python_callback_int(module_path, xscom_module, xscom_readp,
> -                                  args, 2);
> -        python_args_clean(args, 2);
> +                                  args, 3);
> +        python_args_clean(args, 3);
>          g_free(args);
>      }
>      else {
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index 9b8dc346d6..3c8119e040 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -121,6 +121,10 @@ extern const char *module_path;
>  extern const char *xscom_module;
>  extern const char *xscom_readp;
>  extern const char *xscom_writep;
> +extern const char *homer_module;
> +extern const char *homer;
> +extern const char *occ_module;
> +extern const char *occ;
>  extern int mem_prealloc;
>  
>  #define MAX_NODES 128
> diff --git a/vl.c b/vl.c
> index 28f0dc1c1b..c96d35d907 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -144,6 +144,10 @@ const char *module_path = NULL;
>  const char *xscom_module = NULL;
>  const char *xscom_readp = NULL;
>  const char *xscom_writep = NULL;
> +const char *homer_module = NULL;
> +const char *homer = NULL;
> +const char *occ_module = NULL;
> +const char *occ = NULL;
>  int mem_prealloc = 0; /* force preallocation of physical target memory */
>  bool enable_mlock = false;
>  bool enable_cpu_pm = false;
> @@ -495,6 +499,22 @@ static QemuOptsList qemu_module_opts = {
>              .name = "xscom_write",
>              .type = QEMU_OPT_STRING,
>          },
> +        {
> +            .name = "homer_module",
> +            .type = QEMU_OPT_STRING,
> +        },
> +        {
> +            .name = "homer",
> +            .type = QEMU_OPT_STRING,
> +        },
> +        {
> +            .name = "occ_module",
> +            .type = QEMU_OPT_STRING,
> +        },
> +        {
> +            .name = "occ",
> +            .type = QEMU_OPT_STRING,
> +        },
>          { /* end of list */ }
>      },
>  };
> @@ -3231,6 +3251,10 @@ int main(int argc, char **argv, char **envp)
>                  xscom_module = qemu_opt_get(opts, "xscom_module");
>                  xscom_readp = qemu_opt_get(opts, "xscom_read");
>                  xscom_writep = qemu_opt_get(opts, "xscom_write");
> +                homer_module = qemu_opt_get(opts, "homer_module");
> +                homer = qemu_opt_get(opts, "homer");
> +                occ_module = qemu_opt_get(opts, "occ_module");
> +                occ = qemu_opt_get(opts, "occ");
>                  break;
>              case QEMU_OPTION_mem_prealloc:
>                  mem_prealloc = 1;
>
David Gibson Aug. 9, 2019, 4:46 a.m. UTC | #2
On Wed, Aug 07, 2019 at 12:44:45PM +0530, Balamuruhan S wrote:
> use python interface APIs in homer/occ common area emulation to
> interact with scripts if provided else fallback to normal flow,
> it shows how simple to use the interface to call python methods
> with any number of arguments in any script placed in common
> -module-path provided in qemu commandline.

What's the use case for this?

> 
> Signed-off-by: Balamuruhan S <bala24@linux.ibm.com>
> ---
>  hw/ppc/pnv_homer.c      | 20 ++++++++++++++++++++
>  hw/ppc/pnv_xscom.c      |  9 +++++----
>  include/sysemu/sysemu.h |  4 ++++
>  vl.c                    | 24 ++++++++++++++++++++++++
>  4 files changed, 53 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/ppc/pnv_homer.c b/hw/ppc/pnv_homer.c
> index 73a94856d0..6ae5e74f19 100644
> --- a/hw/ppc/pnv_homer.c
> +++ b/hw/ppc/pnv_homer.c
> @@ -16,7 +16,9 @@
>   * You should have received a copy of the GNU Lesser General Public
>   * License along with this library; if not, see <http://www.gnu.org/licenses/>.
>   */
> +#include "sysemu/python_api.h"
>  #include "qemu/osdep.h"
> +#include "sysemu/sysemu.h"
>  #include "sysemu/hw_accel.h"
>  #include "sysemu/cpus.h"
>  #include "hw/ppc/pnv.h"
> @@ -37,6 +39,15 @@ static bool core_max_array(hwaddr addr)
>  
>  static uint64_t homer_read(void *opaque, hwaddr addr, unsigned width)
>  {
> +    if (homer_module && homer) {
> +        uint64_t homer_ret;
> +        char **address = g_malloc(sizeof(uint64_t));
> +        python_args_init_cast_long(address, addr, 0);
> +        homer_ret = python_callback_int(module_path, homer_module, homer, address, 1);
> +        python_args_clean(address, 1);
> +        g_free(address);
> +        return homer_ret;
> +    }
>      switch (addr) {
>          case 0xe2006:  /* max pstate ultra turbo */
>          case 0xe2018:  /* pstate id for 0 */
> @@ -106,6 +117,15 @@ const MemoryRegionOps pnv_homer_ops = {
>  
>  static uint64_t occ_common_area_read(void *opaque, hwaddr addr, unsigned width)
>  {
> +    if (occ_module && occ) {
> +        uint64_t occ_ret;
> +        char **address = g_malloc(sizeof(uint64_t));
> +        python_args_init_cast_long(address, addr, 0);
> +        occ_ret = python_callback_int(module_path, occ_module, occ, address, 1);
> +        python_args_clean(address, 1);
> +        g_free(address);
> +        return occ_ret;
> +    }
>      switch (addr) {
>          /*
>           * occ-sensor sanity check that asserts the sensor
> diff --git a/hw/ppc/pnv_xscom.c b/hw/ppc/pnv_xscom.c
> index 18a780bcdf..5e41b7c953 100644
> --- a/hw/ppc/pnv_xscom.c
> +++ b/hw/ppc/pnv_xscom.c
> @@ -179,13 +179,14 @@ static uint64_t xscom_read(void *opaque, hwaddr addr, unsigned width)
>      MemTxResult result;
>  
>      if (xscom_module && xscom_readp) {
> -        char **args = g_malloc(2 * sizeof(uint64_t));
> +        char **args = g_malloc(3 * sizeof(uint64_t));
>          PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
>          python_args_init_cast_long(args, pcba, 0);
> -        python_args_init_cast_int(args, pcc->chip_type, 1);
> +        python_args_init_cast_int(args, chip->chip_num, 1);
> +        python_args_init_cast_int(args, pcc->chip_type, 2);
>          val = python_callback_int(module_path, xscom_module, xscom_readp,
> -                                  args, 2);
> -        python_args_clean(args, 2);
> +                                  args, 3);
> +        python_args_clean(args, 3);
>          g_free(args);
>      }
>      else {
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index 9b8dc346d6..3c8119e040 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -121,6 +121,10 @@ extern const char *module_path;
>  extern const char *xscom_module;
>  extern const char *xscom_readp;
>  extern const char *xscom_writep;
> +extern const char *homer_module;
> +extern const char *homer;
> +extern const char *occ_module;
> +extern const char *occ;
>  extern int mem_prealloc;
>  
>  #define MAX_NODES 128
> diff --git a/vl.c b/vl.c
> index 28f0dc1c1b..c96d35d907 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -144,6 +144,10 @@ const char *module_path = NULL;
>  const char *xscom_module = NULL;
>  const char *xscom_readp = NULL;
>  const char *xscom_writep = NULL;
> +const char *homer_module = NULL;
> +const char *homer = NULL;
> +const char *occ_module = NULL;
> +const char *occ = NULL;
>  int mem_prealloc = 0; /* force preallocation of physical target memory */
>  bool enable_mlock = false;
>  bool enable_cpu_pm = false;
> @@ -495,6 +499,22 @@ static QemuOptsList qemu_module_opts = {
>              .name = "xscom_write",
>              .type = QEMU_OPT_STRING,
>          },
> +        {
> +            .name = "homer_module",
> +            .type = QEMU_OPT_STRING,
> +        },
> +        {
> +            .name = "homer",
> +            .type = QEMU_OPT_STRING,
> +        },
> +        {
> +            .name = "occ_module",
> +            .type = QEMU_OPT_STRING,
> +        },
> +        {
> +            .name = "occ",
> +            .type = QEMU_OPT_STRING,
> +        },
>          { /* end of list */ }
>      },
>  };
> @@ -3231,6 +3251,10 @@ int main(int argc, char **argv, char **envp)
>                  xscom_module = qemu_opt_get(opts, "xscom_module");
>                  xscom_readp = qemu_opt_get(opts, "xscom_read");
>                  xscom_writep = qemu_opt_get(opts, "xscom_write");
> +                homer_module = qemu_opt_get(opts, "homer_module");
> +                homer = qemu_opt_get(opts, "homer");
> +                occ_module = qemu_opt_get(opts, "occ_module");
> +                occ = qemu_opt_get(opts, "occ");
>                  break;
>              case QEMU_OPTION_mem_prealloc:
>                  mem_prealloc = 1;
Balamuruhan S Aug. 11, 2019, 6:05 a.m. UTC | #3
On 8/7/19 3:57 PM, Philippe Mathieu-Daudé wrote:
> On 8/7/19 9:14 AM, Balamuruhan S wrote:
>> use python interface APIs in homer/occ common area emulation to
>> interact with scripts if provided else fallback to normal flow,
>> it shows how simple to use the interface to call python methods
>> with any number of arguments in any script placed in common
>> -module-path provided in qemu commandline.
>>
>> Signed-off-by: Balamuruhan S <bala24@linux.ibm.com>
>> ---
>>  hw/ppc/pnv_homer.c      | 20 ++++++++++++++++++++
>>  hw/ppc/pnv_xscom.c      |  9 +++++----
>>  include/sysemu/sysemu.h |  4 ++++
>>  vl.c                    | 24 ++++++++++++++++++++++++
>>  4 files changed, 53 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/ppc/pnv_homer.c b/hw/ppc/pnv_homer.c
>> index 73a94856d0..6ae5e74f19 100644
>> --- a/hw/ppc/pnv_homer.c
>> +++ b/hw/ppc/pnv_homer.c
>> @@ -16,7 +16,9 @@
>>   * You should have received a copy of the GNU Lesser General Public
>>   * License along with this library; if not, see <http://www.gnu.org/licenses/>.
>>   */
>> +#include "sysemu/python_api.h"
>>  #include "qemu/osdep.h"
>> +#include "sysemu/sysemu.h"
>>  #include "sysemu/hw_accel.h"
>>  #include "sysemu/cpus.h"
>>  #include "hw/ppc/pnv.h"
>> @@ -37,6 +39,15 @@ static bool core_max_array(hwaddr addr)
>>  
>>  static uint64_t homer_read(void *opaque, hwaddr addr, unsigned width)
>>  {
>> +    if (homer_module && homer) {
>> +        uint64_t homer_ret;
>> +        char **address = g_malloc(sizeof(uint64_t));
>> +        python_args_init_cast_long(address, addr, 0);
>> +        homer_ret = python_callback_int(module_path, homer_module, homer, address, 1);
>> +        python_args_clean(address, 1);
>> +        g_free(address);
> Maybe the heap overhead can be simplified alloc'ing in the PnvChip
> structure.

But it also depends on with how many arguments that we need to call python

functions associated with read/write ops. sure, I will check the way to

adopt this suggestion.

Thanks Philippe.


>
>> +        return homer_ret;
>> +    }
>>      switch (addr) {
>>          case 0xe2006:  /* max pstate ultra turbo */
>>          case 0xe2018:  /* pstate id for 0 */
>> @@ -106,6 +117,15 @@ const MemoryRegionOps pnv_homer_ops = {
>>  
>>  static uint64_t occ_common_area_read(void *opaque, hwaddr addr, unsigned width)
>>  {
>> +    if (occ_module && occ) {
>> +        uint64_t occ_ret;
>> +        char **address = g_malloc(sizeof(uint64_t));
>> +        python_args_init_cast_long(address, addr, 0);
>> +        occ_ret = python_callback_int(module_path, occ_module, occ, address, 1);
>> +        python_args_clean(address, 1);
>> +        g_free(address);
>> +        return occ_ret;
>> +    }
>>      switch (addr) {
>>          /*
>>           * occ-sensor sanity check that asserts the sensor
>> diff --git a/hw/ppc/pnv_xscom.c b/hw/ppc/pnv_xscom.c
>> index 18a780bcdf..5e41b7c953 100644
>> --- a/hw/ppc/pnv_xscom.c
>> +++ b/hw/ppc/pnv_xscom.c
>> @@ -179,13 +179,14 @@ static uint64_t xscom_read(void *opaque, hwaddr addr, unsigned width)
>>      MemTxResult result;
>>  
>>      if (xscom_module && xscom_readp) {
>> -        char **args = g_malloc(2 * sizeof(uint64_t));
>> +        char **args = g_malloc(3 * sizeof(uint64_t));
>>          PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
>>          python_args_init_cast_long(args, pcba, 0);
>> -        python_args_init_cast_int(args, pcc->chip_type, 1);
>> +        python_args_init_cast_int(args, chip->chip_num, 1);
>> +        python_args_init_cast_int(args, pcc->chip_type, 2);
>>          val = python_callback_int(module_path, xscom_module, xscom_readp,
>> -                                  args, 2);
>> -        python_args_clean(args, 2);
>> +                                  args, 3);
>> +        python_args_clean(args, 3);
>>          g_free(args);
>>      }
>>      else {
>> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
>> index 9b8dc346d6..3c8119e040 100644
>> --- a/include/sysemu/sysemu.h
>> +++ b/include/sysemu/sysemu.h
>> @@ -121,6 +121,10 @@ extern const char *module_path;
>>  extern const char *xscom_module;
>>  extern const char *xscom_readp;
>>  extern const char *xscom_writep;
>> +extern const char *homer_module;
>> +extern const char *homer;
>> +extern const char *occ_module;
>> +extern const char *occ;
>>  extern int mem_prealloc;
>>  
>>  #define MAX_NODES 128
>> diff --git a/vl.c b/vl.c
>> index 28f0dc1c1b..c96d35d907 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -144,6 +144,10 @@ const char *module_path = NULL;
>>  const char *xscom_module = NULL;
>>  const char *xscom_readp = NULL;
>>  const char *xscom_writep = NULL;
>> +const char *homer_module = NULL;
>> +const char *homer = NULL;
>> +const char *occ_module = NULL;
>> +const char *occ = NULL;
>>  int mem_prealloc = 0; /* force preallocation of physical target memory */
>>  bool enable_mlock = false;
>>  bool enable_cpu_pm = false;
>> @@ -495,6 +499,22 @@ static QemuOptsList qemu_module_opts = {
>>              .name = "xscom_write",
>>              .type = QEMU_OPT_STRING,
>>          },
>> +        {
>> +            .name = "homer_module",
>> +            .type = QEMU_OPT_STRING,
>> +        },
>> +        {
>> +            .name = "homer",
>> +            .type = QEMU_OPT_STRING,
>> +        },
>> +        {
>> +            .name = "occ_module",
>> +            .type = QEMU_OPT_STRING,
>> +        },
>> +        {
>> +            .name = "occ",
>> +            .type = QEMU_OPT_STRING,
>> +        },
>>          { /* end of list */ }
>>      },
>>  };
>> @@ -3231,6 +3251,10 @@ int main(int argc, char **argv, char **envp)
>>                  xscom_module = qemu_opt_get(opts, "xscom_module");
>>                  xscom_readp = qemu_opt_get(opts, "xscom_read");
>>                  xscom_writep = qemu_opt_get(opts, "xscom_write");
>> +                homer_module = qemu_opt_get(opts, "homer_module");
>> +                homer = qemu_opt_get(opts, "homer");
>> +                occ_module = qemu_opt_get(opts, "occ_module");
>> +                occ = qemu_opt_get(opts, "occ");
>>                  break;
>>              case QEMU_OPTION_mem_prealloc:
>>                  mem_prealloc = 1;
>>
Balamuruhan S Aug. 11, 2019, 6:19 a.m. UTC | #4
On 8/9/19 10:16 AM, David Gibson wrote:
> On Wed, Aug 07, 2019 at 12:44:45PM +0530, Balamuruhan S wrote:
>> use python interface APIs in homer/occ common area emulation to
>> interact with scripts if provided else fallback to normal flow,
>> it shows how simple to use the interface to call python methods
>> with any number of arguments in any script placed in common
>> -module-path provided in qemu commandline.
> What's the use case for this?

The usecase can be performing multiple boot test of the vm or during runtime
with different values expected/unexpected by firmware/kernel and check
how it is behaving or how it should behave.

It can be used as a framework for CI or regression.

>
>> Signed-off-by: Balamuruhan S <bala24@linux.ibm.com>
>> ---
>>  hw/ppc/pnv_homer.c      | 20 ++++++++++++++++++++
>>  hw/ppc/pnv_xscom.c      |  9 +++++----
>>  include/sysemu/sysemu.h |  4 ++++
>>  vl.c                    | 24 ++++++++++++++++++++++++
>>  4 files changed, 53 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/ppc/pnv_homer.c b/hw/ppc/pnv_homer.c
>> index 73a94856d0..6ae5e74f19 100644
>> --- a/hw/ppc/pnv_homer.c
>> +++ b/hw/ppc/pnv_homer.c
>> @@ -16,7 +16,9 @@
>>   * You should have received a copy of the GNU Lesser General Public
>>   * License along with this library; if not, see <http://www.gnu.org/licenses/>.
>>   */
>> +#include "sysemu/python_api.h"
>>  #include "qemu/osdep.h"
>> +#include "sysemu/sysemu.h"
>>  #include "sysemu/hw_accel.h"
>>  #include "sysemu/cpus.h"
>>  #include "hw/ppc/pnv.h"
>> @@ -37,6 +39,15 @@ static bool core_max_array(hwaddr addr)
>>  
>>  static uint64_t homer_read(void *opaque, hwaddr addr, unsigned width)
>>  {
>> +    if (homer_module && homer) {
>> +        uint64_t homer_ret;
>> +        char **address = g_malloc(sizeof(uint64_t));
>> +        python_args_init_cast_long(address, addr, 0);
>> +        homer_ret = python_callback_int(module_path, homer_module, homer, address, 1);
>> +        python_args_clean(address, 1);
>> +        g_free(address);
>> +        return homer_ret;
>> +    }
>>      switch (addr) {
>>          case 0xe2006:  /* max pstate ultra turbo */
>>          case 0xe2018:  /* pstate id for 0 */
>> @@ -106,6 +117,15 @@ const MemoryRegionOps pnv_homer_ops = {
>>  
>>  static uint64_t occ_common_area_read(void *opaque, hwaddr addr, unsigned width)
>>  {
>> +    if (occ_module && occ) {
>> +        uint64_t occ_ret;
>> +        char **address = g_malloc(sizeof(uint64_t));
>> +        python_args_init_cast_long(address, addr, 0);
>> +        occ_ret = python_callback_int(module_path, occ_module, occ, address, 1);
>> +        python_args_clean(address, 1);
>> +        g_free(address);
>> +        return occ_ret;
>> +    }
>>      switch (addr) {
>>          /*
>>           * occ-sensor sanity check that asserts the sensor
>> diff --git a/hw/ppc/pnv_xscom.c b/hw/ppc/pnv_xscom.c
>> index 18a780bcdf..5e41b7c953 100644
>> --- a/hw/ppc/pnv_xscom.c
>> +++ b/hw/ppc/pnv_xscom.c
>> @@ -179,13 +179,14 @@ static uint64_t xscom_read(void *opaque, hwaddr addr, unsigned width)
>>      MemTxResult result;
>>  
>>      if (xscom_module && xscom_readp) {
>> -        char **args = g_malloc(2 * sizeof(uint64_t));
>> +        char **args = g_malloc(3 * sizeof(uint64_t));
>>          PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
>>          python_args_init_cast_long(args, pcba, 0);
>> -        python_args_init_cast_int(args, pcc->chip_type, 1);
>> +        python_args_init_cast_int(args, chip->chip_num, 1);
>> +        python_args_init_cast_int(args, pcc->chip_type, 2);
>>          val = python_callback_int(module_path, xscom_module, xscom_readp,
>> -                                  args, 2);
>> -        python_args_clean(args, 2);
>> +                                  args, 3);
>> +        python_args_clean(args, 3);
>>          g_free(args);
>>      }
>>      else {
>> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
>> index 9b8dc346d6..3c8119e040 100644
>> --- a/include/sysemu/sysemu.h
>> +++ b/include/sysemu/sysemu.h
>> @@ -121,6 +121,10 @@ extern const char *module_path;
>>  extern const char *xscom_module;
>>  extern const char *xscom_readp;
>>  extern const char *xscom_writep;
>> +extern const char *homer_module;
>> +extern const char *homer;
>> +extern const char *occ_module;
>> +extern const char *occ;
>>  extern int mem_prealloc;
>>  
>>  #define MAX_NODES 128
>> diff --git a/vl.c b/vl.c
>> index 28f0dc1c1b..c96d35d907 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -144,6 +144,10 @@ const char *module_path = NULL;
>>  const char *xscom_module = NULL;
>>  const char *xscom_readp = NULL;
>>  const char *xscom_writep = NULL;
>> +const char *homer_module = NULL;
>> +const char *homer = NULL;
>> +const char *occ_module = NULL;
>> +const char *occ = NULL;
>>  int mem_prealloc = 0; /* force preallocation of physical target memory */
>>  bool enable_mlock = false;
>>  bool enable_cpu_pm = false;
>> @@ -495,6 +499,22 @@ static QemuOptsList qemu_module_opts = {
>>              .name = "xscom_write",
>>              .type = QEMU_OPT_STRING,
>>          },
>> +        {
>> +            .name = "homer_module",
>> +            .type = QEMU_OPT_STRING,
>> +        },
>> +        {
>> +            .name = "homer",
>> +            .type = QEMU_OPT_STRING,
>> +        },
>> +        {
>> +            .name = "occ_module",
>> +            .type = QEMU_OPT_STRING,
>> +        },
>> +        {
>> +            .name = "occ",
>> +            .type = QEMU_OPT_STRING,
>> +        },
>>          { /* end of list */ }
>>      },
>>  };
>> @@ -3231,6 +3251,10 @@ int main(int argc, char **argv, char **envp)
>>                  xscom_module = qemu_opt_get(opts, "xscom_module");
>>                  xscom_readp = qemu_opt_get(opts, "xscom_read");
>>                  xscom_writep = qemu_opt_get(opts, "xscom_write");
>> +                homer_module = qemu_opt_get(opts, "homer_module");
>> +                homer = qemu_opt_get(opts, "homer");
>> +                occ_module = qemu_opt_get(opts, "occ_module");
>> +                occ = qemu_opt_get(opts, "occ");
>>                  break;
>>              case QEMU_OPTION_mem_prealloc:
>>                  mem_prealloc = 1;
diff mbox series

Patch

diff --git a/hw/ppc/pnv_homer.c b/hw/ppc/pnv_homer.c
index 73a94856d0..6ae5e74f19 100644
--- a/hw/ppc/pnv_homer.c
+++ b/hw/ppc/pnv_homer.c
@@ -16,7 +16,9 @@ 
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
+#include "sysemu/python_api.h"
 #include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
 #include "sysemu/hw_accel.h"
 #include "sysemu/cpus.h"
 #include "hw/ppc/pnv.h"
@@ -37,6 +39,15 @@  static bool core_max_array(hwaddr addr)
 
 static uint64_t homer_read(void *opaque, hwaddr addr, unsigned width)
 {
+    if (homer_module && homer) {
+        uint64_t homer_ret;
+        char **address = g_malloc(sizeof(uint64_t));
+        python_args_init_cast_long(address, addr, 0);
+        homer_ret = python_callback_int(module_path, homer_module, homer, address, 1);
+        python_args_clean(address, 1);
+        g_free(address);
+        return homer_ret;
+    }
     switch (addr) {
         case 0xe2006:  /* max pstate ultra turbo */
         case 0xe2018:  /* pstate id for 0 */
@@ -106,6 +117,15 @@  const MemoryRegionOps pnv_homer_ops = {
 
 static uint64_t occ_common_area_read(void *opaque, hwaddr addr, unsigned width)
 {
+    if (occ_module && occ) {
+        uint64_t occ_ret;
+        char **address = g_malloc(sizeof(uint64_t));
+        python_args_init_cast_long(address, addr, 0);
+        occ_ret = python_callback_int(module_path, occ_module, occ, address, 1);
+        python_args_clean(address, 1);
+        g_free(address);
+        return occ_ret;
+    }
     switch (addr) {
         /*
          * occ-sensor sanity check that asserts the sensor
diff --git a/hw/ppc/pnv_xscom.c b/hw/ppc/pnv_xscom.c
index 18a780bcdf..5e41b7c953 100644
--- a/hw/ppc/pnv_xscom.c
+++ b/hw/ppc/pnv_xscom.c
@@ -179,13 +179,14 @@  static uint64_t xscom_read(void *opaque, hwaddr addr, unsigned width)
     MemTxResult result;
 
     if (xscom_module && xscom_readp) {
-        char **args = g_malloc(2 * sizeof(uint64_t));
+        char **args = g_malloc(3 * sizeof(uint64_t));
         PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
         python_args_init_cast_long(args, pcba, 0);
-        python_args_init_cast_int(args, pcc->chip_type, 1);
+        python_args_init_cast_int(args, chip->chip_num, 1);
+        python_args_init_cast_int(args, pcc->chip_type, 2);
         val = python_callback_int(module_path, xscom_module, xscom_readp,
-                                  args, 2);
-        python_args_clean(args, 2);
+                                  args, 3);
+        python_args_clean(args, 3);
         g_free(args);
     }
     else {
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 9b8dc346d6..3c8119e040 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -121,6 +121,10 @@  extern const char *module_path;
 extern const char *xscom_module;
 extern const char *xscom_readp;
 extern const char *xscom_writep;
+extern const char *homer_module;
+extern const char *homer;
+extern const char *occ_module;
+extern const char *occ;
 extern int mem_prealloc;
 
 #define MAX_NODES 128
diff --git a/vl.c b/vl.c
index 28f0dc1c1b..c96d35d907 100644
--- a/vl.c
+++ b/vl.c
@@ -144,6 +144,10 @@  const char *module_path = NULL;
 const char *xscom_module = NULL;
 const char *xscom_readp = NULL;
 const char *xscom_writep = NULL;
+const char *homer_module = NULL;
+const char *homer = NULL;
+const char *occ_module = NULL;
+const char *occ = NULL;
 int mem_prealloc = 0; /* force preallocation of physical target memory */
 bool enable_mlock = false;
 bool enable_cpu_pm = false;
@@ -495,6 +499,22 @@  static QemuOptsList qemu_module_opts = {
             .name = "xscom_write",
             .type = QEMU_OPT_STRING,
         },
+        {
+            .name = "homer_module",
+            .type = QEMU_OPT_STRING,
+        },
+        {
+            .name = "homer",
+            .type = QEMU_OPT_STRING,
+        },
+        {
+            .name = "occ_module",
+            .type = QEMU_OPT_STRING,
+        },
+        {
+            .name = "occ",
+            .type = QEMU_OPT_STRING,
+        },
         { /* end of list */ }
     },
 };
@@ -3231,6 +3251,10 @@  int main(int argc, char **argv, char **envp)
                 xscom_module = qemu_opt_get(opts, "xscom_module");
                 xscom_readp = qemu_opt_get(opts, "xscom_read");
                 xscom_writep = qemu_opt_get(opts, "xscom_write");
+                homer_module = qemu_opt_get(opts, "homer_module");
+                homer = qemu_opt_get(opts, "homer");
+                occ_module = qemu_opt_get(opts, "occ_module");
+                occ = qemu_opt_get(opts, "occ");
                 break;
             case QEMU_OPTION_mem_prealloc:
                 mem_prealloc = 1;