dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/0026-Enable-probe_roms-to-scan-more-than-6-roms.patch

f5dd7b
From 4ec389e3f0c1233f5aa2d5b4e63d96e33d2a37f0 Mon Sep 17 00:00:00 2001
f5dd7b
From: Roman Sobanski <roman.sobanski@intel.com>
f5dd7b
Date: Tue, 2 Jul 2019 13:29:27 +0200
f5dd7b
Subject: [RHEL7.8 PATCH V2 26/47] Enable probe_roms to scan more than 6 roms.
f5dd7b
f5dd7b
In some cases if more than 6 oroms exist, resource for particular
f5dd7b
controller may not be found. Change method for storing
f5dd7b
adapter_rom_resources from array to list.
f5dd7b
f5dd7b
Signed-off-by: Roman Sobanski <roman.sobanski@intel.com>
f5dd7b
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
f5dd7b
---
f5dd7b
 probe_roms.c | 98 ++++++++++++++++++++++++++++++++++--------------------------
f5dd7b
 1 file changed, 56 insertions(+), 42 deletions(-)
f5dd7b
f5dd7b
diff --git a/probe_roms.c b/probe_roms.c
f5dd7b
index b0b0883..7ea04c7 100644
f5dd7b
--- a/probe_roms.c
f5dd7b
+++ b/probe_roms.c
f5dd7b
@@ -35,6 +35,9 @@ static const int rom_len = 0xf0000 - 0xc0000; /* option-rom memory region */
f5dd7b
 static int _sigbus;
f5dd7b
 static unsigned long rom_align;
f5dd7b
 
f5dd7b
+static void roms_deinit(void);
f5dd7b
+static int roms_init(void);
f5dd7b
+
f5dd7b
 static void sigbus(int sig)
f5dd7b
 {
f5dd7b
 	_sigbus = 1;
f5dd7b
@@ -75,6 +78,7 @@ void probe_roms_exit(void)
f5dd7b
 		munmap(rom_mem, rom_len);
f5dd7b
 		rom_mem = MAP_FAILED;
f5dd7b
 	}
f5dd7b
+	roms_deinit();
f5dd7b
 }
f5dd7b
 
f5dd7b
 int probe_roms_init(unsigned long align)
f5dd7b
@@ -91,6 +95,9 @@ int probe_roms_init(unsigned long align)
f5dd7b
 	else
f5dd7b
 		return -1;
f5dd7b
 
f5dd7b
+	if (roms_init())
f5dd7b
+		return -1;
f5dd7b
+
f5dd7b
 	if (signal(SIGBUS, sigbus) == SIG_ERR)
f5dd7b
 		rc = -1;
f5dd7b
 	if (rc == 0) {
f5dd7b
@@ -131,6 +138,7 @@ struct resource {
f5dd7b
 	unsigned long end;
f5dd7b
 	unsigned long data;
f5dd7b
 	const char *name;
f5dd7b
+	struct resource *next;
f5dd7b
 };
f5dd7b
 
f5dd7b
 static struct resource system_rom_resource = {
f5dd7b
@@ -147,37 +155,7 @@ static struct resource extension_rom_resource = {
f5dd7b
 	.end	= 0xeffff,
f5dd7b
 };
f5dd7b
 
f5dd7b
-static struct resource adapter_rom_resources[] = { {
f5dd7b
-	.name	= "Adapter ROM",
f5dd7b
-	.start	= 0xc8000,
f5dd7b
-	.data   = 0,
f5dd7b
-	.end	= 0,
f5dd7b
-}, {
f5dd7b
-	.name	= "Adapter ROM",
f5dd7b
-	.start	= 0,
f5dd7b
-	.data   = 0,
f5dd7b
-	.end	= 0,
f5dd7b
-}, {
f5dd7b
-	.name	= "Adapter ROM",
f5dd7b
-	.start	= 0,
f5dd7b
-	.data   = 0,
f5dd7b
-	.end	= 0,
f5dd7b
-}, {
f5dd7b
-	.name	= "Adapter ROM",
f5dd7b
-	.start	= 0,
f5dd7b
-	.data   = 0,
f5dd7b
-	.end	= 0,
f5dd7b
-}, {
f5dd7b
-	.name	= "Adapter ROM",
f5dd7b
-	.start	= 0,
f5dd7b
-	.data   = 0,
f5dd7b
-	.end	= 0,
f5dd7b
-}, {
f5dd7b
-	.name	= "Adapter ROM",
f5dd7b
-	.start	= 0,
f5dd7b
-	.data   = 0,
f5dd7b
-	.end	= 0,
f5dd7b
-} };
f5dd7b
+static struct resource *adapter_rom_resources;
f5dd7b
 
f5dd7b
 static struct resource video_rom_resource = {
f5dd7b
 	.name	= "Video ROM",
f5dd7b
@@ -186,8 +164,35 @@ static struct resource video_rom_resource = {
f5dd7b
 	.end	= 0xc7fff,
f5dd7b
 };
f5dd7b
 
f5dd7b
+static int roms_init(void)
f5dd7b
+{
f5dd7b
+	adapter_rom_resources = malloc(sizeof(struct resource));
f5dd7b
+	if (adapter_rom_resources == NULL)
f5dd7b
+		return 1;
f5dd7b
+	adapter_rom_resources->name = "Adapter ROM";
f5dd7b
+	adapter_rom_resources->start = 0xc8000;
f5dd7b
+	adapter_rom_resources->data = 0;
f5dd7b
+	adapter_rom_resources->end = 0;
f5dd7b
+	adapter_rom_resources->next = NULL;
f5dd7b
+	return 0;
f5dd7b
+}
f5dd7b
+
f5dd7b
+static void roms_deinit(void)
f5dd7b
+{
f5dd7b
+	struct resource *res;
f5dd7b
+
f5dd7b
+	res = adapter_rom_resources;
f5dd7b
+	while (res) {
f5dd7b
+		struct resource *tmp = res;
f5dd7b
+
f5dd7b
+		res = res->next;
f5dd7b
+		free(tmp);
f5dd7b
+	}
f5dd7b
+}
f5dd7b
+
f5dd7b
 #define ROMSIGNATURE 0xaa55
f5dd7b
 
f5dd7b
+
f5dd7b
 static int romsignature(const unsigned char *rom)
f5dd7b
 {
f5dd7b
 	const unsigned short * const ptr = (const unsigned short *)rom;
f5dd7b
@@ -208,16 +213,14 @@ static int romchecksum(const unsigned char *rom, unsigned long length)
f5dd7b
 int scan_adapter_roms(scan_fn fn)
f5dd7b
 {
f5dd7b
 	/* let scan_fn examing each of the adapter roms found by probe_roms */
f5dd7b
-	unsigned int i;
f5dd7b
+	struct resource *res = adapter_rom_resources;
f5dd7b
 	int found;
f5dd7b
 
f5dd7b
 	if (rom_fd < 0)
f5dd7b
 		return 0;
f5dd7b
 
f5dd7b
 	found = 0;
f5dd7b
-	for (i = 0; i < ARRAY_SIZE(adapter_rom_resources); i++) {
f5dd7b
-		struct resource *res = &adapter_rom_resources[i];
f5dd7b
-
f5dd7b
+	while (res) {
f5dd7b
 		if (res->start) {
f5dd7b
 			found = fn(isa_bus_to_virt(res->start),
f5dd7b
 				   isa_bus_to_virt(res->end),
f5dd7b
@@ -226,6 +229,7 @@ int scan_adapter_roms(scan_fn fn)
f5dd7b
 				break;
f5dd7b
 		} else
f5dd7b
 			break;
f5dd7b
+		res = res->next;
f5dd7b
 	}
f5dd7b
 
f5dd7b
 	return found;
f5dd7b
@@ -241,14 +245,14 @@ void probe_roms(void)
f5dd7b
 	const void *rom;
f5dd7b
 	unsigned long start, length, upper;
f5dd7b
 	unsigned char c;
f5dd7b
-	unsigned int i;
f5dd7b
+	struct resource *res = adapter_rom_resources;
f5dd7b
 	__u16 val=0;
f5dd7b
 
f5dd7b
 	if (rom_fd < 0)
f5dd7b
 		return;
f5dd7b
 
f5dd7b
 	/* video rom */
f5dd7b
-	upper = adapter_rom_resources[0].start;
f5dd7b
+	upper = res->start;
f5dd7b
 	for (start = video_rom_resource.start; start < upper; start += rom_align) {
f5dd7b
 		rom = isa_bus_to_virt(start);
f5dd7b
 		if (!romsignature(rom))
f5dd7b
@@ -283,8 +287,9 @@ void probe_roms(void)
f5dd7b
 			upper = extension_rom_resource.start;
f5dd7b
 	}
f5dd7b
 
f5dd7b
+	struct resource *prev_res = res;
f5dd7b
 	/* check for adapter roms on 2k boundaries */
f5dd7b
-	for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += rom_align) {
f5dd7b
+	for (; start < upper; start += rom_align) {
f5dd7b
 		rom = isa_bus_to_virt(start);
f5dd7b
 		if (!romsignature(rom))
f5dd7b
 			continue;
f5dd7b
@@ -308,10 +313,19 @@ void probe_roms(void)
f5dd7b
 		if (!length || start + length > upper || !romchecksum(rom, length))
f5dd7b
 			continue;
f5dd7b
 
f5dd7b
-		adapter_rom_resources[i].start = start;
f5dd7b
-		adapter_rom_resources[i].data = start + (unsigned long) val;
f5dd7b
-		adapter_rom_resources[i].end = start + length - 1;
f5dd7b
+		if (res == NULL) {
f5dd7b
+			res = calloc(1, sizeof(struct resource));
f5dd7b
+			if (res == NULL)
f5dd7b
+				return;
f5dd7b
+			prev_res->next = res;
f5dd7b
+		}
f5dd7b
+
f5dd7b
+		res->start = start;
f5dd7b
+		res->data = start + (unsigned long)val;
f5dd7b
+		res->end = start + length - 1;
f5dd7b
 
f5dd7b
-		start = adapter_rom_resources[i++].end & ~(rom_align - 1);
f5dd7b
+		start = res->end & ~(rom_align - 1);
f5dd7b
+		prev_res = res;
f5dd7b
+		res = res->next;
f5dd7b
 	}
f5dd7b
 }
f5dd7b
-- 
f5dd7b
2.7.5
f5dd7b