/kexec/arch/s390/kexec-s390.c

https://gitlab.com/adam.lukaitis/kexec-tools · C · 116 lines · 76 code · 17 blank · 23 comment · 9 complexity · d41bc700b301666158b8689914da90b9 MD5 · raw file

  1. /*
  2. * kexec/arch/s390/kexec-s390.c
  3. *
  4. * (C) Copyright IBM Corp. 2005
  5. *
  6. * Author(s): Rolf Adelsberger <adelsberger@de.ibm.com>
  7. *
  8. */
  9. #define _GNU_SOURCE
  10. #include <stddef.h>
  11. #include <stdio.h>
  12. #include <errno.h>
  13. #include <stdint.h>
  14. #include <string.h>
  15. #include <getopt.h>
  16. #include "../../kexec.h"
  17. #include "../../kexec-syscall.h"
  18. #include "kexec-s390.h"
  19. #include <arch/options.h>
  20. #define MAX_MEMORY_RANGES 64
  21. static struct memory_range memory_range[MAX_MEMORY_RANGES];
  22. /*
  23. * get_memory_ranges:
  24. * Return a list of memory ranges by parsing the file returned by
  25. * proc_iomem()
  26. *
  27. * INPUT:
  28. * - Pointer to an array of memory_range structures.
  29. * - Pointer to an integer with holds the number of memory ranges.
  30. *
  31. * RETURN:
  32. * - 0 on normal execution.
  33. * - (-1) if something went wrong.
  34. */
  35. int get_memory_ranges(struct memory_range **range, int *ranges,
  36. unsigned long UNUSED(flags))
  37. {
  38. char sys_ram[] = "System RAM\n";
  39. const char *iomem = proc_iomem();
  40. FILE *fp;
  41. char line[80];
  42. int current_range = 0;
  43. fp = fopen(iomem,"r");
  44. if(fp == 0) {
  45. fprintf(stderr,"Unable to open %s: %s\n",iomem,strerror(errno));
  46. return -1;
  47. }
  48. /* Setup the compare string properly. */
  49. while(fgets(line,sizeof(line),fp) != 0) {
  50. unsigned long long start, end;
  51. int cons;
  52. char *str;
  53. if (current_range == MAX_MEMORY_RANGES)
  54. break;
  55. sscanf(line,"%Lx-%Lx : %n", &start, &end, &cons);
  56. str = line+cons;
  57. if(memcmp(str,sys_ram,strlen(sys_ram)) == 0) {
  58. memory_range[current_range].start = start;
  59. memory_range[current_range].end = end;
  60. memory_range[current_range].type = RANGE_RAM;
  61. current_range++;
  62. }
  63. else {
  64. continue;
  65. }
  66. }
  67. fclose(fp);
  68. *range = memory_range;
  69. *ranges = current_range;
  70. return 0;
  71. }
  72. /* Supported file types and callbacks */
  73. struct file_type file_type[] = {
  74. { "image", image_s390_probe, image_s390_load, image_s390_usage},
  75. };
  76. int file_types = sizeof(file_type) / sizeof(file_type[0]);
  77. void arch_usage(void)
  78. {
  79. }
  80. int arch_process_options(int UNUSED(argc), char **UNUSED(argv))
  81. {
  82. return 0;
  83. }
  84. const struct arch_map_entry arches[] = {
  85. { "s390", KEXEC_ARCH_S390 },
  86. { "s390x", KEXEC_ARCH_S390 },
  87. { NULL, 0 },
  88. };
  89. int arch_compat_trampoline(struct kexec_info *UNUSED(info))
  90. {
  91. return 0;
  92. }
  93. void arch_update_purgatory(struct kexec_info *UNUSED(info))
  94. {
  95. }
  96. int is_crashkernel_mem_reserved(void)
  97. {
  98. return 0; /* kdump is not supported on this platform (yet) */
  99. }