1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/types.h>
22#include <linux/kernel.h>
23#include <linux/init.h>
24#include <linux/slab.h>
25#include <linux/mm.h>
26#include <asm/hardware.h>
27#include <asm/io.h>
28#include <asm/mmzone.h>
29#include <asm/pdc.h>
30#include <asm/pdcpat.h>
31#include <asm/processor.h>
32#include <asm/page.h>
33#include <asm/parisc-device.h>
34
35
36
37
38
39#undef DEBUG_PAT
40
41int pdc_type __read_mostly = PDC_TYPE_ILLEGAL;
42
43void __init setup_pdc(void)
44{
45 long status;
46 unsigned int bus_id;
47 struct pdc_system_map_mod_info module_result;
48 struct pdc_module_path module_path;
49 struct pdc_model model;
50#ifdef CONFIG_64BIT
51 struct pdc_pat_cell_num cell_info;
52#endif
53
54
55
56 printk(KERN_INFO "Determining PDC firmware type: ");
57
58 status = pdc_system_map_find_mods(&module_result, &module_path, 0);
59 if (status == PDC_OK) {
60 pdc_type = PDC_TYPE_SYSTEM_MAP;
61 printk("System Map.\n");
62 return;
63 }
64
65
66
67
68
69
70
71
72
73
74
75
76#ifdef CONFIG_64BIT
77 status = pdc_pat_cell_get_number(&cell_info);
78 if (status == PDC_OK) {
79 pdc_type = PDC_TYPE_PAT;
80 printk("64 bit PAT.\n");
81 return;
82 }
83#endif
84
85
86
87 status = pdc_model_info(&model);
88
89 bus_id = (model.hversion >> (4 + 7)) & 0x1f;
90
91 switch (bus_id) {
92 case 0x4:
93 case 0x6:
94 case 0x7:
95 case 0x8:
96 case 0xA:
97 case 0xC:
98
99 pdc_type = PDC_TYPE_SNAKE;
100 printk("Snake.\n");
101 return;
102
103 default:
104
105 printk("Unsupported.\n");
106 panic("If this is a 64-bit machine, please try a 64-bit kernel.\n");
107 }
108}
109
110#define PDC_PAGE_ADJ_SHIFT (PAGE_SHIFT - 12)
111
112static void __init
113set_pmem_entry(physmem_range_t *pmem_ptr, unsigned long start,
114 unsigned long pages4k)
115{
116
117
118
119
120
121
122
123 if (unlikely( ((start & (PAGE_SIZE - 1)) != 0)
124 || ((pages4k & ((1UL << PDC_PAGE_ADJ_SHIFT) - 1)) != 0) )) {
125
126 panic("Memory range doesn't align with page size!\n");
127 }
128
129 pmem_ptr->start_pfn = (start >> PAGE_SHIFT);
130 pmem_ptr->pages = (pages4k >> PDC_PAGE_ADJ_SHIFT);
131}
132
133static void __init pagezero_memconfig(void)
134{
135 unsigned long npages;
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 npages = (PAGE_ALIGN(PAGE0->imm_max_mem) >> PAGE_SHIFT);
151 set_pmem_entry(pmem_ranges,0UL,npages);
152 npmem_ranges = 1;
153}
154
155#ifdef CONFIG_64BIT
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170static int __init
171pat_query_module(ulong pcell_loc, ulong mod_index)
172{
173 pdc_pat_cell_mod_maddr_block_t *pa_pdc_cell;
174 unsigned long bytecnt;
175 unsigned long temp;
176 long status;
177 struct parisc_device *dev;
178
179 pa_pdc_cell = kmalloc(sizeof (*pa_pdc_cell), GFP_KERNEL);
180 if (!pa_pdc_cell)
181 panic("couldn't allocate memory for PDC_PAT_CELL!");
182
183
184 status = pdc_pat_cell_module(&bytecnt, pcell_loc, mod_index,
185 PA_VIEW, pa_pdc_cell);
186
187 if (status != PDC_OK) {
188
189 kfree(pa_pdc_cell);
190 return status;
191 }
192
193 temp = pa_pdc_cell->cba;
194 dev = alloc_pa_dev(PAT_GET_CBA(temp), &(pa_pdc_cell->mod_path));
195 if (!dev) {
196 kfree(pa_pdc_cell);
197 return PDC_OK;
198 }
199
200
201
202
203
204
205
206
207 dev->pcell_loc = pcell_loc;
208 dev->mod_index = mod_index;
209
210
211
212 dev->mod_info = pa_pdc_cell->mod_info;
213 dev->pmod_loc = pa_pdc_cell->mod_location;
214
215 register_parisc_device(dev);
216
217#ifdef DEBUG_PAT
218 pdc_pat_cell_mod_maddr_block_t io_pdc_cell;
219
220 switch (PAT_GET_ENTITY(dev->mod_info)) {
221 unsigned long i;
222
223 case PAT_ENTITY_PROC:
224 printk(KERN_DEBUG "PAT_ENTITY_PROC: id_eid 0x%lx\n",
225 pa_pdc_cell->mod[0]);
226 break;
227
228 case PAT_ENTITY_MEM:
229 printk(KERN_DEBUG
230 "PAT_ENTITY_MEM: amount 0x%lx min_gni_base 0x%lx min_gni_len 0x%lx\n",
231 pa_pdc_cell->mod[0], pa_pdc_cell->mod[1],
232 pa_pdc_cell->mod[2]);
233 break;
234 case PAT_ENTITY_CA:
235 printk(KERN_DEBUG "PAT_ENTITY_CA: %ld\n", pcell_loc);
236 break;
237
238 case PAT_ENTITY_PBC:
239 printk(KERN_DEBUG "PAT_ENTITY_PBC: ");
240 goto print_ranges;
241
242 case PAT_ENTITY_SBA:
243 printk(KERN_DEBUG "PAT_ENTITY_SBA: ");
244 goto print_ranges;
245
246 case PAT_ENTITY_LBA:
247 printk(KERN_DEBUG "PAT_ENTITY_LBA: ");
248
249 print_ranges:
250 pdc_pat_cell_module(&bytecnt, pcell_loc, mod_index,
251 IO_VIEW, &io_pdc_cell);
252 printk(KERN_DEBUG "ranges %ld\n", pa_pdc_cell->mod[1]);
253 for (i = 0; i < pa_pdc_cell->mod[1]; i++) {
254 printk(KERN_DEBUG
255 " PA_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n",
256 i, pa_pdc_cell->mod[2 + i * 3],
257 pa_pdc_cell->mod[3 + i * 3],
258 pa_pdc_cell->mod[4 + i * 3]);
259 printk(KERN_DEBUG
260 " IO_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n",
261 i, io_pdc_cell->mod[2 + i * 3],
262 io_pdc_cell->mod[3 + i * 3],
263 io_pdc_cell->mod[4 + i * 3]);
264 }
265 printk(KERN_DEBUG "\n");
266 break;
267 }
268#endif
269
270 kfree(pa_pdc_cell);
271
272 return PDC_OK;
273}
274
275
276
277
278
279
280
281
282
283#define PAT_MAX_RANGES (4 * MAX_PHYSMEM_RANGES)
284
285static void __init pat_memconfig(void)
286{
287 unsigned long actual_len;
288 struct pdc_pat_pd_addr_map_entry mem_table[PAT_MAX_RANGES+1];
289 struct pdc_pat_pd_addr_map_entry *mtbl_ptr;
290 physmem_range_t *pmem_ptr;
291 long status;
292 int entries;
293 unsigned long length;
294 int i;
295
296 length = (PAT_MAX_RANGES + 1) * sizeof(struct pdc_pat_pd_addr_map_entry);
297
298 status = pdc_pat_pd_get_addr_map(&actual_len, mem_table, length, 0L);
299
300 if ((status != PDC_OK)
301 || ((actual_len % sizeof(struct pdc_pat_pd_addr_map_entry)) != 0)) {
302
303
304
305
306
307 printk("\n\n\n");
308 printk(KERN_WARNING "WARNING! Could not get full memory configuration. "
309 "All memory may not be used!\n\n\n");
310 pagezero_memconfig();
311 return;
312 }
313
314 entries = actual_len / sizeof(struct pdc_pat_pd_addr_map_entry);
315
316 if (entries > PAT_MAX_RANGES) {
317 printk(KERN_WARNING "This Machine has more memory ranges than we support!\n");
318 printk(KERN_WARNING "Some memory may not be used!\n");
319 }
320
321
322
323
324
325
326 npmem_ranges = 0;
327 mtbl_ptr = mem_table;
328 pmem_ptr = pmem_ranges;
329 for (i = 0; i < entries; i++,mtbl_ptr++) {
330 if ( (mtbl_ptr->entry_type != PAT_MEMORY_DESCRIPTOR)
331 || (mtbl_ptr->memory_type != PAT_MEMTYPE_MEMORY)
332 || (mtbl_ptr->pages == 0)
333 || ( (mtbl_ptr->memory_usage != PAT_MEMUSE_GENERAL)
334 && (mtbl_ptr->memory_usage != PAT_MEMUSE_GI)
335 && (mtbl_ptr->memory_usage != PAT_MEMUSE_GNI) ) ) {
336
337 continue;
338 }
339
340 if (npmem_ranges == MAX_PHYSMEM_RANGES) {
341 printk(KERN_WARNING "This Machine has more memory ranges than we support!\n");
342 printk(KERN_WARNING "Some memory will not be used!\n");
343 break;
344 }
345
346 set_pmem_entry(pmem_ptr++,mtbl_ptr->paddr,mtbl_ptr->pages);
347 npmem_ranges++;
348 }
349}
350
351static int __init pat_inventory(void)
352{
353 int status;
354 ulong mod_index = 0;
355 struct pdc_pat_cell_num cell_info;
356
357
358
359
360
361 status = pdc_pat_cell_get_number(&cell_info);
362 if (status != PDC_OK) {
363 return 0;
364 }
365
366#ifdef DEBUG_PAT
367 printk(KERN_DEBUG "CELL_GET_NUMBER: 0x%lx 0x%lx\n", cell_info.cell_num,
368 cell_info.cell_loc);
369#endif
370
371 while (PDC_OK == pat_query_module(cell_info.cell_loc, mod_index)) {
372 mod_index++;
373 }
374
375 return mod_index;
376}
377
378
379static void __init sprockets_memconfig(void)
380{
381 struct pdc_memory_table_raddr r_addr;
382 struct pdc_memory_table mem_table[MAX_PHYSMEM_RANGES];
383 struct pdc_memory_table *mtbl_ptr;
384 physmem_range_t *pmem_ptr;
385 long status;
386 int entries;
387 int i;
388
389 status = pdc_mem_mem_table(&r_addr,mem_table,
390 (unsigned long)MAX_PHYSMEM_RANGES);
391
392 if (status != PDC_OK) {
393
394
395
396
397
398
399
400 pagezero_memconfig();
401 return;
402 }
403
404 if (r_addr.entries_total > MAX_PHYSMEM_RANGES) {
405 printk(KERN_WARNING "This Machine has more memory ranges than we support!\n");
406 printk(KERN_WARNING "Some memory will not be used!\n");
407 }
408
409 entries = (int)r_addr.entries_returned;
410
411 npmem_ranges = 0;
412 mtbl_ptr = mem_table;
413 pmem_ptr = pmem_ranges;
414 for (i = 0; i < entries; i++,mtbl_ptr++) {
415 set_pmem_entry(pmem_ptr++,mtbl_ptr->paddr,mtbl_ptr->pages);
416 npmem_ranges++;
417 }
418}
419
420#else
421
422#define pat_inventory() do { } while (0)
423#define pat_memconfig() do { } while (0)
424#define sprockets_memconfig() pagezero_memconfig()
425
426#endif
427
428
429#ifndef CONFIG_PA20
430
431
432
433static struct parisc_device * __init
434legacy_create_device(struct pdc_memory_map *r_addr,
435 struct pdc_module_path *module_path)
436{
437 struct parisc_device *dev;
438 int status = pdc_mem_map_hpa(r_addr, module_path);
439 if (status != PDC_OK)
440 return NULL;
441
442 dev = alloc_pa_dev(r_addr->hpa, &module_path->path);
443 if (dev == NULL)
444 return NULL;
445
446 register_parisc_device(dev);
447 return dev;
448}
449
450
451
452
453
454
455
456
457
458
459static void __init snake_inventory(void)
460{
461 int mod;
462 for (mod = 0; mod < 16; mod++) {
463 struct parisc_device *dev;
464 struct pdc_module_path module_path;
465 struct pdc_memory_map r_addr;
466 unsigned int func;
467
468 memset(module_path.path.bc, 0xff, 6);
469 module_path.path.mod = mod;
470 dev = legacy_create_device(&r_addr, &module_path);
471 if ((!dev) || (dev->id.hw_type != HPHW_BA))
472 continue;
473
474 memset(module_path.path.bc, 0xff, 4);
475 module_path.path.bc[4] = mod;
476
477 for (func = 0; func < 16; func++) {
478 module_path.path.bc[5] = 0;
479 module_path.path.mod = func;
480 legacy_create_device(&r_addr, &module_path);
481 }
482 }
483}
484
485#else
486#define snake_inventory() do { } while (0)
487#endif
488
489
490
491
492
493
494
495
496
497
498
499
500static void __init
501add_system_map_addresses(struct parisc_device *dev, int num_addrs,
502 int module_instance)
503{
504 int i;
505 long status;
506 struct pdc_system_map_addr_info addr_result;
507
508 dev->addr = kmalloc(num_addrs * sizeof(unsigned long), GFP_KERNEL);
509 if(!dev->addr) {
510 printk(KERN_ERR "%s %s(): memory allocation failure\n",
511 __FILE__, __func__);
512 return;
513 }
514
515 for(i = 1; i <= num_addrs; ++i) {
516 status = pdc_system_map_find_addrs(&addr_result,
517 module_instance, i);
518 if(PDC_OK == status) {
519 dev->addr[dev->num_addrs] = (unsigned long)addr_result.mod_addr;
520 dev->num_addrs++;
521 } else {
522 printk(KERN_WARNING
523 "Bad PDC_FIND_ADDRESS status return (%ld) for index %d\n",
524 status, i);
525 }
526 }
527}
528
529
530
531
532
533
534
535static void __init system_map_inventory(void)
536{
537 int i;
538 long status = PDC_OK;
539
540 for (i = 0; i < 256; i++) {
541 struct parisc_device *dev;
542 struct pdc_system_map_mod_info module_result;
543 struct pdc_module_path module_path;
544
545 status = pdc_system_map_find_mods(&module_result,
546 &module_path, i);
547 if ((status == PDC_BAD_PROC) || (status == PDC_NE_MOD))
548 break;
549 if (status != PDC_OK)
550 continue;
551
552 dev = alloc_pa_dev(module_result.mod_addr, &module_path.path);
553 if (!dev)
554 continue;
555
556 register_parisc_device(dev);
557
558
559 if (!module_result.add_addrs)
560 continue;
561
562 add_system_map_addresses(dev, module_result.add_addrs, i);
563 }
564
565 walk_central_bus();
566 return;
567}
568
569void __init do_memory_inventory(void)
570{
571 switch (pdc_type) {
572
573 case PDC_TYPE_PAT:
574 pat_memconfig();
575 break;
576
577 case PDC_TYPE_SYSTEM_MAP:
578 sprockets_memconfig();
579 break;
580
581 case PDC_TYPE_SNAKE:
582 pagezero_memconfig();
583 return;
584
585 default:
586 panic("Unknown PDC type!\n");
587 }
588
589 if (npmem_ranges == 0 || pmem_ranges[0].start_pfn != 0) {
590 printk(KERN_WARNING "Bad memory configuration returned!\n");
591 printk(KERN_WARNING "Some memory may not be used!\n");
592 pagezero_memconfig();
593 }
594}
595
596void __init do_device_inventory(void)
597{
598 printk(KERN_INFO "Searching for devices...\n");
599
600 init_parisc_bus();
601
602 switch (pdc_type) {
603
604 case PDC_TYPE_PAT:
605 pat_inventory();
606 break;
607
608 case PDC_TYPE_SYSTEM_MAP:
609 system_map_inventory();
610 break;
611
612 case PDC_TYPE_SNAKE:
613 snake_inventory();
614 break;
615
616 default:
617 panic("Unknown PDC type!\n");
618 }
619 printk(KERN_INFO "Found devices:\n");
620 print_parisc_devices();
621}
622