Message ID | 1402935486-29136-20-git-send-email-julien.grall@linaro.org |
---|---|
State | Superseded, archived |
Headers | show |
On Mon, Jun 16, 2014 at 05:18:06PM +0100, Julien Grall wrote: [...] > + if (!xlu_cfg_get_list (config, "dtdev", &dtdevs, 0, 0)) { > + d_config->num_dtdevs = 0; > + d_config->dtdevs = NULL; > + for (i = 0; (buf = xlu_cfg_get_listitem(dtdevs, i)) != NULL; i++) { > + libxl_device_dt *dtdev; > + > + d_config->dtdevs = (libxl_device_dt *) realloc(d_config->dtdevs, sizeof (libxl_device_dt) * (d_config->num_dtdevs + 1)); > + dtdev = d_config->dtdevs + d_config->num_dtdevs; > + libxl_device_dt_init(dtdev); > + There's a macro called ARRAY_EXTEND_INIT, you can probably use that. Wei.
Hi Wei, On 06/16/2014 06:19 PM, Wei Liu wrote: > On Mon, Jun 16, 2014 at 05:18:06PM +0100, Julien Grall wrote: > [...] >> + if (!xlu_cfg_get_list (config, "dtdev", &dtdevs, 0, 0)) { >> + d_config->num_dtdevs = 0; >> + d_config->dtdevs = NULL; >> + for (i = 0; (buf = xlu_cfg_get_listitem(dtdevs, i)) != NULL; i++) { >> + libxl_device_dt *dtdev; >> + >> + d_config->dtdevs = (libxl_device_dt *) realloc(d_config->dtdevs, sizeof (libxl_device_dt) * (d_config->num_dtdevs + 1)); >> + dtdev = d_config->dtdevs + d_config->num_dtdevs; >> + libxl_device_dt_init(dtdev); >> + > > There's a macro called ARRAY_EXTEND_INIT, you can probably use that. I can't use this macro because it requires to have a field devid in the structure. I don't think it worth to add this field just for code conciseness. Though I can add rename this macro into ARRAY_EXTEND_INIT_DEVID and introduce an ARRAY_EXTEND_INIT that could be use in more general case. Regards,
On Wed, Jun 18, 2014 at 02:40:37PM +0100, Julien Grall wrote: > Hi Wei, > > On 06/16/2014 06:19 PM, Wei Liu wrote: > > On Mon, Jun 16, 2014 at 05:18:06PM +0100, Julien Grall wrote: > > [...] > >> + if (!xlu_cfg_get_list (config, "dtdev", &dtdevs, 0, 0)) { > >> + d_config->num_dtdevs = 0; > >> + d_config->dtdevs = NULL; > >> + for (i = 0; (buf = xlu_cfg_get_listitem(dtdevs, i)) != NULL; i++) { > >> + libxl_device_dt *dtdev; > >> + > >> + d_config->dtdevs = (libxl_device_dt *) realloc(d_config->dtdevs, sizeof (libxl_device_dt) * (d_config->num_dtdevs + 1)); > >> + dtdev = d_config->dtdevs + d_config->num_dtdevs; > >> + libxl_device_dt_init(dtdev); > >> + > > > > There's a macro called ARRAY_EXTEND_INIT, you can probably use that. > > I can't use this macro because it requires to have a field devid in the > structure. Ah, OK. In that case, you need to use xrealloc in your code. > > I don't think it worth to add this field just for code conciseness. > Though I can add rename this macro into ARRAY_EXTEND_INIT_DEVID and > introduce an ARRAY_EXTEND_INIT that could be use in more general case. > No need to do that in my opinion. Wei. > Regards, > > -- > Julien Grall
On 06/18/2014 02:43 PM, Wei Liu wrote: > On Wed, Jun 18, 2014 at 02:40:37PM +0100, Julien Grall wrote: >> Hi Wei, >> >> On 06/16/2014 06:19 PM, Wei Liu wrote: >>> On Mon, Jun 16, 2014 at 05:18:06PM +0100, Julien Grall wrote: >>> [...] >>>> + if (!xlu_cfg_get_list (config, "dtdev", &dtdevs, 0, 0)) { >>>> + d_config->num_dtdevs = 0; >>>> + d_config->dtdevs = NULL; >>>> + for (i = 0; (buf = xlu_cfg_get_listitem(dtdevs, i)) != NULL; i++) { >>>> + libxl_device_dt *dtdev; >>>> + >>>> + d_config->dtdevs = (libxl_device_dt *) realloc(d_config->dtdevs, sizeof (libxl_device_dt) * (d_config->num_dtdevs + 1)); >>>> + dtdev = d_config->dtdevs + d_config->num_dtdevs; >>>> + libxl_device_dt_init(dtdev); >>>> + >>> >>> There's a macro called ARRAY_EXTEND_INIT, you can probably use that. >> >> I can't use this macro because it requires to have a field devid in the >> structure. > > Ah, OK. > > In that case, you need to use xrealloc in your code. Right, I blindly copied the pcidevs code which is also using realloc. I will fix both of them in my next series. Regards,
diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5 index 025df27..fdadbe6 100644 --- a/docs/man/xl.cfg.pod.5 +++ b/docs/man/xl.cfg.pod.5 @@ -601,6 +601,11 @@ More information about Xen gfx_passthru feature is available on the XenVGAPassthrough L<http://wiki.xen.org/wiki/XenVGAPassthrough> wiki page. +=item B<dtdev=[ "DTDEV_PATH", "DTDEV_PATH", ... ]> + +Specifies the host device node to passthrough to this guest. Each DTDEV_PATH +is the absolute path in the device tree. + =item B<ioports=[ "IOPORT_RANGE", "IOPORT_RANGE", ... ]> Allow guest to access specific legacy I/O ports. Each B<IOPORT_RANGE> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index f99e6b6..3ecc804 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -702,7 +702,7 @@ static void parse_config_data(const char *config_source, long l; XLU_Config *config; XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms; - XLU_ConfigList *ioports, *irqs, *iomem; + XLU_ConfigList *ioports, *irqs, *iomem, *dtdevs; int num_ioports, num_irqs, num_iomem; int pci_power_mgmt = 0; int pci_msitranslate = 0; @@ -1463,6 +1463,25 @@ skip_vfb: libxl_defbool_set(&b_info->u.pv.e820_host, true); } + if (!xlu_cfg_get_list (config, "dtdev", &dtdevs, 0, 0)) { + d_config->num_dtdevs = 0; + d_config->dtdevs = NULL; + for (i = 0; (buf = xlu_cfg_get_listitem(dtdevs, i)) != NULL; i++) { + libxl_device_dt *dtdev; + + d_config->dtdevs = (libxl_device_dt *) realloc(d_config->dtdevs, sizeof (libxl_device_dt) * (d_config->num_dtdevs + 1)); + dtdev = d_config->dtdevs + d_config->num_dtdevs; + libxl_device_dt_init(dtdev); + + dtdev->path = strdup(buf); + if (dtdev->path == NULL) { + fprintf(stderr, "unable to duplicate string for dtdevs\n"); + exit(-1); + } + d_config->num_dtdevs++; + } + } + switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) { case 0: {
The option "dtdev" will be used to passthrough a non-PCI device described in the device tree to a guest. Signed-off-by: Julien Grall <julien.grall@linaro.org> Cc: Ian Jackson <ian.jackson@eu.citrix.com> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Cc: Ian Campbell <ian.campbell@citrix.com> --- docs/man/xl.cfg.pod.5 | 5 +++++ tools/libxl/xl_cmdimpl.c | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-)