All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Cc: vishal.l.verma@intel.com
Subject: [ndctl PATCH 14/16] ndctl: Refactor nfit.h to acpi.h
Date: Mon, 06 Jul 2020 19:41:32 -0700	[thread overview]
Message-ID: <159408969293.2386154.5394525810090499368.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <159408961822.2386154.888266173771881937.stgit@dwillia2-desk3.amr.corp.intel.com>

In preparation for adding other acpi table creation helper utilities
make a common acpi.h header with common helpers and definitions.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 acpi.h              |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++
 ndctl/create-nfit.c |   66 ++++++-------------------------
 nfit.h              |   65 ------------------------------
 3 files changed, 124 insertions(+), 117 deletions(-)
 create mode 100644 acpi.h
 delete mode 100644 nfit.h

diff --git a/acpi.h b/acpi.h
new file mode 100644
index 000000000000..06685aa2c90a
--- /dev/null
+++ b/acpi.h
@@ -0,0 +1,110 @@
+/*
+ * ACPI Table Definitions
+ *
+ * Copyright(c) 2013-2017 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+#ifndef __ACPI_H__
+#define __ACPI_H__
+#include <stdint.h>
+#include <linux/uuid.h>
+
+static inline void nfit_spa_uuid_pm(void *uuid)
+{
+	uuid_le uuid_pm = UUID_LE(0x66f0d379, 0xb4f3, 0x4074, 0xac, 0x43, 0x0d,
+			0x33, 0x18, 0xb7, 0x8c, 0xdb);
+	memcpy(uuid, &uuid_pm, 16);
+}
+
+enum {
+	NFIT_TABLE_SPA = 0,
+	SRAT_TABLE_MEM = 1,
+	SRAT_MEM_ENABLED = (1<<0),
+	SRAT_MEM_HOT_PLUGGABLE = (1<<1),
+	SRAT_MEM_NON_VOLATILE = (1<<2),
+};
+
+/**
+ * struct nfit - Nvdimm Firmware Interface Table
+ * @signature: "ACPI"
+ * @length: sum of size of this table plus all appended subtables
+ */
+struct acpi_header {
+	uint8_t signature[4];
+	uint32_t length;
+	uint8_t revision;
+	uint8_t checksum;
+	uint8_t oemid[6];
+	uint64_t oem_tbl_id;
+	uint32_t oem_revision;
+	uint32_t asl_id;
+	uint32_t asl_revision;
+} __attribute__((packed));
+
+struct nfit {
+	struct acpi_header h;
+	uint32_t reserved;
+} __attribute__((packed));
+
+/**
+ * struct nfit_spa - System Physical Address Range Descriptor Table
+ */
+struct nfit_spa {
+	uint16_t type;
+	uint16_t length;
+	uint16_t range_index;
+	uint16_t flags;
+	uint32_t reserved;
+	uint32_t proximity_domain;
+	uint8_t type_uuid[16];
+	uint64_t spa_base;
+	uint64_t spa_length;
+	uint64_t mem_attr;
+} __attribute__((packed));
+
+static inline unsigned char acpi_checksum(void *buf, size_t size)
+{
+        unsigned char sum, *data = buf;
+        size_t i;
+
+        for (sum = 0, i = 0; i < size; i++)
+                sum += data[i];
+        return 0 - sum;
+}
+
+static inline void writeq(uint64_t v, void *a)
+{
+	uint64_t *p = a;
+
+	*p = htole64(v);
+}
+
+static inline void writel(uint32_t v, void *a)
+{
+	uint32_t *p = a;
+
+	*p = htole32(v);
+}
+
+static inline void writew(unsigned short v, void *a)
+{
+	unsigned short *p = a;
+
+	*p = htole16(v);
+}
+
+static inline void writeb(unsigned char v, void *a)
+{
+	unsigned char *p = a;
+
+	*p = v;
+}
+#endif /* __ACPI_H__ */
diff --git a/ndctl/create-nfit.c b/ndctl/create-nfit.c
index 53319182d8a4..8f05eab81494 100644
--- a/ndctl/create-nfit.c
+++ b/ndctl/create-nfit.c
@@ -22,7 +22,7 @@
 #include <util/parse-options.h>
 #include <util/size.h>
 
-#include <nfit.h>
+#include <acpi.h>
 
 #define DEFAULT_NFIT "local_nfit.bin"
 static const char *nfit_file = DEFAULT_NFIT;
@@ -68,44 +68,6 @@ static int parse_add_spa(const struct option *option, const char *__arg, int uns
 	return rc;
 }
 
-static unsigned char nfit_checksum(void *buf, size_t size)
-{
-        unsigned char sum, *data = buf;
-        size_t i;
-
-        for (sum = 0, i = 0; i < size; i++)
-                sum += data[i];
-        return 0 - sum;
-}
-
-static void writeq(unsigned long long v, void *a)
-{
-	unsigned long long *p = a;
-
-	*p = htole64(v);
-}
-
-static void writel(unsigned long v, void *a)
-{
-	unsigned long *p = a;
-
-	*p = htole32(v);
-}
-
-static void writew(unsigned short v, void *a)
-{
-	unsigned short *p = a;
-
-	*p = htole16(v);
-}
-
-static void writeb(unsigned char v, void *a)
-{
-	unsigned char *p = a;
-
-	*p = v;
-}
-
 static struct nfit *create_nfit(struct list_head *spa_list)
 {
 	struct nfit_spa *nfit_spa;
@@ -124,15 +86,15 @@ static struct nfit *create_nfit(struct list_head *spa_list)
 		return NULL;
 
 	/* nfit header */
-	nfit = (struct nfit *) buf;
-	memcpy(nfit->signature, "NFIT", 4);
-	writel(size, &nfit->length);
-	writeb(1, &nfit->revision);
-	memcpy(nfit->oemid, "LOCAL", 6);
-	writew(1, &nfit->oem_tbl_id);
-	writel(1, &nfit->oem_revision);
-	writel(0x80860000, &nfit->creator_id);
-	writel(1, &nfit->creator_revision);
+	nfit = (typeof(nfit)) buf;
+	memcpy(nfit->h.signature, "NFIT", 4);
+	writel(size, &nfit->h.length);
+	writeb(1, &nfit->h.revision);
+	memcpy(nfit->h.oemid, "LOCAL", 6);
+	writew(1, &nfit->h.oem_tbl_id);
+	writel(1, &nfit->h.oem_revision);
+	writel(0x80860000, &nfit->h.asl_id);
+	writel(1, &nfit->h.asl_revision);
 
 	nfit_spa = (struct nfit_spa *) (buf + sizeof(*nfit));
 	i = 1;
@@ -146,7 +108,7 @@ static struct nfit *create_nfit(struct list_head *spa_list)
 		nfit_spa++;
 	}
 
-	writeb(nfit_checksum(buf, size), &nfit->checksum);
+	writeb(acpi_checksum(buf, size), &nfit->h.checksum);
 
 	return nfit;
 }
@@ -170,7 +132,7 @@ static int write_nfit(struct nfit *nfit, const char *file, int force)
 		return -errno;
 	}
 
-	rc = write(fd, nfit, le32toh(nfit->length));
+	rc = write(fd, nfit, le32toh(nfit->h.length));
 	close(fd);
 	return rc;
 }
@@ -210,9 +172,9 @@ int cmd_create_nfit(int argc, const char **argv, struct ndctl_ctx *ctx)
 		goto out;
 
 	rc = write_nfit(nfit, nfit_file, force);
-	if ((unsigned int) rc == le32toh(nfit->length)) {
+	if ((unsigned int) rc == le32toh(nfit->h.length)) {
 		fprintf(stderr, "wrote %d bytes to %s\n",
-				le32toh(nfit->length), nfit_file);
+				le32toh(nfit->h.length), nfit_file);
 		rc = 0;
 	}
 
diff --git a/nfit.h b/nfit.h
deleted file mode 100644
index 9815d2143a9e..000000000000
--- a/nfit.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * NVDIMM Firmware Interface Table - NFIT
- *
- * Copyright(c) 2013-2016 Intel Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- */
-#ifndef __NFIT_H__
-#define __NFIT_H__
-#include <stdint.h>
-#include <linux/uuid.h>
-
-static inline void nfit_spa_uuid_pm(void *uuid)
-{
-	uuid_le uuid_pm = UUID_LE(0x66f0d379, 0xb4f3, 0x4074, 0xac, 0x43, 0x0d,
-			0x33, 0x18, 0xb7, 0x8c, 0xdb);
-	memcpy(uuid, &uuid_pm, 16);
-}
-
-enum {
-	NFIT_TABLE_SPA = 0,
-};
-
-/**
- * struct nfit - Nvdimm Firmware Interface Table
- * @signature: "NFIT"
- * @length: sum of size of this table plus all appended subtables
- */
-struct nfit {
-	uint8_t signature[4];
-	uint32_t length;
-	uint8_t revision;
-	uint8_t checksum;
-	uint8_t oemid[6];
-	uint64_t oem_tbl_id;
-	uint32_t oem_revision;
-	uint32_t creator_id;
-	uint32_t creator_revision;
-	uint32_t reserved;
-} __attribute__((packed));
-
-/**
- * struct nfit_spa - System Physical Address Range Descriptor Table
- */
-struct nfit_spa {
-	uint16_t type;
-	uint16_t length;
-	uint16_t range_index;
-	uint16_t flags;
-	uint32_t reserved;
-	uint32_t proximity_domain;
-	uint8_t type_uuid[16];
-	uint64_t spa_base;
-	uint64_t spa_length;
-	uint64_t mem_attr;
-} __attribute__((packed));
-
-#endif /* __NFIT_H__ */
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

  parent reply	other threads:[~2020-07-07  2:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-07  2:40 [ndctl PATCH 00/16] Firmware Activation and Test Updates Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 01/16] ndctl/build: Fix zero-length array warnings Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 02/16] ndctl/dimm: Fix chatty status messages Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 03/16] ndctl/list: Indicate firmware update capability Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 04/16] ndctl/dimm: Detect firmware-update vs ARS conflict Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 05/16] ndctl/dimm: Improve firmware-update failure message Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 06/16] ndctl/dimm: Prepare to emit dimm json object after firmware update Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 07/16] ndctl/dimm: Emit dimm firmware details after update Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 08/16] ndctl/list: Add firmware activation enumeration Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 09/16] ndctl/dimm: Auto-arm firmware activation Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 10/16] ndctl/bus: Add 'activate-firmware' command Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 11/16] ndctl/docs: Update copyright date Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 12/16] ndctl/test: Test firmware-activation interface Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 13/16] test: Validate strict iomem protections of pmem Dan Williams
2020-07-07  2:41 ` Dan Williams [this message]
2020-07-07  2:41 ` [ndctl PATCH 15/16] daxctl: Add 'split-acpi' command to generate custom ACPI tables Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 16/16] test/ndctl: mremap pmd confusion Dan Williams

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=159408969293.2386154.5394525810090499368.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=vishal.l.verma@intel.com \
    /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 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.