WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-ia64-devel

[Xen-ia64-devel] [patch 2/3] Allow architectures to specify the location

To: xen-ia64-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-ia64-devel] [patch 2/3] Allow architectures to specify the location of /proc/iomem
From: Simon Horman <horms@xxxxxxxxxxxx>
Date: Wed, 12 Sep 2007 18:17:42 +0900
Delivery-date: Wed, 12 Sep 2007 02:26:20 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-ia64-devel-request@lists.xensource.com?subject=help>
List-id: Discussion of the ia64 port of Xen <xen-ia64-devel.lists.xensource.com>
List-post: <mailto:xen-ia64-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-ia64-devel>, <mailto:xen-ia64-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-ia64-devel>, <mailto:xen-ia64-devel-request@lists.xensource.com?subject=unsubscribe>
References: <20070912091740.411152109@xxxxxxxxxxxx>
Sender: xen-ia64-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: quilt/0.46-1
On ia64 XEN it is sometimes neccessary to use an alternate location for the
information that is usually provided by /proc/iomem.  By having the path
returned by a function, which can be overriden on a per-architecture basis,
it is possible for ia64 XEN to make use of existing generic code. Hopefully
other achitectures can use this infastructure as the need arises.

If the machine parameter is zero, then iomem file relating to the currently
running kernel should be returned. If the machine parameter is non-zero
then iomem file, relating to the underlying hypervisor, should be returned.
In the simple case, these will be the same file.

Signed-off-by: Simon Horman <horms@xxxxxxxxxxxx>

Index: kexec-tools-testing-20070330/kexec/arch/i386/crashdump-x86.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/i386/crashdump-x86.c   
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/i386/crashdump-x86.c        
2007-08-28 12:12:35.000000000 +0900
@@ -59,7 +59,7 @@ static struct memory_range crash_reserve
  */
 static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 {
-       const char iomem[]= "/proc/iomem";
+       const char *iomem = proc_iomem(1);
        int memory_ranges = 0;
        char line[MAX_LINE];
        FILE *fp;
@@ -557,6 +557,6 @@ int is_crashkernel_mem_reserved(void)
 {
        uint64_t start, end;
 
-       return parse_iomem_single("Crash kernel\n", &start, &end) == 0 ?
+       return parse_iomem_single("Crash kernel\n", 1, &start, &end) == 0 ?
          (start != end) : 0;
 }
Index: kexec-tools-testing-20070330/kexec/arch/i386/kexec-x86.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/i386/kexec-x86.c       
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/i386/kexec-x86.c    2007-08-28 
12:12:35.000000000 +0900
@@ -39,7 +39,7 @@ static struct memory_range memory_range[
 int get_memory_ranges(struct memory_range **range, int *ranges,
                                unsigned long kexec_flags)
 {
-       const char iomem[]= "/proc/iomem";
+       const char *iomem= proc_iomem(kexec_flags & KEXEC_ON_CRASH);
        int memory_ranges = 0;
        char line[MAX_LINE];
        FILE *fp;
Index: kexec-tools-testing-20070330/kexec/arch/i386/x86-linux-setup.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/i386/x86-linux-setup.c 
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/i386/x86-linux-setup.c      
2007-08-28 12:11:19.000000000 +0900
@@ -126,7 +126,7 @@ int setup_linux_vesafb(struct x86_linux_
        real_mode->lfb_linelength = fix.line_length;
        real_mode->vesapm_seg     = 0;
 
-       /* FIXME: better get size from /proc/iomem */
+       /* FIXME: better get size from the file returned by proc_iomem() */
        real_mode->lfb_size       = (fix.smem_len + 65535) / 65536;
        real_mode->pages          = (fix.smem_len + 4095) / 4096;
 
Index: kexec-tools-testing-20070330/kexec/arch/ia64/crashdump-ia64.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/ia64/crashdump-ia64.c  
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/ia64/crashdump-ia64.c       
2007-08-28 12:12:35.000000000 +0900
@@ -43,7 +43,8 @@ static struct crash_elf_info elf_info =
 /* Stores a sorted list of RAM memory ranges for which to create elf headers.
  * A separate program header is created for backup region.
  * The number of entries in memory_range array is always smaller than
- * the number of entries in /proc/iomem, stored in max_memory_ranges. */
+ * the number of entries in the file returned by proc_iomem(),
+ * stored in max_memory_ranges. */
 static struct memory_range *crash_memory_range;
 /* Memory region reserved for storing panic kernel and other data. */
 static struct memory_range crash_reserved_mem;
@@ -142,7 +143,7 @@ static int exclude_crash_reserve_region(
 
 static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 {
-       const char iomem[]= "/proc/iomem";
+       const char *iomem = proc_iomem(1);
         char line[MAX_LINE];
         FILE *fp;
         unsigned long start, end;
@@ -261,6 +262,6 @@ int is_crashkernel_mem_reserved(void)
 {
        uint64_t start, end;
 
-       return parse_iomem_single("Crash kernel\n", &start, &end) == 0 ?
-         (start != end) : 0;
+       return parse_iomem_single("Crash kernel\n", 1, &start,
+                                 &end) == 0 ?  (start != end) : 0;
 }
Index: kexec-tools-testing-20070330/kexec/arch/ia64/kexec-elf-ia64.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/ia64/kexec-elf-ia64.c  
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/ia64/kexec-elf-ia64.c       
2007-08-28 12:12:35.000000000 +0900
@@ -195,7 +195,7 @@ int elf_ia64_load(int argc, char **argv,
        if (info->kexec_flags & KEXEC_ON_CRASH ) {
                if ((mem_min == 0x00) && (mem_max == ULONG_MAX)) {
                        fprintf(stderr, "Failed to find crash kernel region "
-                               "in /proc/iomem\n");
+                               "in %s\n", proc_iomem(1));
                        free_elf_info(&ehdr);
                        return -1;
                }
Index: kexec-tools-testing-20070330/kexec/arch/ia64/kexec-ia64.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/ia64/kexec-ia64.c      
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/ia64/kexec-ia64.c   2007-08-28 
12:12:35.000000000 +0900
@@ -37,7 +37,8 @@
 #include <arch/options.h>
 
 /* The number of entries in memory_range array is always smaller than
-   the number of entries in /proc/iomem, stored in max_memory_ranges. */
+ * the number of entries in the file returned by proc_iomem(),
+ * stored in max_memory_ranges. */
 static struct memory_range *memory_range;
 int max_memory_ranges;
 static int memory_ranges;
@@ -79,7 +80,7 @@ static int split_range(int range, unsign
 int get_memory_ranges(struct memory_range **range, int *ranges,
                                unsigned long kexec_flags)
 {
-       const char iomem[]= "/proc/iomem";
+       const char *iomem = proc_iomem(kexec_flags & KEXEC_ON_CRASH);
        char line[MAX_LINE];
        FILE *fp;
        fp = fopen(iomem, "r");
Index: kexec-tools-testing-20070330/kexec/arch/ppc/kexec-ppc.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/ppc/kexec-ppc.c        
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/ppc/kexec-ppc.c     2007-08-28 
12:11:19.000000000 +0900
@@ -34,7 +34,7 @@ int get_memory_ranges(struct memory_rang
        memory_ranges++;
 #else
 #error Please, fix this for your platform
-       const char iomem[] = "/proc/iomem";
+       const char *iomem = proc_iomem();
        char line[MAX_LINE];
        FILE *fp;
        unsigned long long start, end;
Index: kexec-tools-testing-20070330/kexec/arch/s390/kexec-s390.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/s390/kexec-s390.c      
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/s390/kexec-s390.c   2007-08-28 
12:12:35.000000000 +0900
@@ -25,7 +25,8 @@ static struct memory_range memory_range[
 
 /*
  * get_memory_ranges:
- *  Return a list of memory ranges by parsing /proc/iomem
+ *  Return a list of memory ranges by parsing the file returned by
+ *  proc_iomem()
  *
  * INPUT:
  *  - Pointer to an array of memory_range structures.
@@ -39,7 +40,7 @@ static struct memory_range memory_range[
 int get_memory_ranges(struct memory_range **range, int *ranges, unsigned long 
flags)
 {
        char sys_ram[] = "System RAM\n";
-       char iomem[] = "/proc/iomem";
+       char *iomem = proc_iomem(flags & KEXEC_ON_CRASH);
        FILE *fp;
        char line[80];
        int current_range = 0;
Index: kexec-tools-testing-20070330/kexec/arch/x86_64/crashdump-x86_64.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/x86_64/crashdump-x86_64.c      
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/x86_64/crashdump-x86_64.c   
2007-08-28 12:12:35.000000000 +0900
@@ -52,8 +52,8 @@ static int exclude_crash_reserve_region(
 
 #define KERN_VADDR_ALIGN       0x100000        /* 1MB */
 
-/* Read kernel physical load addr from /proc/iomem (Kernel Code) and
- * store in kexec_info */
+/* Read kernel physical load addr from the file returned by proc_iomem()
+ * (Kernel Code) and store in kexec_info */
 static int get_kernel_paddr(struct kexec_info *info)
 {
        uint64_t start;
@@ -61,7 +61,7 @@ static int get_kernel_paddr(struct kexec
        if (xen_present()) /* Kernel not entity mapped under Xen */
                return 0;
 
-       if (parse_iomem_single("Kernel code\n", &start, NULL) == 0) {
+       if (parse_iomem_single("Kernel code\n", 0, &start, NULL) == 0) {
                info->kern_paddr_start = start;
 #ifdef DEBUG
                printf("kernel load physical addr start = 0x%016Lx\n", start);
@@ -164,7 +164,7 @@ static struct memory_range crash_reserve
  */
 static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 {
-       const char iomem[]= "/proc/iomem";
+       const char *iomem= proc_iomem(1);
        int memory_ranges = 0;
        char line[MAX_LINE];
        FILE *fp;
@@ -642,6 +642,6 @@ int is_crashkernel_mem_reserved(void)
 {
        uint64_t start, end;
 
-       return parse_iomem_single("Crash kernel\n", &start, &end) == 0 ?
+       return parse_iomem_single("Crash kernel\n", 1, &start, &end) == 0 ?
          (start != end) : 0;
 }
Index: kexec-tools-testing-20070330/kexec/arch/x86_64/kexec-x86_64.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/arch/x86_64/kexec-x86_64.c  
2007-08-28 12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/arch/x86_64/kexec-x86_64.c       
2007-08-28 12:12:35.000000000 +0900
@@ -40,7 +40,7 @@ static struct memory_range memory_range[
 int get_memory_ranges(struct memory_range **range, int *ranges,
                                        unsigned long kexec_flags)
 {
-       const char iomem[]= "/proc/iomem";
+       const char *iomem= proc_iomem(kexec_flags & KEXEC_ON_CRASH);
        int memory_ranges = 0;
        char line[MAX_LINE];
        FILE *fp;
Index: kexec-tools-testing-20070330/kexec/kexec-iomem.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/kexec-iomem.c       2007-08-28 
12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/kexec-iomem.c    2007-08-28 
12:12:35.000000000 +0900
@@ -15,12 +15,14 @@
 /*
  * kexec_iomem_for_each_line()
  *
- * Iterate over each line in /proc/iomem. If match is NULL or if the line
- * matches with our match-pattern then call the callback if non-NULL.
+ * Iterate over each line in the file returned by proc_iomem(). If match is
+ * NULL or if the line matches with our match-pattern then call the
+ * callback if non-NULL.
+ *
  * Return the number of lines matched.
  */
 
-int kexec_iomem_for_each_line(char *match,
+int kexec_iomem_for_each_line(char *match, int machine,
                              int (*callback)(void *data,
                                              int nr,
                                              char *str,
@@ -28,7 +30,7 @@ int kexec_iomem_for_each_line(char *matc
                                              unsigned long length),
                              void *data)
 {
-       const char iomem[]= "/proc/iomem";
+       const char *iomem = proc_iomem(machine);
        char line[MAX_LINE];
        FILE *fp;
        unsigned long long start, end, size;
@@ -39,7 +41,7 @@ int kexec_iomem_for_each_line(char *matc
 
        fp = fopen(iomem, "r");
        if (!fp)
-               die("Cannot open /proc/iomem");
+               die("Cannot open %s\n", iomem);
 
        while(fgets(line, sizeof(line), fp) != 0) {
                count = sscanf(line, "%Lx-%Lx : %n", &start, &end, &consumed);
@@ -76,15 +78,15 @@ static int kexec_iomem_single_callback(v
        return 0;
 }
 
-int parse_iomem_single(char *str, uint64_t *start, uint64_t *end)
+int parse_iomem_single(char *str, int machine, uint64_t *start, uint64_t *end)
 {
        struct memory_range range;
        int ret;
 
        memset(&range, 0, sizeof(range));
 
-       ret = kexec_iomem_for_each_line(str, kexec_iomem_single_callback,
-                                       &range);
+       ret = kexec_iomem_for_each_line(str, machine,
+                                       kexec_iomem_single_callback, &range);
 
        if (ret == 1) {
                if (start)
@@ -99,3 +101,16 @@ int parse_iomem_single(char *str, uint64
 
        return ret;
 }
+
+static const char proc_iomem_str[]= "/proc/iomem";
+
+/*
+ * Allow an architecture specific implementation of this
+ * function to override the location of a file looking a lot
+ * like /proc/iomem
+ */
+const char * __attribute__((weak)) proc_iomem(int machine)
+{
+        return proc_iomem_str;
+}
+
Index: kexec-tools-testing-20070330/kexec/kexec.h
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/kexec.h     2007-08-28 
12:10:55.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/kexec.h  2007-08-28 12:12:35.000000000 
+0900
@@ -203,15 +203,15 @@ int arch_compat_trampoline(struct kexec_
 void arch_update_purgatory(struct kexec_info *info);
 int is_crashkernel_mem_reserved(void);
 
-int kexec_iomem_for_each_line(char *match,
+int kexec_iomem_for_each_line(char *match, int machine,
                              int (*callback)(void *data,
                                              int nr,
                                              char *str,
                                              unsigned long base,
                                              unsigned long length),
                              void *data);
-int parse_iomem_single(char *str, uint64_t *start, uint64_t *end);
-
+int parse_iomem_single(char *str, int machine, uint64_t *start, uint64_t *end);
+const char * proc_iomem(int machine);
 
 #define MAX_LINE       160
 
Index: kexec-tools-testing-20070330/kexec/crashdump-xen.c
===================================================================
--- kexec-tools-testing-20070330.orig/kexec/crashdump-xen.c     2007-08-28 
12:10:46.000000000 +0900
+++ kexec-tools-testing-20070330/kexec/crashdump-xen.c  2007-08-28 
12:12:35.000000000 +0900
@@ -12,6 +12,7 @@
 #include <fcntl.h>
 #include "kexec.h"
 #include "crashdump.h"
+#include "kexec-syscall.h"
 
 #ifdef HAVE_XENCTRL_H
 #include <xenctrl.h>
@@ -90,12 +91,12 @@ int xen_get_nr_phys_cpus(void)
        if (xen_phys_cpus)
                return xen_phys_cpus;
 
-       if ((cpus = kexec_iomem_for_each_line(match, NULL, NULL))) {
+       if ((cpus = kexec_iomem_for_each_line(match, 1, NULL, NULL))) {
                n = sizeof(struct crash_note_info) * cpus;
                xen_phys_notes = malloc(n);
                if (xen_phys_notes) {
                        memset(xen_phys_notes, 0, n);
-                       kexec_iomem_for_each_line(match,
+                       kexec_iomem_for_each_line(match, 1,
                                                  xen_crash_note_callback,
                                                  NULL);
                }

-- 

-- 
Horms
  H: http://www.vergenet.net/~horms/
  W: http://www.valinux.co.jp/en/


_______________________________________________
Xen-ia64-devel mailing list
Xen-ia64-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ia64-devel