OSDN Git Service

dma-mapping: bypass indirect calls for dma-direct
[uclinux-h8/linux.git] / arch / parisc / kernel / setup.c
1 /*
2  *    Initial setup-routines for HP 9000 based hardware.
3  *
4  *    Copyright (C) 1991, 1992, 1995  Linus Torvalds
5  *    Modifications for PA-RISC (C) 1999 Helge Deller <deller@gmx.de>
6  *    Modifications copyright 1999 SuSE GmbH (Philipp Rumpf)
7  *    Modifications copyright 2000 Martin K. Petersen <mkp@mkp.net>
8  *    Modifications copyright 2000 Philipp Rumpf <prumpf@tux.org>
9  *    Modifications copyright 2001 Ryan Bradetich <rbradetich@uswest.net>
10  *
11  *    Initial PA-RISC Version: 04-23-1999 by Helge Deller
12  *
13  *    This program is free software; you can redistribute it and/or modify
14  *    it under the terms of the GNU General Public License as published by
15  *    the Free Software Foundation; either version 2, or (at your option)
16  *    any later version.
17  *
18  *    This program is distributed in the hope that it will be useful,
19  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *    GNU General Public License for more details.
22  *
23  *    You should have received a copy of the GNU General Public License
24  *    along with this program; if not, write to the Free Software
25  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26  *
27  */
28
29 #include <linux/kernel.h>
30 #include <linux/initrd.h>
31 #include <linux/init.h>
32 #include <linux/console.h>
33 #include <linux/seq_file.h>
34 #define PCI_DEBUG
35 #include <linux/pci.h>
36 #undef PCI_DEBUG
37 #include <linux/proc_fs.h>
38 #include <linux/export.h>
39 #include <linux/sched.h>
40 #include <linux/sched/clock.h>
41 #include <linux/start_kernel.h>
42
43 #include <asm/processor.h>
44 #include <asm/sections.h>
45 #include <asm/pdc.h>
46 #include <asm/led.h>
47 #include <asm/machdep.h>        /* for pa7300lc_init() proto */
48 #include <asm/pdc_chassis.h>
49 #include <asm/io.h>
50 #include <asm/setup.h>
51 #include <asm/unwind.h>
52 #include <asm/smp.h>
53
54 static char __initdata command_line[COMMAND_LINE_SIZE];
55
56 /* Intended for ccio/sba/cpu statistics under /proc/bus/{runway|gsc} */
57 struct proc_dir_entry * proc_runway_root __read_mostly = NULL;
58 struct proc_dir_entry * proc_gsc_root __read_mostly = NULL;
59 struct proc_dir_entry * proc_mckinley_root __read_mostly = NULL;
60
61 void __init setup_cmdline(char **cmdline_p)
62 {
63         extern unsigned int boot_args[];
64
65         /* Collect stuff passed in from the boot loader */
66
67         /* boot_args[0] is free-mem start, boot_args[1] is ptr to command line */
68         if (boot_args[0] < 64) {
69                 /* called from hpux boot loader */
70                 boot_command_line[0] = '\0';
71         } else {
72                 strlcpy(boot_command_line, (char *)__va(boot_args[1]),
73                         COMMAND_LINE_SIZE);
74
75 #ifdef CONFIG_BLK_DEV_INITRD
76                 if (boot_args[2] != 0) /* did palo pass us a ramdisk? */
77                 {
78                     initrd_start = (unsigned long)__va(boot_args[2]);
79                     initrd_end = (unsigned long)__va(boot_args[3]);
80                 }
81 #endif
82         }
83
84         strcpy(command_line, boot_command_line);
85         *cmdline_p = command_line;
86 }
87
88 #ifdef CONFIG_PA11
89 void __init dma_ops_init(void)
90 {
91         switch (boot_cpu_data.cpu_type) {
92         case pcx:
93                 /*
94                  * We've got way too many dependencies on 1.1 semantics
95                  * to support 1.0 boxes at this point.
96                  */
97                 panic(  "PA-RISC Linux currently only supports machines that conform to\n"
98                         "the PA-RISC 1.1 or 2.0 architecture specification.\n");
99
100         case pcxl2:
101                 pa7300lc_init();
102                 break;
103         default:
104                 break;
105         }
106 }
107 #endif
108
109 extern void collect_boot_cpu_data(void);
110
111 void __init setup_arch(char **cmdline_p)
112 {
113 #ifdef CONFIG_64BIT
114         extern int parisc_narrow_firmware;
115 #endif
116         unwind_init();
117
118         init_per_cpu(smp_processor_id());       /* Set Modes & Enable FP */
119
120 #ifdef CONFIG_64BIT
121         printk(KERN_INFO "The 64-bit Kernel has started...\n");
122 #else
123         printk(KERN_INFO "The 32-bit Kernel has started...\n");
124 #endif
125
126         printk(KERN_INFO "Kernel default page size is %d KB. Huge pages ",
127                 (int)(PAGE_SIZE / 1024));
128 #ifdef CONFIG_HUGETLB_PAGE
129         printk(KERN_CONT "enabled with %d MB physical and %d MB virtual size",
130                  1 << (REAL_HPAGE_SHIFT - 20), 1 << (HPAGE_SHIFT - 20));
131 #else
132         printk(KERN_CONT "disabled");
133 #endif
134         printk(KERN_CONT ".\n");
135
136         /*
137          * Check if initial kernel page mappings are sufficient.
138          * panic early if not, else we may access kernel functions
139          * and variables which can't be reached.
140          */
141         if (__pa((unsigned long) &_end) >= KERNEL_INITIAL_SIZE)
142                 panic("KERNEL_INITIAL_ORDER too small!");
143
144         pdc_console_init();
145
146 #ifdef CONFIG_64BIT
147         if(parisc_narrow_firmware) {
148                 printk(KERN_INFO "Kernel is using PDC in 32-bit mode.\n");
149         }
150 #endif
151         setup_pdc();
152         setup_cmdline(cmdline_p);
153         collect_boot_cpu_data();
154         do_memory_inventory();  /* probe for physical memory */
155         parisc_cache_init();
156         paging_init();
157
158 #ifdef CONFIG_CHASSIS_LCD_LED
159         /* initialize the LCD/LED after boot_cpu_data is available ! */
160         led_init();             /* LCD/LED initialization */
161 #endif
162
163 #ifdef CONFIG_PA11
164         dma_ops_init();
165 #endif
166
167 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
168         conswitchp = &dummy_con;        /* we use do_take_over_console() later ! */
169 #endif
170
171         clear_sched_clock_stable();
172 }
173
174 /*
175  * Display CPU info for all CPUs.
176  * for parisc this is in processor.c
177  */
178 extern int show_cpuinfo (struct seq_file *m, void *v);
179
180 static void *
181 c_start (struct seq_file *m, loff_t *pos)
182 {
183         /* Looks like the caller will call repeatedly until we return
184          * 0, signaling EOF perhaps.  This could be used to sequence
185          * through CPUs for example.  Since we print all cpu info in our
186          * show_cpuinfo() disregarding 'pos' (which I assume is 'v' above)
187          * we only allow for one "position".  */
188         return ((long)*pos < 1) ? (void *)1 : NULL;
189 }
190
191 static void *
192 c_next (struct seq_file *m, void *v, loff_t *pos)
193 {
194         ++*pos;
195         return c_start(m, pos);
196 }
197
198 static void
199 c_stop (struct seq_file *m, void *v)
200 {
201 }
202
203 const struct seq_operations cpuinfo_op = {
204         .start  = c_start,
205         .next   = c_next,
206         .stop   = c_stop,
207         .show   = show_cpuinfo
208 };
209
210 static void __init parisc_proc_mkdir(void)
211 {
212         /*
213         ** Can't call proc_mkdir() until after proc_root_init() has been
214         ** called by start_kernel(). In other words, this code can't
215         ** live in arch/.../setup.c because start_parisc() calls
216         ** start_kernel().
217         */
218         switch (boot_cpu_data.cpu_type) {
219         case pcxl:
220         case pcxl2:
221                 if (NULL == proc_gsc_root)
222                 {
223                         proc_gsc_root = proc_mkdir("bus/gsc", NULL);
224                 }
225                 break;
226         case pcxt_:
227         case pcxu:
228         case pcxu_:
229         case pcxw:
230         case pcxw_:
231         case pcxw2:
232                 if (NULL == proc_runway_root)
233                 {
234                         proc_runway_root = proc_mkdir("bus/runway", NULL);
235                 }
236                 break;
237         case mako:
238         case mako2:
239                 if (NULL == proc_mckinley_root)
240                 {
241                         proc_mckinley_root = proc_mkdir("bus/mckinley", NULL);
242                 }
243                 break;
244         default:
245                 /* FIXME: this was added to prevent the compiler 
246                  * complaining about missing pcx, pcxs and pcxt
247                  * I'm assuming they have neither gsc nor runway */
248                 break;
249         }
250 }
251
252 static struct resource central_bus = {
253         .name   = "Central Bus",
254         .start  = F_EXTEND(0xfff80000),
255         .end    = F_EXTEND(0xfffaffff),
256         .flags  = IORESOURCE_MEM,
257 };
258
259 static struct resource local_broadcast = {
260         .name   = "Local Broadcast",
261         .start  = F_EXTEND(0xfffb0000),
262         .end    = F_EXTEND(0xfffdffff),
263         .flags  = IORESOURCE_MEM,
264 };
265
266 static struct resource global_broadcast = {
267         .name   = "Global Broadcast",
268         .start  = F_EXTEND(0xfffe0000),
269         .end    = F_EXTEND(0xffffffff),
270         .flags  = IORESOURCE_MEM,
271 };
272
273 static int __init parisc_init_resources(void)
274 {
275         int result;
276
277         result = request_resource(&iomem_resource, &central_bus);
278         if (result < 0) {
279                 printk(KERN_ERR 
280                        "%s: failed to claim %s address space!\n", 
281                        __FILE__, central_bus.name);
282                 return result;
283         }
284
285         result = request_resource(&iomem_resource, &local_broadcast);
286         if (result < 0) {
287                 printk(KERN_ERR 
288                        "%s: failed to claim %saddress space!\n", 
289                        __FILE__, local_broadcast.name);
290                 return result;
291         }
292
293         result = request_resource(&iomem_resource, &global_broadcast);
294         if (result < 0) {
295                 printk(KERN_ERR 
296                        "%s: failed to claim %s address space!\n", 
297                        __FILE__, global_broadcast.name);
298                 return result;
299         }
300
301         return 0;
302 }
303
304 static int no_alternatives __initdata;
305 static int __init setup_no_alternatives(char *str)
306 {
307         no_alternatives = 1;
308         return 1;
309 }
310 __setup("no-alternatives", setup_no_alternatives);
311
312 static void __init apply_alternatives_all(void)
313 {
314         struct alt_instr *entry;
315         int index = 0, applied = 0;
316
317
318         pr_info("alternatives: %spatching kernel code\n",
319                 no_alternatives ? "NOT " : "");
320         if (no_alternatives)
321                 return;
322
323         set_kernel_text_rw(1);
324
325         for (entry = (struct alt_instr *) &__alt_instructions;
326                 entry < (struct alt_instr *) &__alt_instructions_end;
327                 entry++, index++) {
328
329                 u32 *from, len, cond, replacement;
330
331                 from = (u32 *)((ulong)&entry->orig_offset + entry->orig_offset);
332                 len = entry->len;
333                 cond = entry->cond;
334                 replacement = entry->replacement;
335
336                 WARN_ON(!cond);
337                 pr_debug("Check %d: Cond 0x%x, Replace %02d instructions @ 0x%px with 0x%08x\n",
338                         index, cond, len, from, replacement);
339
340                 if ((cond & ALT_COND_NO_SMP) && (num_online_cpus() != 1))
341                         continue;
342                 if ((cond & ALT_COND_NO_DCACHE) && (cache_info.dc_size != 0))
343                         continue;
344                 if ((cond & ALT_COND_NO_ICACHE) && (cache_info.ic_size != 0))
345                         continue;
346
347                 /*
348                  * If the PDC_MODEL capabilities has Non-coherent IO-PDIR bit
349                  * set (bit #61, big endian), we have to flush and sync every
350                  * time IO-PDIR is changed in Ike/Astro.
351                  */
352                 if ((cond & ALT_COND_NO_IOC_FDC) &&
353                         (boot_cpu_data.pdc.capabilities & PDC_MODEL_IOPDIR_FDC))
354                         continue;
355
356                 /* Want to replace pdtlb by a pdtlb,l instruction? */
357                 if (replacement == INSN_PxTLB) {
358                         replacement = *from;
359                         if (boot_cpu_data.cpu_type >= pcxu) /* >= pa2.0 ? */
360                                 replacement |= (1 << 10); /* set el bit */
361                 }
362
363                 /*
364                  * Replace instruction with NOPs?
365                  * For long distance insert a branch instruction instead.
366                  */
367                 if (replacement == INSN_NOP && len > 1)
368                         replacement = 0xe8000002 + (len-2)*8; /* "b,n .+8" */
369
370                 pr_debug("Do    %d: Cond 0x%x, Replace %02d instructions @ 0x%px with 0x%08x\n",
371                         index, cond, len, from, replacement);
372
373                 /* Replace instruction */
374                 *from = replacement;
375                 applied++;
376         }
377
378         pr_info("alternatives: applied %d out of %d patches\n", applied, index);
379
380         set_kernel_text_rw(0);
381 }
382
383
384 extern void gsc_init(void);
385 extern void processor_init(void);
386 extern void ccio_init(void);
387 extern void hppb_init(void);
388 extern void dino_init(void);
389 extern void iosapic_init(void);
390 extern void lba_init(void);
391 extern void sba_init(void);
392 extern void eisa_init(void);
393
394 static int __init parisc_init(void)
395 {
396         u32 osid = (OS_ID_LINUX << 16);
397
398         parisc_proc_mkdir();
399         parisc_init_resources();
400         do_device_inventory();                  /* probe for hardware */
401
402         parisc_pdc_chassis_init();
403         
404         /* set up a new led state on systems shipped LED State panel */
405         pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BSTART);
406
407         /* tell PDC we're Linux. Nevermind failure. */
408         pdc_stable_write(0x40, &osid, sizeof(osid));
409         
410         /* start with known state */
411         flush_cache_all_local();
412         flush_tlb_all_local(NULL);
413
414         processor_init();
415 #ifdef CONFIG_SMP
416         pr_info("CPU(s): %d out of %d %s at %d.%06d MHz online\n",
417                 num_online_cpus(), num_present_cpus(),
418 #else
419         pr_info("CPU(s): 1 x %s at %d.%06d MHz\n",
420 #endif
421                         boot_cpu_data.cpu_name,
422                         boot_cpu_data.cpu_hz / 1000000,
423                         boot_cpu_data.cpu_hz % 1000000  );
424
425         apply_alternatives_all();
426         parisc_setup_cache_timing();
427
428         /* These are in a non-obvious order, will fix when we have an iotree */
429 #if defined(CONFIG_IOSAPIC)
430         iosapic_init();
431 #endif
432 #if defined(CONFIG_IOMMU_SBA)
433         sba_init();
434 #endif
435 #if defined(CONFIG_PCI_LBA)
436         lba_init();
437 #endif
438
439         /* CCIO before any potential subdevices */
440 #if defined(CONFIG_IOMMU_CCIO)
441         ccio_init();
442 #endif
443
444         /*
445          * Need to register Asp & Wax before the EISA adapters for the IRQ
446          * regions.  EISA must come before PCI to be sure it gets IRQ region
447          * 0.
448          */
449 #if defined(CONFIG_GSC_LASI) || defined(CONFIG_GSC_WAX)
450         gsc_init();
451 #endif
452 #ifdef CONFIG_EISA
453         eisa_init();
454 #endif
455
456 #if defined(CONFIG_HPPB)
457         hppb_init();
458 #endif
459
460 #if defined(CONFIG_GSC_DINO)
461         dino_init();
462 #endif
463
464 #ifdef CONFIG_CHASSIS_LCD_LED
465         register_led_regions(); /* register LED port info in procfs */
466 #endif
467
468         return 0;
469 }
470 arch_initcall(parisc_init);
471
472 void __init start_parisc(void)
473 {
474         extern void early_trap_init(void);
475
476         int ret, cpunum;
477         struct pdc_coproc_cfg coproc_cfg;
478
479         cpunum = smp_processor_id();
480
481         init_cpu_topology();
482
483         set_firmware_width_unlocked();
484
485         ret = pdc_coproc_cfg_unlocked(&coproc_cfg);
486         if (ret >= 0 && coproc_cfg.ccr_functional) {
487                 mtctl(coproc_cfg.ccr_functional, 10);
488
489                 per_cpu(cpu_data, cpunum).fp_rev = coproc_cfg.revision;
490                 per_cpu(cpu_data, cpunum).fp_model = coproc_cfg.model;
491
492                 asm volatile ("fstd     %fr0,8(%sp)");
493         } else {
494                 panic("must have an fpu to boot linux");
495         }
496
497         early_trap_init(); /* initialize checksum of fault_vector */
498
499         start_kernel();
500         // not reached
501 }