dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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