4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Copyright (c) 1999 The Puffin Group (David Kennedy and Alex deVries)
10 * Copyright (c) 2001 Matthew Wilcox for Hewlett-Packard
12 * These are the routines to discover what hardware exists in this box.
13 * This task is complicated by there being 3 different ways of
14 * performing an inventory, depending largely on the age of the box.
15 * The recommended way to do this is to check to see whether the machine
16 * is a `Snake' first, then try System Map, then try PAT. We try System
17 * Map before checking for a Snake -- this probably doesn't cause any
21 #include <linux/types.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
26 #include <asm/hardware.h>
28 #include <asm/mmzone.h>
30 #include <asm/pdcpat.h>
31 #include <asm/processor.h>
33 #include <asm/parisc-device.h>
34 #include <asm/tlbflush.h>
38 ** DEBUG_PAT Dump details which PDC PAT provides about ranges/devices.
42 int pdc_type __ro_after_init
= PDC_TYPE_ILLEGAL
;
44 /* cell number and location (PAT firmware only) */
45 unsigned long parisc_cell_num __ro_after_init
;
46 unsigned long parisc_cell_loc __ro_after_init
;
47 unsigned long parisc_pat_pdc_cap __ro_after_init
;
50 void __init
setup_pdc(void)
54 struct pdc_system_map_mod_info module_result
;
55 struct pdc_module_path module_path
;
56 struct pdc_model model
;
58 struct pdc_pat_cell_num cell_info
;
61 /* Determine the pdc "type" used on this machine */
63 printk(KERN_INFO
"Determining PDC firmware type: ");
65 status
= pdc_system_map_find_mods(&module_result
, &module_path
, 0);
66 if (status
== PDC_OK
) {
67 pdc_type
= PDC_TYPE_SYSTEM_MAP
;
68 pr_cont("System Map.\n");
73 * If the machine doesn't support PDC_SYSTEM_MAP then either it
74 * is a pdc pat box, or it is an older box. All 64 bit capable
75 * machines are either pdc pat boxes or they support PDC_SYSTEM_MAP.
79 * TODO: We should test for 64 bit capability and give a
84 status
= pdc_pat_cell_get_number(&cell_info
);
85 if (status
== PDC_OK
) {
86 unsigned long legacy_rev
, pat_rev
;
87 pdc_type
= PDC_TYPE_PAT
;
88 pr_cont("64 bit PAT.\n");
89 parisc_cell_num
= cell_info
.cell_num
;
90 parisc_cell_loc
= cell_info
.cell_loc
;
91 pr_info("PAT: Running on cell %lu and location %lu.\n",
92 parisc_cell_num
, parisc_cell_loc
);
93 status
= pdc_pat_pd_get_pdc_revisions(&legacy_rev
,
94 &pat_rev
, &parisc_pat_pdc_cap
);
95 pr_info("PAT: legacy revision 0x%lx, pat_rev 0x%lx, pdc_cap 0x%lx, S-PTLB %d, HPMC_RENDEZ %d.\n",
96 legacy_rev
, pat_rev
, parisc_pat_pdc_cap
,
98 & PDC_PAT_CAPABILITY_BIT_SIMULTANEOUS_PTLB
? 1:0,
100 & PDC_PAT_CAPABILITY_BIT_PDC_HPMC_RENDEZ
? 1:0);
105 /* Check the CPU's bus ID. There's probably a better test. */
107 status
= pdc_model_info(&model
);
109 bus_id
= (model
.hversion
>> (4 + 7)) & 0x1f;
112 case 0x4: /* 720, 730, 750, 735, 755 */
113 case 0x6: /* 705, 710 */
114 case 0x7: /* 715, 725 */
115 case 0x8: /* 745, 747, 742 */
116 case 0xA: /* 712 and similar */
117 case 0xC: /* 715/64, at least */
119 pdc_type
= PDC_TYPE_SNAKE
;
123 default: /* Everything else */
125 pr_cont("Unsupported.\n");
126 panic("If this is a 64-bit machine, please try a 64-bit kernel.\n");
130 #define PDC_PAGE_ADJ_SHIFT (PAGE_SHIFT - 12) /* pdc pages are always 4k */
133 set_pmem_entry(physmem_range_t
*pmem_ptr
, unsigned long start
,
134 unsigned long pages4k
)
136 /* Rather than aligning and potentially throwing away
137 * memory, we'll assume that any ranges are already
138 * nicely aligned with any reasonable page size, and
139 * panic if they are not (it's more likely that the
140 * pdc info is bad in this case).
143 if (unlikely( ((start
& (PAGE_SIZE
- 1)) != 0)
144 || ((pages4k
& ((1UL << PDC_PAGE_ADJ_SHIFT
) - 1)) != 0) )) {
146 panic("Memory range doesn't align with page size!\n");
149 pmem_ptr
->start_pfn
= (start
>> PAGE_SHIFT
);
150 pmem_ptr
->pages
= (pages4k
>> PDC_PAGE_ADJ_SHIFT
);
153 static void __init
pagezero_memconfig(void)
155 unsigned long npages
;
157 /* Use the 32 bit information from page zero to create a single
158 * entry in the pmem_ranges[] table.
160 * We currently don't support machines with contiguous memory
161 * >= 4 Gb, who report that memory using 64 bit only fields
162 * on page zero. It's not worth doing until it can be tested,
163 * and it is not clear we can support those machines for other
166 * If that support is done in the future, this is where it
170 npages
= (PAGE_ALIGN(PAGE0
->imm_max_mem
) >> PAGE_SHIFT
);
171 set_pmem_entry(pmem_ranges
,0UL,npages
);
177 /* All of the PDC PAT specific code is 64-bit only */
180 ** The module object is filled via PDC_PAT_CELL[Return Cell Module].
181 ** If a module is found, register module will get the IODC bytes via
182 ** pdc_iodc_read() using the PA view of conf_base_addr for the hpa parameter.
184 ** The IO view can be used by PDC_PAT_CELL[Return Cell Module]
185 ** only for SBAs and LBAs. This view will cause an invalid
186 ** argument error for all other cell module types.
191 pat_query_module(ulong pcell_loc
, ulong mod_index
)
193 pdc_pat_cell_mod_maddr_block_t
*pa_pdc_cell
;
194 unsigned long bytecnt
;
195 unsigned long temp
; /* 64-bit scratch value */
196 long status
; /* PDC return value status */
197 struct parisc_device
*dev
;
199 pa_pdc_cell
= kmalloc(sizeof (*pa_pdc_cell
), GFP_KERNEL
);
201 panic("couldn't allocate memory for PDC_PAT_CELL!");
203 /* return cell module (PA or Processor view) */
204 status
= pdc_pat_cell_module(&bytecnt
, pcell_loc
, mod_index
,
205 PA_VIEW
, pa_pdc_cell
);
207 if (status
!= PDC_OK
) {
208 /* no more cell modules or error */
213 temp
= pa_pdc_cell
->cba
;
214 dev
= alloc_pa_dev(PAT_GET_CBA(temp
), &(pa_pdc_cell
->mod_path
));
220 /* alloc_pa_dev sets dev->hpa */
223 ** save parameters in the parisc_device
224 ** (The idea being the device driver will call pdc_pat_cell_module()
225 ** and store the results in its own data structure.)
227 dev
->pcell_loc
= pcell_loc
;
228 dev
->mod_index
= mod_index
;
230 /* save generic info returned from the call */
231 /* REVISIT: who is the consumer of this? not sure yet... */
232 dev
->mod_info
= pa_pdc_cell
->mod_info
; /* pass to PAT_GET_ENTITY() */
233 dev
->pmod_loc
= pa_pdc_cell
->mod_location
;
234 dev
->mod0
= pa_pdc_cell
->mod
[0];
236 register_parisc_device(dev
); /* advertise device */
239 /* dump what we see so far... */
240 switch (PAT_GET_ENTITY(dev
->mod_info
)) {
241 pdc_pat_cell_mod_maddr_block_t io_pdc_cell
;
244 case PAT_ENTITY_PROC
:
245 printk(KERN_DEBUG
"PAT_ENTITY_PROC: id_eid 0x%lx\n",
246 pa_pdc_cell
->mod
[0]);
251 "PAT_ENTITY_MEM: amount 0x%lx min_gni_base 0x%lx min_gni_len 0x%lx\n",
252 pa_pdc_cell
->mod
[0], pa_pdc_cell
->mod
[1],
253 pa_pdc_cell
->mod
[2]);
256 printk(KERN_DEBUG
"PAT_ENTITY_CA: %ld\n", pcell_loc
);
260 printk(KERN_DEBUG
"PAT_ENTITY_PBC: ");
264 printk(KERN_DEBUG
"PAT_ENTITY_SBA: ");
268 printk(KERN_DEBUG
"PAT_ENTITY_LBA: ");
271 pdc_pat_cell_module(&bytecnt
, pcell_loc
, mod_index
,
272 IO_VIEW
, &io_pdc_cell
);
273 printk(KERN_DEBUG
"ranges %ld\n", pa_pdc_cell
->mod
[1]);
274 for (i
= 0; i
< pa_pdc_cell
->mod
[1]; i
++) {
276 " PA_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n",
277 i
, pa_pdc_cell
->mod
[2 + i
* 3], /* type */
278 pa_pdc_cell
->mod
[3 + i
* 3], /* start */
279 pa_pdc_cell
->mod
[4 + i
* 3]); /* finish (ie end) */
281 " IO_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n",
282 i
, io_pdc_cell
.mod
[2 + i
* 3], /* type */
283 io_pdc_cell
.mod
[3 + i
* 3], /* start */
284 io_pdc_cell
.mod
[4 + i
* 3]); /* finish (ie end) */
286 printk(KERN_DEBUG
"\n");
289 #endif /* DEBUG_PAT */
297 /* pat pdc can return information about a variety of different
298 * types of memory (e.g. firmware,i/o, etc) but we only care about
299 * the usable physical ram right now. Since the firmware specific
300 * information is allocated on the stack, we'll be generous, in
301 * case there is a lot of other information we don't care about.
304 #define PAT_MAX_RANGES (4 * MAX_PHYSMEM_RANGES)
306 static void __init
pat_memconfig(void)
308 unsigned long actual_len
;
309 struct pdc_pat_pd_addr_map_entry mem_table
[PAT_MAX_RANGES
+1];
310 struct pdc_pat_pd_addr_map_entry
*mtbl_ptr
;
311 physmem_range_t
*pmem_ptr
;
314 unsigned long length
;
317 length
= (PAT_MAX_RANGES
+ 1) * sizeof(struct pdc_pat_pd_addr_map_entry
);
319 status
= pdc_pat_pd_get_addr_map(&actual_len
, mem_table
, length
, 0L);
321 if ((status
!= PDC_OK
)
322 || ((actual_len
% sizeof(struct pdc_pat_pd_addr_map_entry
)) != 0)) {
324 /* The above pdc call shouldn't fail, but, just in
325 * case, just use the PAGE0 info.
329 printk(KERN_WARNING
"WARNING! Could not get full memory configuration. "
330 "All memory may not be used!\n\n\n");
331 pagezero_memconfig();
335 entries
= actual_len
/ sizeof(struct pdc_pat_pd_addr_map_entry
);
337 if (entries
> PAT_MAX_RANGES
) {
338 printk(KERN_WARNING
"This Machine has more memory ranges than we support!\n");
339 printk(KERN_WARNING
"Some memory may not be used!\n");
342 /* Copy information into the firmware independent pmem_ranges
343 * array, skipping types we don't care about. Notice we said
344 * "may" above. We'll use all the entries that were returned.
348 mtbl_ptr
= mem_table
;
349 pmem_ptr
= pmem_ranges
; /* Global firmware independent table */
350 for (i
= 0; i
< entries
; i
++,mtbl_ptr
++) {
351 if ( (mtbl_ptr
->entry_type
!= PAT_MEMORY_DESCRIPTOR
)
352 || (mtbl_ptr
->memory_type
!= PAT_MEMTYPE_MEMORY
)
353 || (mtbl_ptr
->pages
== 0)
354 || ( (mtbl_ptr
->memory_usage
!= PAT_MEMUSE_GENERAL
)
355 && (mtbl_ptr
->memory_usage
!= PAT_MEMUSE_GI
)
356 && (mtbl_ptr
->memory_usage
!= PAT_MEMUSE_GNI
) ) ) {
361 if (npmem_ranges
== MAX_PHYSMEM_RANGES
) {
362 printk(KERN_WARNING
"This Machine has more memory ranges than we support!\n");
363 printk(KERN_WARNING
"Some memory will not be used!\n");
367 set_pmem_entry(pmem_ptr
++,mtbl_ptr
->paddr
,mtbl_ptr
->pages
);
372 static int __init
pat_inventory(void)
376 struct pdc_pat_cell_num cell_info
;
379 ** Note: Prelude (and it's successors: Lclass, A400/500) only
380 ** implement PDC_PAT_CELL sub-options 0 and 2.
382 status
= pdc_pat_cell_get_number(&cell_info
);
383 if (status
!= PDC_OK
) {
388 printk(KERN_DEBUG
"CELL_GET_NUMBER: 0x%lx 0x%lx\n", cell_info
.cell_num
,
392 while (PDC_OK
== pat_query_module(cell_info
.cell_loc
, mod_index
)) {
399 /* We only look for extended memory ranges on a 64 bit capable box */
400 static void __init
sprockets_memconfig(void)
402 struct pdc_memory_table_raddr r_addr
;
403 struct pdc_memory_table mem_table
[MAX_PHYSMEM_RANGES
];
404 struct pdc_memory_table
*mtbl_ptr
;
405 physmem_range_t
*pmem_ptr
;
410 status
= pdc_mem_mem_table(&r_addr
,mem_table
,
411 (unsigned long)MAX_PHYSMEM_RANGES
);
413 if (status
!= PDC_OK
) {
415 /* The above pdc call only works on boxes with sprockets
416 * firmware (newer B,C,J class). Other non PAT PDC machines
417 * do support more than 3.75 Gb of memory, but we don't
421 pagezero_memconfig();
425 if (r_addr
.entries_total
> MAX_PHYSMEM_RANGES
) {
426 printk(KERN_WARNING
"This Machine has more memory ranges than we support!\n");
427 printk(KERN_WARNING
"Some memory will not be used!\n");
430 entries
= (int)r_addr
.entries_returned
;
433 mtbl_ptr
= mem_table
;
434 pmem_ptr
= pmem_ranges
; /* Global firmware independent table */
435 for (i
= 0; i
< entries
; i
++,mtbl_ptr
++) {
436 set_pmem_entry(pmem_ptr
++,mtbl_ptr
->paddr
,mtbl_ptr
->pages
);
441 #else /* !CONFIG_64BIT */
443 #define pat_inventory() do { } while (0)
444 #define pat_memconfig() do { } while (0)
445 #define sprockets_memconfig() pagezero_memconfig()
447 #endif /* !CONFIG_64BIT */
452 /* Code to support Snake machines (7[2350], 7[235]5, 715/Scorpio) */
454 static struct parisc_device
* __init
455 legacy_create_device(struct pdc_memory_map
*r_addr
,
456 struct pdc_module_path
*module_path
)
458 struct parisc_device
*dev
;
459 int status
= pdc_mem_map_hpa(r_addr
, module_path
);
460 if (status
!= PDC_OK
)
463 dev
= alloc_pa_dev(r_addr
->hpa
, &module_path
->path
);
467 register_parisc_device(dev
);
474 * Before PDC_SYSTEM_MAP was invented, the PDC_MEM_MAP call was used.
475 * To use it, we initialise the mod_path.bc to 0xff and try all values of
476 * mod to get the HPA for the top-level devices. Bus adapters may have
477 * sub-devices which are discovered by setting bc[5] to 0 and bc[4] to the
478 * module, then trying all possible functions.
480 static void __init
snake_inventory(void)
483 for (mod
= 0; mod
< 16; mod
++) {
484 struct parisc_device
*dev
;
485 struct pdc_module_path module_path
;
486 struct pdc_memory_map r_addr
;
489 memset(module_path
.path
.bc
, 0xff, 6);
490 module_path
.path
.mod
= mod
;
491 dev
= legacy_create_device(&r_addr
, &module_path
);
492 if ((!dev
) || (dev
->id
.hw_type
!= HPHW_BA
))
495 memset(module_path
.path
.bc
, 0xff, 4);
496 module_path
.path
.bc
[4] = mod
;
498 for (func
= 0; func
< 16; func
++) {
499 module_path
.path
.bc
[5] = 0;
500 module_path
.path
.mod
= func
;
501 legacy_create_device(&r_addr
, &module_path
);
506 #else /* CONFIG_PA20 */
507 #define snake_inventory() do { } while (0)
508 #endif /* CONFIG_PA20 */
510 /* Common 32/64 bit based code goes here */
513 * add_system_map_addresses - Add additional addresses to the parisc device.
514 * @dev: The parisc device.
515 * @num_addrs: Then number of addresses to add;
516 * @module_instance: The system_map module instance.
518 * This function adds any additional addresses reported by the system_map
519 * firmware to the parisc device.
522 add_system_map_addresses(struct parisc_device
*dev
, int num_addrs
,
527 struct pdc_system_map_addr_info addr_result
;
529 dev
->addr
= kmalloc_array(num_addrs
, sizeof(*dev
->addr
), GFP_KERNEL
);
531 printk(KERN_ERR
"%s %s(): memory allocation failure\n",
536 for(i
= 1; i
<= num_addrs
; ++i
) {
537 status
= pdc_system_map_find_addrs(&addr_result
,
539 if(PDC_OK
== status
) {
540 dev
->addr
[dev
->num_addrs
] = (unsigned long)addr_result
.mod_addr
;
544 "Bad PDC_FIND_ADDRESS status return (%ld) for index %d\n",
551 * system_map_inventory - Retrieve firmware devices via SYSTEM_MAP.
553 * This function attempts to retrieve and register all the devices firmware
554 * knows about via the SYSTEM_MAP PDC call.
556 static void __init
system_map_inventory(void)
559 long status
= PDC_OK
;
561 for (i
= 0; i
< 256; i
++) {
562 struct parisc_device
*dev
;
563 struct pdc_system_map_mod_info module_result
;
564 struct pdc_module_path module_path
;
566 status
= pdc_system_map_find_mods(&module_result
,
568 if ((status
== PDC_BAD_PROC
) || (status
== PDC_NE_MOD
))
570 if (status
!= PDC_OK
)
573 dev
= alloc_pa_dev(module_result
.mod_addr
, &module_path
.path
);
577 register_parisc_device(dev
);
579 /* if available, get the additional addresses for a module */
580 if (!module_result
.add_addrs
)
583 add_system_map_addresses(dev
, module_result
.add_addrs
, i
);
590 void __init
do_memory_inventory(void)
598 case PDC_TYPE_SYSTEM_MAP
:
599 sprockets_memconfig();
603 pagezero_memconfig();
607 panic("Unknown PDC type!\n");
610 if (npmem_ranges
== 0 || pmem_ranges
[0].start_pfn
!= 0) {
611 printk(KERN_WARNING
"Bad memory configuration returned!\n");
612 printk(KERN_WARNING
"Some memory may not be used!\n");
613 pagezero_memconfig();
617 void __init
do_device_inventory(void)
619 printk(KERN_INFO
"Searching for devices...\n");
629 case PDC_TYPE_SYSTEM_MAP
:
630 system_map_inventory();
638 panic("Unknown PDC type!\n");
640 printk(KERN_INFO
"Found devices:\n");
641 print_parisc_devices();
643 #if defined(CONFIG_64BIT) && defined(CONFIG_SMP)
644 pa_serialize_tlb_flushes
= machine_has_merced_bus();
645 if (pa_serialize_tlb_flushes
)
646 pr_info("Merced bus found: Enable PxTLB serialization.\n");