kexec-tools: Read out /proc/iomem and store in range data type
This patch contains code to read out /proc/iomem and store it in a range
data type. It builds on top of the already existing iomem code.
The code should be able to parse /proc/iomem for multiple architectures.
Signed-off-by: Magnus Damm <[EMAIL PROTECTED]>
---
kexec/kexec-iomem.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++--
kexec/kexec.h | 8 +++++++
--- 0001/kexec/kexec-iomem.c
+++ work/kexec/kexec-iomem.c 2006-12-22 16:47:17.000000000 +0900
@@ -36,6 +36,7 @@ int kexec_iomem_for_each_line(char *matc
int consumed;
int count;
int nr = 0;
+ int res = 0;
fp = fopen(iomem, "r");
if (!fp)
@@ -48,8 +49,8 @@ int kexec_iomem_for_each_line(char *matc
str = line + consumed;
size = end - start + 1;
if (!match || memcmp(str, match, strlen(match)) == 0) {
- if (callback
- && callback(data, nr, str, start, size) < 0) {
+ if (callback &&
+ (res = callback(data, nr, str, start, size)) < 0) {
break;
}
nr++;
@@ -58,6 +59,9 @@ int kexec_iomem_for_each_line(char *matc
fclose(fp);
+ if (res < 0)
+ return res;
+
return nr;
}
@@ -99,3 +103,52 @@ int parse_iomem_single(char *str, uint64
return ret;
}
+
+
+static int kexec_iomem_range_callback(void *data, int nr,
+ char *str,
+ unsigned long base,
+ unsigned long length)
+{
+ int type;
+
+ do {
+ if (memcmp(str, "System RAM\n", 11) == 0) {
+ type = RANGE_IOMEM_RAM;
+ break;
+ }
+
+ if (memcmp(str, "Crash kernel\n", 13) == 0) {
+ type = RANGE_IOMEM_CRASH;
+ break;
+ }
+
+ if (memcmp(str, "ACPI Tables\n", 12) == 0) {
+ type = RANGE_IOMEM_ACPI;
+ break;
+ }
+
+ if(memcmp(str,"ACPI Non-volatile Storage\n", 26) == 0) {
+ type = RANGE_IOMEM_ACPI_NVS;
+ break;
+ }
+
+ /* do nothing if no match */
+
+ return 0;
+
+ } while(0);
+
+ return range_set((struct range *)data, base, length, type);
+}
+
+int get_iomem_range(struct range *range)
+{
+ if (kexec_iomem_for_each_line(NULL,
+ kexec_iomem_range_callback,
+ range) <= 0)
+ return -1;
+
+ return 0;
+}
+
--- 0001/kexec/kexec.h
+++ work/kexec/kexec.h 2006-12-22 16:45:28.000000000 +0900
@@ -9,6 +9,7 @@
#define _GNU_SOURCE
#include "kexec-elf.h"
+#include "range.h"
#ifndef BYTE_ORDER
#error BYTE_ORDER not defined
@@ -210,6 +211,13 @@ int kexec_iomem_for_each_line(char *matc
void *data);
int parse_iomem_single(char *str, uint64_t *start, uint64_t *end);
+int get_iomem_range(struct range *range);
+
+#define RANGE_IOMEM_NOTHING RANGE_NOTHING /* must be 0 */
+#define RANGE_IOMEM_RAM 1
+#define RANGE_IOMEM_CRASH 2
+#define RANGE_IOMEM_ACPI 3
+#define RANGE_IOMEM_ACPI_NVS 4
#define MAX_LINE 160
_______________________________________________
fastboot mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/fastboot