From 6cee668a21a09793936f35cba5e74a83291caef0 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Mon, 1 Feb 2021 20:35:41 +0100
Subject: [PATCH 6/6] kernel/mptable: Remove the unused 'name' member of struct
 BASETABLE_ENTRY.

While here, make the entry type an enum and use it appropriately.
---
 sys/platform/pc64/x86_64/mptable.c | 80 ++++++++++++++++--------------
 1 file changed, 43 insertions(+), 37 deletions(-)

diff --git a/sys/platform/pc64/x86_64/mptable.c b/sys/platform/pc64/x86_64/mptable.c
index 68537f8aa41..5e0a8477534 100644
--- a/sys/platform/pc64/x86_64/mptable.c
+++ b/sys/platform/pc64/x86_64/mptable.c
@@ -83,6 +83,13 @@ TUNABLE_INT("hw.lapic_force_enable", &force_enable);
 #define PROCENTRY_FLAG_BP	0x02
 #define IOAPICENTRY_FLAG_EN	0x01
 
+enum entry_type {
+	BTE_PROCESSOR,	/* Processor */
+	BTE_BUS,	/* Bus */
+	BTE_IOAPIC,	/* I/O APIC */
+	BTE_IOINT,	/* I/O INT */
+	BTE_LINT	/* Local INT */
+};
 
 /* MP Floating Pointer Structure */
 typedef struct MPFPS {
@@ -117,7 +124,7 @@ typedef struct MPCTH {
 
 
 typedef struct PROCENTRY {
-	u_char  type;
+	enum entry_type type;
 	u_char  apic_id;
 	u_char  apic_version;
 	u_char  cpu_flags;
@@ -128,13 +135,13 @@ typedef struct PROCENTRY {
 }      *proc_entry_ptr;
 
 typedef struct BUSENTRY {
-	u_char  type;
+	enum entry_type type;
 	u_char  bus_id;
 	char    bus_type[6];
 }      *bus_entry_ptr;
 
 typedef struct IOAPICENTRY {
-	u_char  type;
+	enum entry_type type;
 	u_char  apic_id;
 	u_char  apic_version;
 	u_char  apic_flags;
@@ -142,7 +149,7 @@ typedef struct IOAPICENTRY {
 }      *io_apic_entry_ptr;
 
 typedef struct INTENTRY {
-	u_char  type;
+	enum entry_type type;
 	u_char  int_type;
 	u_short int_flags;
 	u_char  src_bus_id;
@@ -153,9 +160,8 @@ typedef struct INTENTRY {
 
 /* descriptions of MP basetable entries */
 typedef struct BASETABLE_ENTRY {
-	u_char  type;
+	enum entry_type type;
 	u_char  length;
-	char    name[16];
 }       basetable_entry;
 
 struct mptable_pos {
@@ -199,7 +205,7 @@ struct mptable_ioapic {
 	TAILQ_ENTRY(mptable_ioapic) mio_link;
 };
 
-typedef	int	(*mptable_iter_func)(void *, const void *, int);
+typedef	int	(*mptable_iter_func)(void *, const void *, enum entry_type);
 
 static int	mptable_iterate_entries(const mpcth_t,
 		    mptable_iter_func, void *);
@@ -219,13 +225,12 @@ static void	mptable_lapic_default(void);
 static int	mptable_ioapic_probe(struct ioapic_enumerator *);
 static void	mptable_ioapic_enumerate(struct ioapic_enumerator *);
 
-static basetable_entry basetable_entry_types[] =
-{
-	{0, 20, "Processor"},
-	{1, 8, "Bus"},
-	{2, 8, "I/O APIC"},
-	{3, 8, "I/O INT"},
-	{4, 8, "Local INT"}
+static basetable_entry basetable_entry_types[] = {
+	{ BTE_PROCESSOR, 20 },
+	{ BTE_BUS,	  8 },
+	{ BTE_IOAPIC,	  8 },
+	{ BTE_IOINT,	  8 },
+	{ BTE_LINT,	  8 }
 };
 
 static vm_paddr_t	mptable_fps_phyaddr;
@@ -312,7 +317,8 @@ mptable_iterate_entries(const mpcth_t cth, mptable_iter_func func, void *arg)
 	count = cth->entry_count;
 
 	while (count--) {
-		int type, error;
+		enum entry_type type;
+		int error;
 
 		KKASSERT(total_size >= 0);
 		if (total_size == 0) {
@@ -323,11 +329,11 @@ mptable_iterate_entries(const mpcth_t cth, mptable_iter_func func, void *arg)
 
 		type = *(const uint8_t *)position;
 		switch (type) {
-		case 0: /* processor_entry */
-		case 1: /* bus_entry */
-		case 2: /* io_apic_entry */
-		case 3: /* int_entry */
-		case 4:	/* int_entry */
+		case BTE_PROCESSOR:	/* processor_entry */
+		case BTE_BUS:		/* bus_entry */
+		case BTE_IOAPIC:	/* io_apic_entry */
+		case BTE_IOINT:		/* int_entry */
+		case BTE_LINT:		/* int_entry */
 			break;
 		default:
 			kprintf("unknown base MP table entry type %d\n", type);
@@ -577,13 +583,13 @@ processor_entry(const struct PROCENTRY *entry, int cpu)
 }
 
 static int
-mptable_bus_info_callback(void *xarg, const void *pos, int type)
+mptable_bus_info_callback(void *xarg, const void *pos, enum entry_type type)
 {
 	struct mptable_bus_info *bus_info = xarg;
 	const struct BUSENTRY *ent;
 	struct mptable_bus *bus;
 
-	if (type != 1)
+	if (type != BTE_BUS)
 		return 0;
 
 	ent = pos;
@@ -642,12 +648,12 @@ struct mptable_lapic_cbarg1 {
 };
 
 static int
-mptable_lapic_pass1_callback(void *xarg, const void *pos, int type)
+mptable_lapic_pass1_callback(void *xarg, const void *pos, enum entry_type type)
 {
 	const struct PROCENTRY *ent;
 	struct mptable_lapic_cbarg1 *arg = xarg;
 
-	if (type != 0)
+	if (type != BTE_PROCESSOR)
 		return 0;
 	ent = pos;
 
@@ -671,12 +677,12 @@ struct mptable_lapic_cbarg2 {
 };
 
 static int
-mptable_lapic_pass2_callback(void *xarg, const void *pos, int type)
+mptable_lapic_pass2_callback(void *xarg, const void *pos, enum entry_type type)
 {
 	const struct PROCENTRY *ent;
 	struct mptable_lapic_cbarg2 *arg = xarg;
 
-	if (type != 0)
+	if (type != BTE_PROCESSOR)
 		return 0;
 	ent = pos;
 
@@ -698,7 +704,7 @@ mptable_lapic_pass2_callback(void *xarg, const void *pos, int type)
 		 * enumerate the logical CPUs.
 		 */
 		bzero(&proc, sizeof(proc));
-		proc.type = 0;
+		proc.type = BTE_PROCESSOR;
 		proc.cpu_flags = (force_enable) ? PROCENTRY_FLAG_EN : ent->cpu_flags;
 		proc.apic_id = ent->apic_id;
 
@@ -815,12 +821,12 @@ struct mptable_lapic_probe_cbarg {
 };
 
 static int
-mptable_lapic_probe_callback(void *xarg, const void *pos, int type)
+mptable_lapic_probe_callback(void *xarg, const void *pos, enum entry_type type)
 {
 	const struct PROCENTRY *ent;
 	struct mptable_lapic_probe_cbarg *arg = xarg;
 
-	if (type != 0)
+	if (type != BTE_PROCESSOR)
 		return 0;
 	ent = pos;
 
@@ -901,12 +907,12 @@ SYSINIT(mptable_lapic, SI_BOOT2_PRESMP, SI_ORDER_ANY,
 	mptable_lapic_enum_register, 0);
 
 static int
-mptable_ioapic_list_callback(void *xarg, const void *pos, int type)
+mptable_ioapic_list_callback(void *xarg, const void *pos, enum entry_type type)
 {
 	const struct IOAPICENTRY *ent;
 	struct mptable_ioapic *nioapic, *ioapic;
 
-	if (type != 2)
+	if (type != BTE_IOAPIC)
 		return 0;
 	ent = pos;
 
@@ -1007,7 +1013,7 @@ SYSINIT(mptable_ioapic_list, SI_BOOT2_PRESMP, SI_ORDER_SECOND,
 	mptable_ioapic_create_list, 0);
 
 static int
-mptable_pci_int_callback(void *xarg, const void *pos, int type)
+mptable_pci_int_callback(void *xarg, const void *pos, enum entry_type type)
 {
 	const struct mptable_bus_info *bus_info = xarg;
 	const struct mptable_ioapic *ioapic;
@@ -1016,7 +1022,7 @@ mptable_pci_int_callback(void *xarg, const void *pos, int type)
 	const struct INTENTRY *ent;
 	int pci_pin, pci_dev;
 
-	if (type != 3)
+	if (type != BTE_IOINT)
 		return 0;
 	ent = pos;
 
@@ -1172,14 +1178,14 @@ struct mptable_ioapic_probe_cbarg {
 };
 
 static int
-mptable_ioapic_probe_callback(void *xarg, const void *pos, int type)
+mptable_ioapic_probe_callback(void *xarg, const void *pos, enum entry_type type)
 {
 	struct mptable_ioapic_probe_cbarg *arg = xarg;
 	const struct mptable_ioapic *ioapic;
 	const struct mptable_bus *bus;
 	const struct INTENTRY *ent;
 
-	if (type != 3)
+	if (type != BTE_IOINT)
 		return 0;
 	ent = pos;
 
@@ -1258,7 +1264,7 @@ struct mptable_ioapic_int_cbarg {
 };
 
 static int
-mptable_ioapic_int_callback(void *xarg, const void *pos, int type)
+mptable_ioapic_int_callback(void *xarg, const void *pos, enum entry_type type)
 {
 	struct mptable_ioapic_int_cbarg *arg = xarg;
 	const struct mptable_ioapic *ioapic;
@@ -1266,7 +1272,7 @@ mptable_ioapic_int_callback(void *xarg, const void *pos, int type)
 	const struct INTENTRY *ent;
 	int gsi;
 
-	if (type != 3)
+	if (type != BTE_IOINT)
 		return 0;
 
 	arg->ioapic_nint++;
-- 
2.28.0

