From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xen.org
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
Wei Liu <wei.liu2@citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Konrad Rzeszutek Wilk <konrad@darnok.org>,
Dan Williams <dan.j.williams@intel.com>
Subject: [RFC XEN PATCH v2 09/15] tools/libacpi: add callbacks to access XenStore
Date: Mon, 20 Mar 2017 08:09:43 +0800 [thread overview]
Message-ID: <20170320000949.24675-10-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20170320000949.24675-1-haozhong.zhang@intel.com>
libacpi needs to access information placed in XenStore in order to
load ACPI built by the device model.
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Changes in v2:
* Extract the common part of the existing xenstore_read() and the
new xenstore_directory() in xenbus.c.
---
tools/firmware/hvmloader/util.c | 52 +++++++++++++++++++++++++++++++++++++++
tools/firmware/hvmloader/util.h | 9 +++++++
tools/firmware/hvmloader/xenbus.c | 44 +++++++++++++++++++++++----------
tools/libacpi/libacpi.h | 10 ++++++++
tools/libxl/libxl_x86_acpi.c | 29 ++++++++++++++++++++++
5 files changed, 131 insertions(+), 13 deletions(-)
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index b2372a75be..ec0de711c2 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -893,6 +893,53 @@ static uint8_t acpi_lapic_id(unsigned cpu)
return LAPIC_ID(cpu);
}
+static const char *acpi_xs_read(struct acpi_ctxt *ctxt, const char *path)
+{
+ return xenstore_read(path, NULL);
+}
+
+static int acpi_xs_write(struct acpi_ctxt *ctxt,
+ const char *path, const char *value)
+{
+ return xenstore_write(path, value);
+}
+
+static unsigned int count_strings(const char *strings, unsigned int len)
+{
+ const char *p;
+ unsigned int n;
+
+ for ( p = strings, n = 0; p < strings + len; p++ )
+ if ( *p == '\0' )
+ n++;
+
+ return n;
+}
+
+static char **acpi_xs_directory(struct acpi_ctxt *ctxt,
+ const char *path, unsigned int *num)
+{
+ const char *strings;
+ char *s, *p, **ret;
+ unsigned int len, n;
+
+ strings = xenstore_directory(path, &len, NULL);
+ if ( !strings )
+ return NULL;
+
+ n = count_strings(strings, len);
+ ret = ctxt->mem_ops.alloc(ctxt, n * sizeof(p) + len, 0);
+ if ( !ret )
+ return NULL;
+ memcpy(&ret[n], strings, len);
+
+ s = (char *)&ret[n];
+ for ( p = s, *num = 0; p < s + len; p += strlen(p) + 1 )
+ ret[(*num)++] = p;
+
+ return ret;
+}
+
void hvmloader_acpi_build_tables(struct acpi_config *config,
unsigned int physical)
{
@@ -979,6 +1026,11 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
ctxt.min_alloc_byte_align = 16;
+ ctxt.xs_ops.read = acpi_xs_read;
+ ctxt.xs_ops.write = acpi_xs_write;
+ ctxt.xs_ops.directory = acpi_xs_directory;
+ ctxt.xs_opaque = NULL;
+
acpi_build_tables(&ctxt, config);
hvm_param_set(HVM_PARAM_VM_GENERATION_ID_ADDR, config->vm_gid_addr);
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 6a50dae1eb..ac10a7106a 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -225,6 +225,15 @@ const char *xenstore_read(const char *path, const char *default_resp);
*/
int xenstore_write(const char *path, const char *value);
+/* Read a xenstore directory. Return NULL, or a nul-terminated string
+ * which contains all names of directory entries. Names are separated
+ * by '\0'. The returned string is in a static buffer, so only valid
+ * until the next xenstore/xenbus operation. If @default_resp is
+ * specified, it is returned in preference to a NULL or empty string
+ * received from xenstore.
+ */
+const char *xenstore_directory(const char *path, uint32_t *len,
+ const char *default_resp);
/* Get a HVM param.
*/
diff --git a/tools/firmware/hvmloader/xenbus.c b/tools/firmware/hvmloader/xenbus.c
index 448157dcb0..8cad7af019 100644
--- a/tools/firmware/hvmloader/xenbus.c
+++ b/tools/firmware/hvmloader/xenbus.c
@@ -245,24 +245,16 @@ static int xenbus_recv(uint32_t *reply_len, const char **reply_data,
return 0;
}
-
-/* Read a xenstore key. Returns a nul-terminated string (even if the XS
- * data wasn't nul-terminated) or NULL. The returned string is in a
- * static buffer, so only valid until the next xenstore/xenbus operation.
- * If @default_resp is specified, it is returned in preference to a NULL or
- * empty string received from xenstore.
- */
-const char *xenstore_read(const char *path, const char *default_resp)
+static const char *xenstore_read_common(const char *path, uint32_t *len,
+ const char *default_resp, bool is_dir)
{
- uint32_t len = 0, type = 0;
+ uint32_t type = 0, expected_type = is_dir ? XS_DIRECTORY : XS_READ;
const char *answer = NULL;
- xenbus_send(XS_READ,
- path, strlen(path),
- "", 1, /* nul separator */
+ xenbus_send(expected_type, path, strlen(path), "", 1, /* nul separator */
NULL, 0);
- if ( xenbus_recv(&len, &answer, &type) || (type != XS_READ) )
+ if ( xenbus_recv(len, &answer, &type) || type != expected_type )
answer = NULL;
if ( (default_resp != NULL) && ((answer == NULL) || (*answer == '\0')) )
@@ -272,6 +264,32 @@ const char *xenstore_read(const char *path, const char *default_resp)
return answer;
}
+/* Read a xenstore key. Returns a nul-terminated string (even if the XS
+ * data wasn't nul-terminated) or NULL. The returned string is in a
+ * static buffer, so only valid until the next xenstore/xenbus operation.
+ * If @default_resp is specified, it is returned in preference to a NULL or
+ * empty string received from xenstore.
+ */
+const char *xenstore_read(const char *path, const char *default_resp)
+{
+ uint32_t len = 0;
+
+ return xenstore_read_common(path, &len, default_resp, false);
+}
+
+/* Read a xenstore directory. Return NULL, or a nul-terminated string
+ * which contains all names of directory entries. Names are separated
+ * by '\0'. The returned string is in a static buffer, so only valid
+ * until the next xenstore/xenbus operation. If @default_resp is
+ * specified, it is returned in preference to a NULL or empty string
+ * received from xenstore.
+ */
+const char *xenstore_directory(const char *path, uint32_t *len,
+ const char *default_resp)
+{
+ return xenstore_read_common(path, len, default_resp, true);
+}
+
/* Write a xenstore key. @value must be a nul-terminated string. Returns
* zero on success or a xenstore error code on failure.
*/
diff --git a/tools/libacpi/libacpi.h b/tools/libacpi/libacpi.h
index 48acf9583c..645e091f68 100644
--- a/tools/libacpi/libacpi.h
+++ b/tools/libacpi/libacpi.h
@@ -54,6 +54,16 @@ struct acpi_ctxt {
} mem_ops;
uint32_t min_alloc_byte_align; /* minimum alignment used by mem_ops.alloc */
+
+ struct acpi_xs_ops {
+ const char *(*read)(struct acpi_ctxt *ctxt, const char *path);
+ int (*write)(struct acpi_ctxt *ctxt,
+ const char *path, const char *value);
+ char **(*directory)(struct acpi_ctxt *ctxt,
+ const char *path, unsigned int *num);
+ } xs_ops;
+
+ void *xs_opaque;
};
struct acpi_config {
diff --git a/tools/libxl/libxl_x86_acpi.c b/tools/libxl/libxl_x86_acpi.c
index 2622e03ce6..591a4f44fa 100644
--- a/tools/libxl/libxl_x86_acpi.c
+++ b/tools/libxl/libxl_x86_acpi.c
@@ -93,6 +93,25 @@ static void acpi_mem_free(struct acpi_ctxt *ctxt,
{
}
+static const char *acpi_xs_read(struct acpi_ctxt *ctxt, const char *path)
+{
+ return libxl__xs_read((libxl__gc *)ctxt->xs_opaque, XBT_NULL, path);
+}
+
+static int acpi_xs_write(struct acpi_ctxt *ctxt,
+ const char *path, const char *value)
+{
+ return libxl__xs_write_checked((libxl__gc *)ctxt->xs_opaque, XBT_NULL,
+ path, value);
+}
+
+static char **acpi_xs_directory(struct acpi_ctxt *ctxt,
+ const char *path, unsigned int *num)
+{
+ return libxl__xs_directory((libxl__gc *)ctxt->xs_opaque, XBT_NULL,
+ path, num);
+}
+
static uint8_t acpi_lapic_id(unsigned cpu)
{
return cpu * 2;
@@ -195,6 +214,16 @@ int libxl__dom_load_acpi(libxl__gc *gc,
libxl_ctxt.c.min_alloc_byte_align = 16;
+ libxl_ctxt.c.xs_ops.read = acpi_xs_read;
+ libxl_ctxt.c.xs_ops.write = acpi_xs_write;
+ libxl_ctxt.c.xs_ops.directory = acpi_xs_directory;
+ libxl_ctxt.c.xs_opaque = gc;
+
+ libxl_ctxt.c.xs_ops.read = acpi_xs_read;
+ libxl_ctxt.c.xs_ops.write = acpi_xs_write;
+ libxl_ctxt.c.xs_ops.directory = acpi_xs_directory;
+ libxl_ctxt.c.xs_opaque = gc;
+
rc = init_acpi_config(gc, dom, b_info, &config);
if (rc) {
LOG(ERROR, "init_acpi_config failed (rc=%d)", rc);
--
2.12.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-03-20 0:09 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-20 0:09 [RFC XEN PATCH v2 00/15] Add vNVDIMM support to HVM domains Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 01/15] xen/common: add Kconfig item for pmem support Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 02/15] xen: probe pmem regions via ACPI NFIT Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 03/15] xen/x86: allow customizing locations of extended frametable & M2P Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 04/15] xen/x86: add XEN_SYSCTL_nvdimm_pmem_setup to setup host pmem Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 05/15] xen/x86: add XENMEM_populate_pmem_map to map host pmem pages to HVM domain Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 06/15] tools: reserve guest memory for ACPI from device model Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 07/15] tools/libacpi: expose the minimum alignment used by mem_ops.alloc Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 08/15] tools/libacpi: add callback acpi_ctxt.p2v to get a pointer from physical address Haozhong Zhang
2017-03-20 0:09 ` Haozhong Zhang [this message]
2017-03-20 0:09 ` [RFC XEN PATCH v2 10/15] tools/libacpi: add a simple AML builder Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 11/15] tools/libacpi: load ACPI built by the device model Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 12/15] tools/libxl: build qemu options from xl vNVDIMM configs Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 13/15] tools/libxl: add support to map host pmem device to guests Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 14/15] tools/libxl: initiate pmem mapping via qmp callback Haozhong Zhang
2017-03-20 0:09 ` [RFC XEN PATCH v2 15/15] tools/misc: add xen-ndctl Haozhong Zhang
2017-03-30 4:11 ` Dan Williams
2017-03-30 7:58 ` Haozhong Zhang
2017-04-01 11:55 ` Konrad Rzeszutek Wilk
2017-03-30 4:20 ` [RFC XEN PATCH v2 00/15] Add vNVDIMM support to HVM domains Dan Williams
2017-03-30 8:21 ` Haozhong Zhang
2017-03-30 16:01 ` Dan Williams
2017-04-01 11:54 ` Konrad Rzeszutek Wilk
2017-04-01 15:45 ` Dan Williams
2017-04-04 17:00 ` Konrad Rzeszutek Wilk
2017-04-04 17:16 ` Dan Williams
2017-04-04 17:34 ` Konrad Rzeszutek Wilk
2017-04-04 17:59 ` Dan Williams
2017-04-04 18:05 ` Konrad Rzeszutek Wilk
2017-04-04 18:59 ` Dan Williams
2017-04-11 17:48 ` Konrad Rzeszutek Wilk
2017-04-01 12:24 ` Konrad Rzeszutek Wilk
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=20170320000949.24675-10-haozhong.zhang@intel.com \
--to=haozhong.zhang@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=dan.j.williams@intel.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=konrad@darnok.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).