dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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