atags_compat.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/kernel/atags_compat.c
  4. *
  5. * Copyright (C) 2001 Russell King
  6. *
  7. * We keep the old params compatibility cruft in one place (here)
  8. * so we don't end up with lots of mess around other places.
  9. *
  10. * NOTE:
  11. * The old struct param_struct is deprecated, but it will be kept in
  12. * the kernel for 5 years from now (2001). This will allow boot loaders
  13. * to convert to the new struct tag way.
  14. */
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/string.h>
  18. #include <linux/init.h>
  19. #include <asm/setup.h>
  20. #include <asm/mach-types.h>
  21. #include <asm/page.h>
  22. #include <asm/mach/arch.h>
  23. #include "atags.h"
  24. /*
  25. * Usage:
  26. * - do not go blindly adding fields, add them at the end
  27. * - when adding fields, don't rely on the address until
  28. * a patch from me has been released
  29. * - unused fields should be zero (for future expansion)
  30. * - this structure is relatively short-lived - only
  31. * guaranteed to contain useful data in setup_arch()
  32. *
  33. * This is the old deprecated way to pass parameters to the kernel
  34. */
  35. struct param_struct {
  36. union {
  37. struct {
  38. unsigned long page_size; /* 0 */
  39. unsigned long nr_pages; /* 4 */
  40. unsigned long ramdisk_size; /* 8 */
  41. unsigned long flags; /* 12 */
  42. #define FLAG_READONLY 1
  43. #define FLAG_RDLOAD 4
  44. #define FLAG_RDPROMPT 8
  45. unsigned long rootdev; /* 16 */
  46. unsigned long video_num_cols; /* 20 */
  47. unsigned long video_num_rows; /* 24 */
  48. unsigned long video_x; /* 28 */
  49. unsigned long video_y; /* 32 */
  50. unsigned long memc_control_reg; /* 36 */
  51. unsigned char sounddefault; /* 40 */
  52. unsigned char adfsdrives; /* 41 */
  53. unsigned char bytes_per_char_h; /* 42 */
  54. unsigned char bytes_per_char_v; /* 43 */
  55. unsigned long pages_in_bank[4]; /* 44 */
  56. unsigned long pages_in_vram; /* 60 */
  57. unsigned long initrd_start; /* 64 */
  58. unsigned long initrd_size; /* 68 */
  59. unsigned long rd_start; /* 72 */
  60. unsigned long system_rev; /* 76 */
  61. unsigned long system_serial_low; /* 80 */
  62. unsigned long system_serial_high; /* 84 */
  63. unsigned long mem_fclk_21285; /* 88 */
  64. } s;
  65. char unused[256];
  66. } u1;
  67. union {
  68. char paths[8][128];
  69. struct {
  70. unsigned long magic;
  71. char n[1024 - sizeof(unsigned long)];
  72. } s;
  73. } u2;
  74. char commandline[COMMAND_LINE_SIZE];
  75. };
  76. static struct tag * __init memtag(struct tag *tag, unsigned long start, unsigned long size)
  77. {
  78. tag = tag_next(tag);
  79. tag->hdr.tag = ATAG_MEM;
  80. tag->hdr.size = tag_size(tag_mem32);
  81. tag->u.mem.size = size;
  82. tag->u.mem.start = start;
  83. return tag;
  84. }
  85. static void __init build_tag_list(struct param_struct *params, void *taglist)
  86. {
  87. struct tag *tag = taglist;
  88. if (params->u1.s.page_size != PAGE_SIZE) {
  89. pr_warn("Warning: bad configuration page, trying to continue\n");
  90. return;
  91. }
  92. printk(KERN_DEBUG "Converting old-style param struct to taglist\n");
  93. #ifdef CONFIG_ARCH_NETWINDER
  94. if (params->u1.s.nr_pages != 0x02000 &&
  95. params->u1.s.nr_pages != 0x04000 &&
  96. params->u1.s.nr_pages != 0x08000 &&
  97. params->u1.s.nr_pages != 0x10000) {
  98. pr_warn("Warning: bad NeTTrom parameters detected, using defaults\n");
  99. params->u1.s.nr_pages = 0x1000; /* 16MB */
  100. params->u1.s.ramdisk_size = 0;
  101. params->u1.s.flags = FLAG_READONLY;
  102. params->u1.s.initrd_start = 0;
  103. params->u1.s.initrd_size = 0;
  104. params->u1.s.rd_start = 0;
  105. }
  106. #endif
  107. tag->hdr.tag = ATAG_CORE;
  108. tag->hdr.size = tag_size(tag_core);
  109. tag->u.core.flags = params->u1.s.flags & FLAG_READONLY;
  110. tag->u.core.pagesize = params->u1.s.page_size;
  111. tag->u.core.rootdev = params->u1.s.rootdev;
  112. tag = tag_next(tag);
  113. tag->hdr.tag = ATAG_RAMDISK;
  114. tag->hdr.size = tag_size(tag_ramdisk);
  115. tag->u.ramdisk.flags = (params->u1.s.flags & FLAG_RDLOAD ? 1 : 0) |
  116. (params->u1.s.flags & FLAG_RDPROMPT ? 2 : 0);
  117. tag->u.ramdisk.size = params->u1.s.ramdisk_size;
  118. tag->u.ramdisk.start = params->u1.s.rd_start;
  119. tag = tag_next(tag);
  120. tag->hdr.tag = ATAG_INITRD;
  121. tag->hdr.size = tag_size(tag_initrd);
  122. tag->u.initrd.start = params->u1.s.initrd_start;
  123. tag->u.initrd.size = params->u1.s.initrd_size;
  124. tag = tag_next(tag);
  125. tag->hdr.tag = ATAG_SERIAL;
  126. tag->hdr.size = tag_size(tag_serialnr);
  127. tag->u.serialnr.low = params->u1.s.system_serial_low;
  128. tag->u.serialnr.high = params->u1.s.system_serial_high;
  129. tag = tag_next(tag);
  130. tag->hdr.tag = ATAG_REVISION;
  131. tag->hdr.size = tag_size(tag_revision);
  132. tag->u.revision.rev = params->u1.s.system_rev;
  133. #ifdef CONFIG_ARCH_ACORN
  134. if (machine_is_riscpc()) {
  135. int i;
  136. for (i = 0; i < 4; i++)
  137. tag = memtag(tag, PHYS_OFFSET + (i << 26),
  138. params->u1.s.pages_in_bank[i] * PAGE_SIZE);
  139. } else
  140. #endif
  141. tag = memtag(tag, PHYS_OFFSET, params->u1.s.nr_pages * PAGE_SIZE);
  142. #ifdef CONFIG_FOOTBRIDGE
  143. if (params->u1.s.mem_fclk_21285) {
  144. tag = tag_next(tag);
  145. tag->hdr.tag = ATAG_MEMCLK;
  146. tag->hdr.size = tag_size(tag_memclk);
  147. tag->u.memclk.fmemclk = params->u1.s.mem_fclk_21285;
  148. }
  149. #endif
  150. #ifdef CONFIG_ARCH_EBSA285
  151. if (machine_is_ebsa285()) {
  152. tag = tag_next(tag);
  153. tag->hdr.tag = ATAG_VIDEOTEXT;
  154. tag->hdr.size = tag_size(tag_videotext);
  155. tag->u.videotext.x = params->u1.s.video_x;
  156. tag->u.videotext.y = params->u1.s.video_y;
  157. tag->u.videotext.video_page = 0;
  158. tag->u.videotext.video_mode = 0;
  159. tag->u.videotext.video_cols = params->u1.s.video_num_cols;
  160. tag->u.videotext.video_ega_bx = 0;
  161. tag->u.videotext.video_lines = params->u1.s.video_num_rows;
  162. tag->u.videotext.video_isvga = 1;
  163. tag->u.videotext.video_points = 8;
  164. }
  165. #endif
  166. #ifdef CONFIG_ARCH_ACORN
  167. tag = tag_next(tag);
  168. tag->hdr.tag = ATAG_ACORN;
  169. tag->hdr.size = tag_size(tag_acorn);
  170. tag->u.acorn.memc_control_reg = params->u1.s.memc_control_reg;
  171. tag->u.acorn.vram_pages = params->u1.s.pages_in_vram;
  172. tag->u.acorn.sounddefault = params->u1.s.sounddefault;
  173. tag->u.acorn.adfsdrives = params->u1.s.adfsdrives;
  174. #endif
  175. tag = tag_next(tag);
  176. tag->hdr.tag = ATAG_CMDLINE;
  177. tag->hdr.size = (strlen(params->commandline) + 3 +
  178. sizeof(struct tag_header)) >> 2;
  179. strcpy(tag->u.cmdline.cmdline, params->commandline);
  180. tag = tag_next(tag);
  181. tag->hdr.tag = ATAG_NONE;
  182. tag->hdr.size = 0;
  183. memmove(params, taglist, ((int)tag) - ((int)taglist) +
  184. sizeof(struct tag_header));
  185. }
  186. void __init convert_to_tag_list(struct tag *tags)
  187. {
  188. struct param_struct *params = (struct param_struct *)tags;
  189. build_tag_list(params, &params->u2);
  190. }