Module Name: src
Committed By: maxv
Date: Thu Dec 28 08:49:28 UTC 2017
Modified Files:
src/sys/dev/acpi: acpi_srat.c acpi_srat.h
Log Message:
Style, export struct acpisrat_node, and add acpisrat_get_node.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/acpi_srat.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/acpi_srat.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/acpi/acpi_srat.c
diff -u src/sys/dev/acpi/acpi_srat.c:1.4 src/sys/dev/acpi/acpi_srat.c:1.5
--- src/sys/dev/acpi/acpi_srat.c:1.4 Thu Aug 31 08:45:03 2017
+++ src/sys/dev/acpi/acpi_srat.c Thu Dec 28 08:49:28 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_srat.c,v 1.4 2017/08/31 08:45:03 msaitoh Exp $ */
+/* $NetBSD: acpi_srat.c,v 1.5 2017/12/28 08:49:28 maxv Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_srat.c,v 1.4 2017/08/31 08:45:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_srat.c,v 1.5 2017/12/28 08:49:28 maxv Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@@ -41,14 +41,6 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_srat.c,
static ACPI_TABLE_SRAT *srat;
-struct acpisrat_node {
- acpisrat_nodeid_t nodeid;
- uint32_t ncpus; /* Number of cpus in this node */
- struct acpisrat_cpu **cpu; /* Array of cpus */
- uint32_t nmems; /* Number of memory ranges in this node */
- struct acpisrat_mem **mem; /* Array of memory ranges */
-};
-
static uint32_t nnodes; /* Number of NUMA nodes */
static struct acpisrat_node *node_array; /* Array of NUMA nodes */
static uint32_t ncpus; /* Number of CPUs */
@@ -56,7 +48,6 @@ static struct acpisrat_cpu *cpu_array; /
static uint32_t nmems; /* Number of Memory ranges */
static struct acpisrat_mem *mem_array;
-
struct cpulist {
struct acpisrat_cpu cpu;
TAILQ_ENTRY(cpulist) entry;
@@ -64,12 +55,11 @@ struct cpulist {
static TAILQ_HEAD(, cpulist) cpulisthead;
-#define CPU_INIT TAILQ_INIT(&cpulisthead);
+#define CPU_INIT() TAILQ_INIT(&cpulisthead);
#define CPU_FOREACH(cpu) TAILQ_FOREACH(cpu, &cpulisthead, entry)
#define CPU_ADD(cpu) TAILQ_INSERT_TAIL(&cpulisthead, cpu, entry)
#define CPU_REM(cpu) TAILQ_REMOVE(&cpulisthead, cpu, entry)
-#define CPU_FIRST TAILQ_FIRST(&cpulisthead)
-
+#define CPU_FIRST() TAILQ_FIRST(&cpulisthead)
struct memlist {
struct acpisrat_mem mem;
@@ -78,12 +68,12 @@ struct memlist {
static TAILQ_HEAD(, memlist) memlisthead;
-#define MEM_INIT TAILQ_INIT(&memlisthead)
+#define MEM_INIT() TAILQ_INIT(&memlisthead)
#define MEM_FOREACH(mem) TAILQ_FOREACH(mem, &memlisthead, entry)
#define MEM_ADD(mem) TAILQ_INSERT_TAIL(&memlisthead, mem, entry)
#define MEM_ADD_BEFORE(mem, b) TAILQ_INSERT_BEFORE(b, mem, entry)
#define MEM_REM(mem) TAILQ_REMOVE(&memlisthead, mem, entry)
-#define MEM_FIRST TAILQ_FIRST(&memlisthead)
+#define MEM_FIRST() TAILQ_FIRST(&memlisthead)
static struct cpulist *
@@ -98,21 +88,6 @@ cpu_free(struct cpulist *c)
kmem_free(c, sizeof(struct cpulist));
}
-#if 0
-static struct cpulist *
-cpu_get(acpisrat_nodeid_t nodeid)
-{
- struct cpulist *tmp;
-
- CPU_FOREACH(tmp) {
- if (tmp->cpu.nodeid == nodeid)
- return tmp;
- }
-
- return NULL;
-}
-#endif
-
static struct memlist *
mem_alloc(void)
{
@@ -138,7 +113,10 @@ mem_get(acpisrat_nodeid_t nodeid)
return NULL;
}
-
+/*
+ * Returns true if ACPI SRAT table is available. If table does not exist, all
+ * functions below have undefined behaviour.
+ */
bool
acpisrat_exist(void)
{
@@ -232,12 +210,13 @@ acpisrat_parse(void)
break;
nodeid = srat_x2apic->ProximityDomain;
- /* This table entry overrides
+ /*
+ * This table entry overrides
* ACPI_SRAT_TYPE_CPU_AFFINITY.
*/
if (!ignore_cpu_affinity) {
struct cpulist *citer;
- while ((citer = CPU_FIRST) != NULL) {
+ while ((citer = CPU_FIRST()) != NULL) {
CPU_REM(citer);
cpu_free(citer);
}
@@ -273,14 +252,13 @@ acpisrat_quirks(void)
/* Some sanity checks. */
- /* Deal with holes in the memory nodes.
- * BIOS doesn't enlist memory nodes which
- * don't have any memory modules plugged in.
- * This behaviour has been observed on AMD machines.
+ /*
+ * Deal with holes in the memory nodes. BIOS doesn't enlist memory
+ * nodes which don't have any memory modules plugged in. This behaviour
+ * has been observed on AMD machines.
*
- * Do that by searching for CPUs in NUMA nodes
- * which don't exist in the memory and then insert
- * a zero memory range for the missing node.
+ * Do that by searching for CPUs in NUMA nodes which don't exist in the
+ * memory and then insert a zero memory range for the missing node.
*/
CPU_FOREACH(citer) {
mem = mem_get(citer->cpu.nodeid);
@@ -303,6 +281,10 @@ acpisrat_quirks(void)
return 0;
}
+/*
+ * Initializes parser. Must be the first function being called when table is
+ * available.
+ */
int
acpisrat_init(void)
{
@@ -311,6 +293,9 @@ acpisrat_init(void)
return acpisrat_refresh();
}
+/*
+ * Re-parse ACPI SRAT table. Useful after hotplugging cpu or RAM.
+ */
int
acpisrat_refresh(void)
{
@@ -319,8 +304,8 @@ acpisrat_refresh(void)
struct memlist *miter;
uint32_t cnodes = 0, mnodes = 0;
- CPU_INIT;
- MEM_INIT;
+ CPU_INIT();
+ MEM_INIT();
rc = acpisrat_parse();
if (rc)
@@ -335,7 +320,6 @@ acpisrat_refresh(void)
if (rc)
return rc;
- nnodes = 0;
ncpus = 0;
CPU_FOREACH(citer) {
cnodes = MAX(citer->cpu.nodeid, cnodes);
@@ -404,12 +388,12 @@ acpisrat_refresh(void)
}
}
- while ((citer = CPU_FIRST) != NULL) {
+ while ((citer = CPU_FIRST()) != NULL) {
CPU_REM(citer);
cpu_free(citer);
}
- while ((miter = MEM_FIRST) != NULL) {
+ while ((miter = MEM_FIRST()) != NULL) {
MEM_REM(miter);
mem_free(miter);
}
@@ -417,7 +401,10 @@ acpisrat_refresh(void)
return 0;
}
-
+/*
+ * Free allocated memory. Should be called when acpisrat is no longer of any
+ * use.
+ */
int
acpisrat_exit(void)
{
@@ -451,7 +438,6 @@ acpisrat_exit(void)
return 0;
}
-
void
acpisrat_dump(void)
{
@@ -482,18 +468,27 @@ acpisrat_dump(void)
}
}
+/*
+ * Get number of NUMA nodes.
+ */
uint32_t
acpisrat_nodes(void)
{
return nnodes;
}
+/*
+ * Get number of cpus in the node. 0 means, this is a cpu-less node.
+ */
uint32_t
acpisrat_node_cpus(acpisrat_nodeid_t nodeid)
{
return node_array[nodeid].ncpus;
}
+/*
+ * Get number of memory ranges in the node 0 means, this node has no RAM.
+ */
uint32_t
acpisrat_node_memoryranges(acpisrat_nodeid_t nodeid)
{
@@ -515,3 +510,28 @@ acpisrat_mem(acpisrat_nodeid_t nodeid, u
memcpy(mem, node_array[nodeid].mem[memrange],
sizeof(struct acpisrat_mem));
}
+
+/*
+ * Get a node from an APIC id (belonging to a cpu).
+ */
+struct acpisrat_node *
+acpisrat_get_node(uint32_t apicid)
+{
+ struct acpisrat_node *node;
+ struct acpisrat_cpu *cpu;
+ size_t i, n;
+
+ for (i = 0; i < nnodes; i++) {
+ node = &node_array[i];
+
+ for (n = 0; n < node->ncpus; n++) {
+ cpu = node->cpu[n];
+ if (cpu->apicid == apicid) {
+ return node;
+ }
+ }
+ }
+
+ return NULL;
+}
+
Index: src/sys/dev/acpi/acpi_srat.h
diff -u src/sys/dev/acpi/acpi_srat.h:1.3 src/sys/dev/acpi/acpi_srat.h:1.4
--- src/sys/dev/acpi/acpi_srat.h:1.3 Fri Mar 5 08:30:48 2010
+++ src/sys/dev/acpi/acpi_srat.h Thu Dec 28 08:49:28 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_srat.h,v 1.3 2010/03/05 08:30:48 jruoho Exp $ */
+/* $NetBSD: acpi_srat.h,v 1.4 2017/12/28 08:49:28 maxv Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -40,7 +40,8 @@ struct acpisrat_cpu {
uint32_t sapiceid;
uint32_t flags;
- /* clockdomain has a meaningful value when the ACPI MADT table has
+ /*
+ * clockdomain has a meaningful value when the ACPI MADT table has
* ACPI_MADT_TYPE_LOCAL_X2APIC and/or ACPI_MADT_TYPE_LOCAL_X2APIC_NMI
* entries or ACPI CPU device have a _CDM.
*/
@@ -54,45 +55,24 @@ struct acpisrat_mem {
uint32_t flags;
};
-/* Returns true if ACPI SRAT table is available.
- *
- * If table does not exist, all functions below
- * have undefined behaviour.
- */
-bool acpisrat_exist(void);
+struct acpisrat_node {
+ acpisrat_nodeid_t nodeid; /* Proximity domain */
+ uint32_t ncpus; /* Number of cpus in this node */
+ struct acpisrat_cpu **cpu; /* Array of cpus */
+ uint32_t nmems; /* Number of memory ranges in this node */
+ struct acpisrat_mem **mem; /* Array of memory ranges */
+};
-/* Initializes parser. Must be the first function
- * being called when table is available.
- */
+bool acpisrat_exist(void);
int acpisrat_init(void);
-
-/* Re-parse ACPI SRAT table. Useful after
- * hotplugging cpu or RAM.
- */
int acpisrat_refresh(void);
-
-/* Free allocated memory. Should be called
- * when acpisrat is no longer of any use.
- */
int acpisrat_exit(void);
-
void acpisrat_dump(void);
-
-/* Get number of NUMA nodes */
uint32_t acpisrat_nodes(void);
-
-/* Get number of cpus in the node.
- * 0 means, this is a cpu-less node.
- */
uint32_t acpisrat_node_cpus(acpisrat_nodeid_t);
-
-/* Get number of memory ranges in the node
- * 0 means, this node has no RAM.
- */
uint32_t acpisrat_node_memoryranges(acpisrat_nodeid_t);
-
-/* Retrieve cpu and memory info. */
-void acpisrat_cpu(acpisrat_nodeid_t, uint32_t cpunum, struct acpisrat_cpu *);
-void acpisrat_mem(acpisrat_nodeid_t, uint32_t memrange, struct acpisrat_mem *);
+void acpisrat_cpu(acpisrat_nodeid_t, uint32_t, struct acpisrat_cpu *);
+void acpisrat_mem(acpisrat_nodeid_t, uint32_t, struct acpisrat_mem *);
+struct acpisrat_node *acpisrat_get_node(uint32_t);
#endif /* !_SYS_DEV_ACPI_ACPI_SRAT_H */