[PATCH] knfsd: nfsd4: fix non-terminated string
[wrt350n-kernel.git] / arch / s390 / kernel / early.c
blobe518dd53eff52408f0b7427d181efd4715145e75
1 /*
2 * arch/s390/kernel/early.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Hongjie Yang <hongjie@us.ibm.com>,
6 * Heiko Carstens <heiko.carstens@de.ibm.com>
7 */
9 #include <linux/init.h>
10 #include <linux/errno.h>
11 #include <linux/string.h>
12 #include <linux/ctype.h>
13 #include <linux/lockdep.h>
14 #include <linux/module.h>
15 #include <linux/pfn.h>
16 #include <linux/uaccess.h>
17 #include <asm/lowcore.h>
18 #include <asm/processor.h>
19 #include <asm/sections.h>
20 #include <asm/setup.h>
21 #include <asm/cpcmd.h>
22 #include <asm/sclp.h>
25 * Create a Kernel NSS if the SAVESYS= parameter is defined
27 #define DEFSYS_CMD_SIZE 96
28 #define SAVESYS_CMD_SIZE 32
30 char kernel_nss_name[NSS_NAME_SIZE + 1];
32 #ifdef CONFIG_SHARED_KERNEL
33 static noinline __init void create_kernel_nss(void)
35 unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size;
36 #ifdef CONFIG_BLK_DEV_INITRD
37 unsigned int sinitrd_pfn, einitrd_pfn;
38 #endif
39 int response;
40 char *savesys_ptr;
41 char upper_command_line[COMMAND_LINE_SIZE];
42 char defsys_cmd[DEFSYS_CMD_SIZE];
43 char savesys_cmd[SAVESYS_CMD_SIZE];
45 /* Do nothing if we are not running under VM */
46 if (!MACHINE_IS_VM)
47 return;
49 /* Convert COMMAND_LINE to upper case */
50 for (i = 0; i < strlen(COMMAND_LINE); i++)
51 upper_command_line[i] = toupper(COMMAND_LINE[i]);
53 savesys_ptr = strstr(upper_command_line, "SAVESYS=");
55 if (!savesys_ptr)
56 return;
58 savesys_ptr += 8; /* Point to the beginning of the NSS name */
59 for (i = 0; i < NSS_NAME_SIZE; i++) {
60 if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0')
61 break;
62 kernel_nss_name[i] = savesys_ptr[i];
65 stext_pfn = PFN_DOWN(__pa(&_stext));
66 eshared_pfn = PFN_DOWN(__pa(&_eshared));
67 end_pfn = PFN_UP(__pa(&_end));
68 min_size = end_pfn << 2;
70 sprintf(defsys_cmd, "DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X",
71 kernel_nss_name, stext_pfn - 1, stext_pfn, eshared_pfn - 1,
72 eshared_pfn, end_pfn);
74 #ifdef CONFIG_BLK_DEV_INITRD
75 if (INITRD_START && INITRD_SIZE) {
76 sinitrd_pfn = PFN_DOWN(__pa(INITRD_START));
77 einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE));
78 min_size = einitrd_pfn << 2;
79 sprintf(defsys_cmd, "%s EW %.5X-%.5X", defsys_cmd,
80 sinitrd_pfn, einitrd_pfn);
82 #endif
84 sprintf(defsys_cmd, "%s EW MINSIZE=%.7iK", defsys_cmd, min_size);
85 sprintf(savesys_cmd, "SAVESYS %s \n IPL %s",
86 kernel_nss_name, kernel_nss_name);
88 __cpcmd(defsys_cmd, NULL, 0, &response);
90 if (response != 0)
91 return;
93 __cpcmd(savesys_cmd, NULL, 0, &response);
95 if (response != strlen(savesys_cmd))
96 return;
98 ipl_flags = IPL_NSS_VALID;
101 #else /* CONFIG_SHARED_KERNEL */
103 static inline void create_kernel_nss(void) { }
105 #endif /* CONFIG_SHARED_KERNEL */
108 * Clear bss memory
110 static noinline __init void clear_bss_section(void)
112 memset(__bss_start, 0, _end - __bss_start);
116 * Initialize storage key for kernel pages
118 static noinline __init void init_kernel_storage_key(void)
120 unsigned long end_pfn, init_pfn;
122 end_pfn = PFN_UP(__pa(&_end));
124 for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++)
125 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
128 static noinline __init void detect_machine_type(void)
130 struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data;
132 asm volatile("stidp %0" : "=m" (S390_lowcore.cpu_data.cpu_id));
134 /* Running under z/VM ? */
135 if (cpuinfo->cpu_id.version == 0xff)
136 machine_flags |= 1;
138 /* Running on a P/390 ? */
139 if (cpuinfo->cpu_id.machine == 0x7490)
140 machine_flags |= 4;
143 static noinline __init int memory_fast_detect(void)
146 unsigned long val0 = 0;
147 unsigned long val1 = 0xc;
148 int ret = -ENOSYS;
150 if (ipl_flags & IPL_NSS_VALID)
151 return -ENOSYS;
153 asm volatile(
154 " diag %1,%2,0x260\n"
155 "0: lhi %0,0\n"
156 "1:\n"
157 EX_TABLE(0b,1b)
158 : "+d" (ret), "+d" (val0), "+d" (val1) : : "cc");
160 if (ret || val0 != val1)
161 return -ENOSYS;
163 memory_chunk[0].size = val0;
164 return 0;
167 #define ADDR2G (1UL << 31)
169 static noinline __init unsigned long sclp_memory_detect(void)
171 struct sclp_readinfo_sccb *sccb;
172 unsigned long long memsize;
174 sccb = &s390_readinfo_sccb;
176 if (sccb->header.response_code != 0x10)
177 return 0;
179 if (sccb->rnsize)
180 memsize = sccb->rnsize << 20;
181 else
182 memsize = sccb->rnsize2 << 20;
183 if (sccb->rnmax)
184 memsize *= sccb->rnmax;
185 else
186 memsize *= sccb->rnmax2;
187 #ifndef CONFIG_64BIT
189 * Can't deal with more than 2G in 31 bit addressing mode, so
190 * limit the value in order to avoid strange side effects.
192 if (memsize > ADDR2G)
193 memsize = ADDR2G;
194 #endif
195 return (unsigned long) memsize;
198 static inline __init unsigned long __tprot(unsigned long addr)
200 int cc = -1;
202 asm volatile(
203 " tprot 0(%1),0\n"
204 "0: ipm %0\n"
205 " srl %0,28\n"
206 "1:\n"
207 EX_TABLE(0b,1b)
208 : "+d" (cc) : "a" (addr) : "cc");
209 return (unsigned long)cc;
212 /* Checking memory in 128KB increments. */
213 #define CHUNK_INCR (1UL << 17)
215 static noinline __init void find_memory_chunks(unsigned long memsize)
217 unsigned long addr = 0, old_addr = 0;
218 unsigned long old_cc = CHUNK_READ_WRITE;
219 unsigned long cc;
220 int chunk = 0;
222 while (chunk < MEMORY_CHUNKS) {
223 cc = __tprot(addr);
224 while (cc == old_cc) {
225 addr += CHUNK_INCR;
226 cc = __tprot(addr);
227 #ifndef CONFIG_64BIT
228 if (addr == ADDR2G)
229 break;
230 #endif
233 if (old_addr != addr &&
234 (old_cc == CHUNK_READ_WRITE || old_cc == CHUNK_READ_ONLY)) {
235 memory_chunk[chunk].addr = old_addr;
236 memory_chunk[chunk].size = addr - old_addr;
237 memory_chunk[chunk].type = old_cc;
238 chunk++;
241 old_addr = addr;
242 old_cc = cc;
244 #ifndef CONFIG_64BIT
245 if (addr == ADDR2G)
246 break;
247 #endif
249 * Finish memory detection at the first hole, unless
250 * - we reached the hsa -> skip it.
251 * - we know there must be more.
253 if (cc == -1UL && !memsize && old_addr != ADDR2G)
254 break;
255 if (memsize && addr >= memsize)
256 break;
260 static __init void early_pgm_check_handler(void)
262 unsigned long addr;
263 const struct exception_table_entry *fixup;
265 addr = S390_lowcore.program_old_psw.addr;
266 fixup = search_exception_tables(addr & PSW_ADDR_INSN);
267 if (!fixup)
268 disabled_wait(0);
269 S390_lowcore.program_old_psw.addr = fixup->fixup | PSW_ADDR_AMODE;
272 static noinline __init void setup_lowcore_early(void)
274 psw_t psw;
276 psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
277 psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_ext_handler;
278 S390_lowcore.external_new_psw = psw;
279 psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
280 S390_lowcore.program_new_psw = psw;
281 s390_base_pgm_handler_fn = early_pgm_check_handler;
285 * Save ipl parameters, clear bss memory, initialize storage keys
286 * and create a kernel NSS at startup if the SAVESYS= parm is defined
288 void __init startup_init(void)
290 unsigned long memsize;
292 ipl_save_parameters();
293 clear_bss_section();
294 init_kernel_storage_key();
295 lockdep_init();
296 lockdep_off();
297 detect_machine_type();
298 create_kernel_nss();
299 sort_main_extable();
300 setup_lowcore_early();
301 sclp_readinfo_early();
302 memsize = sclp_memory_detect();
303 if (memory_fast_detect() < 0)
304 find_memory_chunks(memsize);
305 lockdep_on();