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