2 * arch/parisc/kernel/firmware.c - safe PDC access routines
4 * PDC == Processor Dependent Code
6 * See http://www.parisc-linux.org/documentation/index.html
7 * for documentation describing the entry points and calling
8 * conventions defined below.
10 * Copyright 1999 SuSE GmbH Nuernberg (Philipp Rumpf, prumpf@tux.org)
11 * Copyright 1999 The Puffin Group, (Alex deVries, David Kennedy)
12 * Copyright 2003 Grant Grundler <grundler parisc-linux org>
13 * Copyright 2003,2004 Ryan Bradetich <rbrad@parisc-linux.org>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
22 /* I think it would be in everyone's best interest to follow this
23 * guidelines when writing PDC wrappers:
25 * - the name of the pdc wrapper should match one of the macros
26 * used for the first two arguments
27 * - don't use caps for random parts of the name
28 * - use the static PDC result buffers and "copyout" to structs
29 * supplied by the caller to encapsulate alignment restrictions
30 * - hold pdc_lock while in PDC or using static result buffers
31 * - use __pa() to convert virtual (kernel) pointers to physical
33 * - the name of the struct used for pdc return values should equal
34 * one of the macros used for the first two arguments to the
35 * corresponding PDC call
36 * - keep the order of arguments
37 * - don't be smart (setting trailing NUL bytes for strings, return
38 * something useful even if the call failed) unless you are sure
39 * it's not going to affect functionality or performance
42 * int pdc_cache_info(struct pdc_cache_info *cache_info )
46 * spin_lock_irq(&pdc_lock);
47 * retval = mem_pdc_call(PDC_CACHE,PDC_CACHE_INFO,__pa(cache_info),0);
48 * convert_to_wide(pdc_result);
49 * memcpy(cache_info, pdc_result, sizeof(*cache_info));
50 * spin_unlock_irq(&pdc_lock);
59 #include <linux/delay.h>
60 #include <linux/init.h>
61 #include <linux/kernel.h>
62 #include <linux/module.h>
63 #include <linux/string.h>
64 #include <linux/spinlock.h>
68 #include <asm/pdcpat.h>
69 #include <asm/system.h>
70 #include <asm/processor.h> /* for boot_cpu_data */
72 static spinlock_t pdc_lock = SPIN_LOCK_UNLOCKED;
73 static unsigned long pdc_result[32] __attribute__ ((aligned (8)));
74 static unsigned long pdc_result2[32] __attribute__ ((aligned (8)));
77 #define WIDE_FIRMWARE 0x1
78 #define NARROW_FIRMWARE 0x2
80 /* Firmware needs to be initially set to narrow to determine the
81 * actual firmware width. */
82 int parisc_narrow_firmware = 1;
85 /* on all currently-supported platforms, IODC I/O calls are always
86 * 32-bit calls, and MEM_PDC calls are always the same width as the OS.
87 * This means Cxxx boxes can't run wide kernels right now. -PB
89 * CONFIG_PDC_NARROW has been added to allow 64-bit kernels to run on
90 * systems with 32-bit MEM_PDC calls. This will allow wide kernels to
91 * run on Cxxx boxes now. -RB
93 * Note that some PAT boxes may have 64-bit IODC I/O...
97 long real64_call(unsigned long function, ...);
99 long real32_call(unsigned long function, ...);
102 # define MEM_PDC (unsigned long)(PAGE0->mem_pdc_hi) << 32 | PAGE0->mem_pdc
103 # define mem_pdc_call(args...) unlikely(parisc_narrow_firmware) ? real32_call(MEM_PDC, args) : real64_call(MEM_PDC, args)
105 # define MEM_PDC (unsigned long)PAGE0->mem_pdc
106 # define mem_pdc_call(args...) real32_call(MEM_PDC, args)
111 * f_extend - Convert PDC addresses to kernel addresses.
112 * @address: Address returned from PDC.
114 * This function is used to convert PDC addresses into kernel addresses
115 * when the PDC address size and kernel address size are different.
117 static unsigned long f_extend(unsigned long address)
120 if(unlikely(parisc_narrow_firmware)) {
121 if((address & 0xff000000) == 0xf0000000)
122 return 0xf0f0f0f000000000 | (u32)address;
124 if((address & 0xf0000000) == 0xf0000000)
125 return 0xffffffff00000000 | (u32)address;
132 * convert_to_wide - Convert the return buffer addresses into kernel addresses.
133 * @address: The return buffer from PDC.
135 * This function is used to convert the return buffer addresses retrieved from PDC
136 * into kernel addresses when the PDC address size and kernel address size are
139 static void convert_to_wide(unsigned long *addr)
143 unsigned int *p = (unsigned int *)addr;
145 if(unlikely(parisc_narrow_firmware)) {
146 for(i = 31; i >= 0; --i)
153 * set_firmware_width - Determine if the firmware is wide or narrow.
155 * This function must be called before any pdc_* function that uses the convert_to_wide
158 void __init set_firmware_width(void)
163 spin_lock_irq(&pdc_lock);
164 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES, __pa(pdc_result), 0);
165 convert_to_wide(pdc_result);
166 if(pdc_result[0] != NARROW_FIRMWARE)
167 parisc_narrow_firmware = 0;
168 spin_unlock_irq(&pdc_lock);
173 * pdc_emergency_unlock - Unlock the linux pdc lock
175 * This call unlocks the linux pdc lock in case we need some PDC functions
176 * (like pdc_add_valid) during kernel stack dump.
178 void pdc_emergency_unlock(void)
180 /* Spinlock DEBUG code freaks out if we unconditionally unlock */
181 if (spin_is_locked(&pdc_lock))
182 spin_unlock(&pdc_lock);
187 * pdc_add_valid - Verify address can be accessed without causing a HPMC.
188 * @address: Address to be verified.
190 * This PDC call attempts to read from the specified address and verifies
191 * if the address is valid.
193 * The return value is PDC_OK (0) in case accessing this address is valid.
195 int pdc_add_valid(unsigned long address)
199 spin_lock_irq(&pdc_lock);
200 retval = mem_pdc_call(PDC_ADD_VALID, PDC_ADD_VALID_VERIFY, address);
201 spin_unlock_irq(&pdc_lock);
205 EXPORT_SYMBOL(pdc_add_valid);
208 * pdc_chassis_info - Return chassis information.
209 * @result: The return buffer.
210 * @chassis_info: The memory buffer address.
211 * @len: The size of the memory buffer address.
213 * An HVERSION dependent call for returning the chassis information.
215 int __init pdc_chassis_info(struct pdc_chassis_info *chassis_info, void *led_info, unsigned long len)
219 spin_lock_irq(&pdc_lock);
220 memcpy(&pdc_result, chassis_info, sizeof(*chassis_info));
221 memcpy(&pdc_result2, led_info, len);
222 retval = mem_pdc_call(PDC_CHASSIS, PDC_RETURN_CHASSIS_INFO,
223 __pa(pdc_result), __pa(pdc_result2), len);
224 memcpy(chassis_info, pdc_result, sizeof(*chassis_info));
225 memcpy(led_info, pdc_result2, len);
226 spin_unlock_irq(&pdc_lock);
232 * pdc_pat_chassis_send_log - Sends a PDC PAT CHASSIS log message.
233 * @retval: -1 on error, 0 on success. Other value are PDC errors
235 * Must be correctly formatted or expect system crash
238 int pdc_pat_chassis_send_log(unsigned long state, unsigned long data)
245 spin_lock_irq(&pdc_lock);
246 retval = mem_pdc_call(PDC_PAT_CHASSIS_LOG, PDC_PAT_CHASSIS_WRITE_LOG, __pa(&state), __pa(&data));
247 spin_unlock_irq(&pdc_lock);
254 * pdc_chassis_disp - Updates display
255 * @retval: -1 on error, 0 on success
257 * Works on old PDC only (E class, others?)
259 int pdc_chassis_disp(unsigned long disp)
263 spin_lock_irq(&pdc_lock);
264 retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_DISP, disp);
265 spin_unlock_irq(&pdc_lock);
271 * pdc_coproc_cfg - To identify coprocessors attached to the processor.
272 * @pdc_coproc_info: Return buffer address.
274 * This PDC call returns the presence and status of all the coprocessors
275 * attached to the processor.
277 int __init pdc_coproc_cfg(struct pdc_coproc_cfg *pdc_coproc_info)
281 spin_lock_irq(&pdc_lock);
282 retval = mem_pdc_call(PDC_COPROC, PDC_COPROC_CFG, __pa(pdc_result));
283 convert_to_wide(pdc_result);
284 pdc_coproc_info->ccr_functional = pdc_result[0];
285 pdc_coproc_info->ccr_present = pdc_result[1];
286 pdc_coproc_info->revision = pdc_result[17];
287 pdc_coproc_info->model = pdc_result[18];
288 spin_unlock_irq(&pdc_lock);
294 * pdc_iodc_read - Read data from the modules IODC.
295 * @actcnt: The actual number of bytes.
296 * @hpa: The HPA of the module for the iodc read.
297 * @index: The iodc entry point.
298 * @iodc_data: A buffer memory for the iodc options.
299 * @iodc_data_size: Size of the memory buffer.
301 * This PDC call reads from the IODC of the module specified by the hpa
304 int pdc_iodc_read(unsigned long *actcnt, unsigned long hpa, unsigned int index,
305 void *iodc_data, unsigned int iodc_data_size)
309 spin_lock_irq(&pdc_lock);
310 retval = mem_pdc_call(PDC_IODC, PDC_IODC_READ, __pa(pdc_result), hpa,
311 index, __pa(pdc_result2), iodc_data_size);
312 convert_to_wide(pdc_result);
313 *actcnt = pdc_result[0];
314 memcpy(iodc_data, pdc_result2, iodc_data_size);
315 spin_unlock_irq(&pdc_lock);
319 EXPORT_SYMBOL(pdc_iodc_read);
322 * pdc_system_map_find_mods - Locate unarchitected modules.
323 * @pdc_mod_info: Return buffer address.
324 * @mod_path: pointer to dev path structure.
325 * @mod_index: fixed address module index.
327 * To locate and identify modules which reside at fixed I/O addresses, which
328 * do not self-identify via architected bus walks.
330 int pdc_system_map_find_mods(struct pdc_system_map_mod_info *pdc_mod_info,
331 struct pdc_module_path *mod_path, long mod_index)
335 spin_lock_irq(&pdc_lock);
336 retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_MODULE, __pa(pdc_result),
337 __pa(pdc_result2), mod_index);
338 convert_to_wide(pdc_result);
339 memcpy(pdc_mod_info, pdc_result, sizeof(*pdc_mod_info));
340 memcpy(mod_path, pdc_result2, sizeof(*mod_path));
341 spin_unlock_irq(&pdc_lock);
343 pdc_mod_info->mod_addr = f_extend(pdc_mod_info->mod_addr);
348 * pdc_system_map_find_addrs - Retrieve additional address ranges.
349 * @pdc_addr_info: Return buffer address.
350 * @mod_index: Fixed address module index.
351 * @addr_index: Address range index.
353 * Retrieve additional information about subsequent address ranges for modules
354 * with multiple address ranges.
356 int pdc_system_map_find_addrs(struct pdc_system_map_addr_info *pdc_addr_info,
357 long mod_index, long addr_index)
361 spin_lock_irq(&pdc_lock);
362 retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_ADDRESS, __pa(pdc_result),
363 mod_index, addr_index);
364 convert_to_wide(pdc_result);
365 memcpy(pdc_addr_info, pdc_result, sizeof(*pdc_addr_info));
366 spin_unlock_irq(&pdc_lock);
368 pdc_addr_info->mod_addr = f_extend(pdc_addr_info->mod_addr);
373 * pdc_model_info - Return model information about the processor.
374 * @model: The return buffer.
376 * Returns the version numbers, identifiers, and capabilities from the processor module.
378 int pdc_model_info(struct pdc_model *model)
382 spin_lock_irq(&pdc_lock);
383 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_INFO, __pa(pdc_result), 0);
384 convert_to_wide(pdc_result);
385 memcpy(model, pdc_result, sizeof(*model));
386 spin_unlock_irq(&pdc_lock);
392 * pdc_model_sysmodel - Get the system model name.
393 * @name: A char array of at least 81 characters.
395 * Get system model name from PDC ROM (e.g. 9000/715 or 9000/778/B160L)
397 int pdc_model_sysmodel(char *name)
401 spin_lock_irq(&pdc_lock);
402 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_SYSMODEL, __pa(pdc_result),
403 OS_ID_HPUX, __pa(name));
404 convert_to_wide(pdc_result);
406 if (retval == PDC_OK) {
407 name[pdc_result[0]] = '\0'; /* add trailing '\0' */
411 spin_unlock_irq(&pdc_lock);
417 * pdc_model_versions - Identify the version number of each processor.
418 * @cpu_id: The return buffer.
419 * @id: The id of the processor to check.
421 * Returns the version number for each processor component.
423 * This comment was here before, but I do not know what it means :( -RB
424 * id: 0 = cpu revision, 1 = boot-rom-version
426 int pdc_model_versions(unsigned long *versions, int id)
430 spin_lock_irq(&pdc_lock);
431 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_VERSIONS, __pa(pdc_result), id);
432 convert_to_wide(pdc_result);
433 *versions = pdc_result[0];
434 spin_unlock_irq(&pdc_lock);
440 * pdc_model_cpuid - Returns the CPU_ID.
441 * @cpu_id: The return buffer.
443 * Returns the CPU_ID value which uniquely identifies the cpu portion of
444 * the processor module.
446 int pdc_model_cpuid(unsigned long *cpu_id)
450 spin_lock_irq(&pdc_lock);
451 pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
452 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CPU_ID, __pa(pdc_result), 0);
453 convert_to_wide(pdc_result);
454 *cpu_id = pdc_result[0];
455 spin_unlock_irq(&pdc_lock);
461 * pdc_model_capabilities - Returns the platform capabilities.
462 * @capabilities: The return buffer.
464 * Returns information about platform support for 32- and/or 64-bit
465 * OSes, IO-PDIR coherency, and virtual aliasing.
467 int pdc_model_capabilities(unsigned long *capabilities)
471 spin_lock_irq(&pdc_lock);
472 pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
473 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES, __pa(pdc_result), 0);
474 convert_to_wide(pdc_result);
475 *capabilities = pdc_result[0];
476 spin_unlock_irq(&pdc_lock);
482 * pdc_cache_info - Return cache and TLB information.
483 * @cache_info: The return buffer.
485 * Returns information about the processor's cache and TLB.
487 int pdc_cache_info(struct pdc_cache_info *cache_info)
491 spin_lock_irq(&pdc_lock);
492 retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_INFO, __pa(pdc_result), 0);
493 convert_to_wide(pdc_result);
494 memcpy(cache_info, pdc_result, sizeof(*cache_info));
495 spin_unlock_irq(&pdc_lock);
502 * pdc_btlb_info - Return block TLB information.
503 * @btlb: The return buffer.
505 * Returns information about the hardware Block TLB.
507 int pdc_btlb_info(struct pdc_btlb_info *btlb)
511 spin_lock_irq(&pdc_lock);
512 retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_INFO, __pa(pdc_result), 0);
513 memcpy(btlb, pdc_result, sizeof(*btlb));
514 spin_unlock_irq(&pdc_lock);
523 * pdc_mem_map_hpa - Find fixed module information.
524 * @address: The return buffer
525 * @mod_path: pointer to dev path structure.
527 * This call was developed for S700 workstations to allow the kernel to find
528 * the I/O devices (Core I/O). In the future (Kittyhawk and beyond) this
529 * call will be replaced (on workstations) by the architected PDC_SYSTEM_MAP
532 * This call is supported by all existing S700 workstations (up to Gecko).
534 int pdc_mem_map_hpa(struct pdc_memory_map *address,
535 struct pdc_module_path *mod_path)
539 spin_lock_irq(&pdc_lock);
540 memcpy(pdc_result2, mod_path, sizeof(*mod_path));
541 retval = mem_pdc_call(PDC_MEM_MAP, PDC_MEM_MAP_HPA, __pa(pdc_result),
543 memcpy(address, pdc_result, sizeof(*address));
544 spin_unlock_irq(&pdc_lock);
548 #endif /* !CONFIG_PA20 */
551 * pdc_lan_station_id - Get the LAN address.
552 * @lan_addr: The return buffer.
553 * @hpa: The network device HPA.
555 * Get the LAN station address when it is not directly available from the LAN hardware.
557 int pdc_lan_station_id(char *lan_addr, unsigned long hpa)
561 spin_lock_irq(&pdc_lock);
562 retval = mem_pdc_call(PDC_LAN_STATION_ID, PDC_LAN_STATION_ID_READ,
563 __pa(pdc_result), hpa);
565 /* FIXME: else read MAC from NVRAM */
566 memset(lan_addr, 0, PDC_LAN_STATION_ID_SIZE);
568 memcpy(lan_addr, pdc_result, PDC_LAN_STATION_ID_SIZE);
570 spin_unlock_irq(&pdc_lock);
574 EXPORT_SYMBOL(pdc_lan_station_id);
578 * pdc_get_initiator - Get the SCSI Interface Card params (SCSI ID, SDTR, SE or LVD)
579 * @hwpath: fully bc.mod style path to the device.
580 * @scsi_id: what someone told firmware the ID should be.
581 * @period: time in cycles
582 * @width: 8 or 16-bit wide bus
583 * @mode: 0,1,2 -> SE,HVD,LVD signalling mode
585 * Get the SCSI operational parameters from PDC.
586 * Needed since HPUX never used BIOS or symbios card NVRAM.
587 * Most ncr/sym cards won't have an entry and just use whatever
588 * capabilities of the card are (eg Ultra, LVD). But there are
589 * several cases where it's useful:
590 * o set SCSI id for Multi-initiator clusters,
591 * o cable too long (ie SE scsi 10Mhz won't support 6m length),
592 * o bus width exported is less than what the interface chip supports.
594 int pdc_get_initiator(struct hardware_path *hwpath, unsigned char *scsi_id,
595 unsigned long *period, char *width, char *mode)
599 spin_lock_irq(&pdc_lock);
601 /* BCJ-XXXX series boxes. E.G. "9000/785/C3000" */
602 #define IS_SPROCKETS() (strlen(boot_cpu_data.pdc.sys_model_name) == 14 && \
603 strncmp(boot_cpu_data.pdc.sys_model_name, "9000/785", 8) == 0)
605 retval = mem_pdc_call(PDC_INITIATOR, PDC_GET_INITIATOR,
606 __pa(pdc_result), __pa(hwpath));
611 *scsi_id = (unsigned char) pdc_result[0];
613 /* convert Bus speed in Mhz to period (in 1/10 ns) */
614 switch (pdc_result[1]) {
616 * case 0: driver determines rate
617 * case -1: Settings are uninitialized.
619 case 5: *period = 2000; break;
620 case 10: *period = 1000; break;
621 case 20: *period = 500; break;
622 case 40: *period = 250; break;
623 case 80: *period = 125; break;
624 default: /* Do nothing */ break;
628 * pdc_result[2] PDC suggested SCSI id
629 * pdc_result[3] PDC suggested SCSI rate
632 if (IS_SPROCKETS()) {
633 /* 0 == 8-bit, 1 == 16-bit */
634 *width = (char) pdc_result[4];
636 /* ...in case someone needs it in the future.
637 * sym53c8xx.c comments say it can't autodetect
638 * for 825/825A/875 chips.
639 * 0 == SE, 1 == HVD, 2 == LVD
641 *mode = (char) pdc_result[5];
645 spin_unlock_irq(&pdc_lock);
646 return (retval >= PDC_OK);
648 EXPORT_SYMBOL(pdc_get_initiator);
652 * pdc_pci_irt_size - Get the number of entries in the interrupt routing table.
653 * @num_entries: The return value.
654 * @hpa: The HPA for the device.
656 * This PDC function returns the number of entries in the specified cell's
658 * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
660 int pdc_pci_irt_size(unsigned long *num_entries, unsigned long hpa)
664 spin_lock_irq(&pdc_lock);
665 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL_SIZE,
666 __pa(pdc_result), hpa);
667 convert_to_wide(pdc_result);
668 *num_entries = pdc_result[0];
669 spin_unlock_irq(&pdc_lock);
675 * pdc_pci_irt - Get the PCI interrupt routing table.
676 * @num_entries: The number of entries in the table.
677 * @hpa: The Hard Physical Address of the device.
680 * Get the PCI interrupt routing table for the device at the given HPA.
681 * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
683 int pdc_pci_irt(unsigned long num_entries, unsigned long hpa, void *tbl)
687 spin_lock_irq(&pdc_lock);
688 pdc_result[0] = num_entries;
689 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL,
690 __pa(pdc_result), hpa, __pa(tbl));
691 spin_unlock_irq(&pdc_lock);
697 #if 0 /* UNTEST CODE - left here in case someone needs it */
700 * pdc_pci_config_read - read PCI config space.
701 * @hpa token from PDC to indicate which PCI device
702 * @pci_addr configuration space address to read from
704 * Read PCI Configuration space *before* linux PCI subsystem is running.
706 unsigned int pdc_pci_config_read(void *hpa, unsigned long cfg_addr)
709 spin_lock_irq(&pdc_lock);
712 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_READ_CONFIG,
713 __pa(pdc_result), hpa, cfg_addr&~3UL, 4UL);
714 spin_unlock_irq(&pdc_lock);
715 return retval ? ~0 : (unsigned int) pdc_result[0];
720 * pdc_pci_config_write - read PCI config space.
721 * @hpa token from PDC to indicate which PCI device
722 * @pci_addr configuration space address to write
723 * @val value we want in the 32-bit register
725 * Write PCI Configuration space *before* linux PCI subsystem is running.
727 void pdc_pci_config_write(void *hpa, unsigned long cfg_addr, unsigned int val)
730 spin_lock_irq(&pdc_lock);
732 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_WRITE_CONFIG,
733 __pa(pdc_result), hpa,
734 cfg_addr&~3UL, 4UL, (unsigned long) val);
735 spin_unlock_irq(&pdc_lock);
738 #endif /* UNTESTED CODE */
741 * pdc_tod_read - Read the Time-Of-Day clock.
742 * @tod: The return buffer:
744 * Read the Time-Of-Day clock
746 int pdc_tod_read(struct pdc_tod *tod)
750 spin_lock_irq(&pdc_lock);
751 retval = mem_pdc_call(PDC_TOD, PDC_TOD_READ, __pa(pdc_result), 0);
752 convert_to_wide(pdc_result);
753 memcpy(tod, pdc_result, sizeof(*tod));
754 spin_unlock_irq(&pdc_lock);
758 EXPORT_SYMBOL(pdc_tod_read);
761 * pdc_tod_set - Set the Time-Of-Day clock.
762 * @sec: The number of seconds since epoch.
763 * @usec: The number of micro seconds.
765 * Set the Time-Of-Day clock.
767 int pdc_tod_set(unsigned long sec, unsigned long usec)
771 spin_lock_irq(&pdc_lock);
772 retval = mem_pdc_call(PDC_TOD, PDC_TOD_WRITE, sec, usec);
773 spin_unlock_irq(&pdc_lock);
777 EXPORT_SYMBOL(pdc_tod_set);
780 int pdc_mem_mem_table(struct pdc_memory_table_raddr *r_addr,
781 struct pdc_memory_table *tbl, unsigned long entries)
785 spin_lock_irq(&pdc_lock);
786 retval = mem_pdc_call(PDC_MEM, PDC_MEM_TABLE, __pa(pdc_result), __pa(pdc_result2), entries);
787 convert_to_wide(pdc_result);
788 memcpy(r_addr, pdc_result, sizeof(*r_addr));
789 memcpy(tbl, pdc_result2, entries * sizeof(*tbl));
790 spin_unlock_irq(&pdc_lock);
794 #endif /* __LP64__ */
796 /* FIXME: Is this pdc used? I could not find type reference to ftc_bitmap
797 * so I guessed at unsigned long. Someone who knows what this does, can fix
800 int pdc_do_firm_test_reset(unsigned long ftc_bitmap)
804 spin_lock_irq(&pdc_lock);
805 retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_FIRM_TEST_RESET,
806 PDC_FIRM_TEST_MAGIC, ftc_bitmap);
807 spin_unlock_irq(&pdc_lock);
813 * pdc_do_reset - Reset the system.
821 spin_lock_irq(&pdc_lock);
822 retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_RESET);
823 spin_unlock_irq(&pdc_lock);
829 * pdc_soft_power_info - Enable soft power switch.
830 * @power_reg: address of soft power register
832 * Return the absolute address of the soft power switch register
834 int __init pdc_soft_power_info(unsigned long *power_reg)
838 *power_reg = (unsigned long) (-1);
840 spin_lock_irq(&pdc_lock);
841 retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_INFO, __pa(pdc_result), 0);
842 if (retval == PDC_OK) {
843 convert_to_wide(pdc_result);
844 *power_reg = f_extend(pdc_result[0]);
846 spin_unlock_irq(&pdc_lock);
852 * pdc_soft_power_button - Control the soft power button behaviour
853 * @sw_control: 0 for hardware control, 1 for software control
856 * This PDC function places the soft power button under software or
858 * Under software control the OS may control to when to allow to shut
859 * down the system. Under hardware control pressing the power button
860 * powers off the system immediately.
862 int pdc_soft_power_button(int sw_control)
865 spin_lock_irq(&pdc_lock);
866 retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
867 spin_unlock_irq(&pdc_lock);
872 * pdc_io_reset - Hack to avoid overlapping range registers of Bridges devices.
873 * Primarily a problem on T600 (which parisc-linux doesn't support) but
874 * who knows what other platform firmware might do with this OS "hook".
876 void pdc_io_reset(void)
878 spin_lock_irq(&pdc_lock);
879 mem_pdc_call(PDC_IO, PDC_IO_RESET, 0);
880 spin_unlock_irq(&pdc_lock);
884 * pdc_io_reset_devices - Hack to Stop USB controller
886 * If PDC used the usb controller, the usb controller
887 * is still running and will crash the machines during iommu
888 * setup, because of still running DMA. This PDC call
889 * stops the USB controller.
890 * Normally called after calling pdc_io_reset().
892 void pdc_io_reset_devices(void)
894 spin_lock_irq(&pdc_lock);
895 mem_pdc_call(PDC_IO, PDC_IO_RESET_DEVICES, 0);
896 spin_unlock_irq(&pdc_lock);
901 * pdc_iodc_putc - Console character print using IODC.
902 * @c: the character to output.
904 * Note that only these special chars are architected for console IODC io:
905 * BEL, BS, CR, and LF. Others are passed through.
906 * Since the HP console requires CR+LF to perform a 'newline', we translate
909 void pdc_iodc_putc(unsigned char c)
911 /* XXX Should we spinlock posx usage */
912 static int posx; /* for simple TAB-Simulation... */
913 static int __attribute__((aligned(8))) iodc_retbuf[32];
914 static char __attribute__((aligned(64))) iodc_dbuf[4096];
927 while (posx & 7) /* expand TAB */
929 return; /* return since IODC can't handle this */
939 spin_lock_irqsave(&pdc_lock, flags);
940 real32_call(PAGE0->mem_cons.iodc_io,
941 (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
942 PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
943 __pa(iodc_retbuf), 0, __pa(iodc_dbuf), n, 0);
944 spin_unlock_irqrestore(&pdc_lock, flags);
948 * pdc_iodc_outc - Console character print using IODC (without conversions).
949 * @c: the character to output.
951 * Write the character directly to the IODC console.
953 void pdc_iodc_outc(unsigned char c)
955 unsigned int n, flags;
957 /* fill buffer with one caracter and print it */
958 static int __attribute__((aligned(8))) iodc_retbuf[32];
959 static char __attribute__((aligned(64))) iodc_dbuf[4096];
964 spin_lock_irqsave(&pdc_lock, flags);
965 real32_call(PAGE0->mem_cons.iodc_io,
966 (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
967 PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
968 __pa(iodc_retbuf), 0, __pa(iodc_dbuf), n, 0);
969 spin_unlock_irqrestore(&pdc_lock, flags);
973 * pdc_iodc_getc - Read a character (non-blocking) from the PDC console.
975 * Read a character (non-blocking) from the PDC console, returns -1 if
976 * key is not present.
978 int pdc_iodc_getc(void)
981 static int __attribute__((aligned(8))) iodc_retbuf[32];
982 static char __attribute__((aligned(64))) iodc_dbuf[4096];
986 /* Bail if no console input device. */
987 if (!PAGE0->mem_kbd.iodc_io)
990 /* wait for a keyboard (rs232)-input */
991 spin_lock_irqsave(&pdc_lock, flags);
992 real32_call(PAGE0->mem_kbd.iodc_io,
993 (unsigned long)PAGE0->mem_kbd.hpa, ENTRY_IO_CIN,
994 PAGE0->mem_kbd.spa, __pa(PAGE0->mem_kbd.dp.layers),
995 __pa(iodc_retbuf), 0, __pa(iodc_dbuf), 1, 0);
998 status = *iodc_retbuf;
999 spin_unlock_irqrestore(&pdc_lock, flags);
1007 int pdc_sti_call(unsigned long func, unsigned long flags,
1008 unsigned long inptr, unsigned long outputr,
1009 unsigned long glob_cfg)
1013 spin_lock_irq(&pdc_lock);
1014 retval = real32_call(func, flags, inptr, outputr, glob_cfg);
1015 spin_unlock_irq(&pdc_lock);
1019 EXPORT_SYMBOL(pdc_sti_call);
1023 * pdc_pat_cell_get_number - Returns the cell number.
1024 * @cell_info: The return buffer.
1026 * This PDC call returns the cell number of the cell from which the call
1029 int pdc_pat_cell_get_number(struct pdc_pat_cell_num *cell_info)
1033 spin_lock_irq(&pdc_lock);
1034 retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_GET_NUMBER, __pa(pdc_result));
1035 memcpy(cell_info, pdc_result, sizeof(*cell_info));
1036 spin_unlock_irq(&pdc_lock);
1042 * pdc_pat_cell_module - Retrieve the cell's module information.
1043 * @actcnt: The number of bytes written to mem_addr.
1044 * @ploc: The physical location.
1045 * @mod: The module index.
1046 * @view_type: The view of the address type.
1047 * @mem_addr: The return buffer.
1049 * This PDC call returns information about each module attached to the cell
1050 * at the specified location.
1052 int pdc_pat_cell_module(unsigned long *actcnt, unsigned long ploc, unsigned long mod,
1053 unsigned long view_type, void *mem_addr)
1056 static struct pdc_pat_cell_mod_maddr_block result __attribute__ ((aligned (8)));
1058 spin_lock_irq(&pdc_lock);
1059 retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_MODULE, __pa(pdc_result),
1060 ploc, mod, view_type, __pa(&result));
1062 *actcnt = pdc_result[0];
1063 memcpy(mem_addr, &result, *actcnt);
1065 spin_unlock_irq(&pdc_lock);
1071 * pdc_pat_cpu_get_number - Retrieve the cpu number.
1072 * @cpu_info: The return buffer.
1073 * @hpa: The Hard Physical Address of the CPU.
1075 * Retrieve the cpu number for the cpu at the specified HPA.
1077 int pdc_pat_cpu_get_number(struct pdc_pat_cpu_num *cpu_info, void *hpa)
1081 spin_lock_irq(&pdc_lock);
1082 retval = mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_GET_NUMBER,
1083 __pa(&pdc_result), hpa);
1084 memcpy(cpu_info, pdc_result, sizeof(*cpu_info));
1085 spin_unlock_irq(&pdc_lock);
1091 * pdc_pat_get_irt_size - Retrieve the number of entries in the cell's interrupt table.
1092 * @num_entries: The return value.
1093 * @cell_num: The target cell.
1095 * This PDC function returns the number of entries in the specified cell's
1098 int pdc_pat_get_irt_size(unsigned long *num_entries, unsigned long cell_num)
1102 spin_lock_irq(&pdc_lock);
1103 retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE_SIZE,
1104 __pa(pdc_result), cell_num);
1105 *num_entries = pdc_result[0];
1106 spin_unlock_irq(&pdc_lock);
1112 * pdc_pat_get_irt - Retrieve the cell's interrupt table.
1113 * @r_addr: The return buffer.
1114 * @cell_num: The target cell.
1116 * This PDC function returns the actual interrupt table for the specified cell.
1118 int pdc_pat_get_irt(void *r_addr, unsigned long cell_num)
1122 spin_lock_irq(&pdc_lock);
1123 retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE,
1124 __pa(r_addr), cell_num);
1125 spin_unlock_irq(&pdc_lock);
1131 * pdc_pat_pd_get_addr_map - Retrieve information about memory address ranges.
1132 * @actlen: The return buffer.
1133 * @mem_addr: Pointer to the memory buffer.
1134 * @count: The number of bytes to read from the buffer.
1135 * @offset: The offset with respect to the beginning of the buffer.
1138 int pdc_pat_pd_get_addr_map(unsigned long *actual_len, void *mem_addr,
1139 unsigned long count, unsigned long offset)
1143 spin_lock_irq(&pdc_lock);
1144 retval = mem_pdc_call(PDC_PAT_PD, PDC_PAT_PD_GET_ADDR_MAP, __pa(pdc_result),
1145 __pa(pdc_result2), count, offset);
1146 *actual_len = pdc_result[0];
1147 memcpy(mem_addr, pdc_result2, *actual_len);
1148 spin_unlock_irq(&pdc_lock);
1154 * pdc_pat_io_pci_cfg_read - Read PCI configuration space.
1155 * @pci_addr: PCI configuration space address for which the read request is being made.
1156 * @pci_size: Size of read in bytes. Valid values are 1, 2, and 4.
1157 * @mem_addr: Pointer to return memory buffer.
1160 int pdc_pat_io_pci_cfg_read(unsigned long pci_addr, int pci_size, u32 *mem_addr)
1163 spin_lock_irq(&pdc_lock);
1164 retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_READ,
1165 __pa(pdc_result), pci_addr, pci_size);
1167 case 1: *(u8 *) mem_addr = (u8) pdc_result[0];
1168 case 2: *(u16 *)mem_addr = (u16) pdc_result[0];
1169 case 4: *(u32 *)mem_addr = (u32) pdc_result[0];
1171 spin_unlock_irq(&pdc_lock);
1177 * pdc_pat_io_pci_cfg_write - Retrieve information about memory address ranges.
1178 * @pci_addr: PCI configuration space address for which the write request is being made.
1179 * @pci_size: Size of write in bytes. Valid values are 1, 2, and 4.
1180 * @value: Pointer to 1, 2, or 4 byte value in low order end of argument to be
1181 * written to PCI Config space.
1184 int pdc_pat_io_pci_cfg_write(unsigned long pci_addr, int pci_size, u32 val)
1188 spin_lock_irq(&pdc_lock);
1189 retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_WRITE,
1190 pci_addr, pci_size, val);
1191 spin_unlock_irq(&pdc_lock);
1195 #endif /* __LP64__ */
1198 /***************** 32-bit real-mode calls ***********/
1199 /* The struct below is used
1200 * to overlay real_stack (real2.S), preparing a 32-bit call frame.
1201 * real32_call_asm() then uses this stack in narrow real mode
1204 struct narrow_stack {
1205 /* use int, not long which is 64 bits */
1220 unsigned int frame_marker[8];
1222 /* in reality, there's nearly 8k of stack after this */
1225 long real32_call(unsigned long fn, ...)
1228 extern struct narrow_stack real_stack;
1229 extern unsigned long real32_call_asm(unsigned int *,
1234 real_stack.arg0 = va_arg(args, unsigned int);
1235 real_stack.arg1 = va_arg(args, unsigned int);
1236 real_stack.arg2 = va_arg(args, unsigned int);
1237 real_stack.arg3 = va_arg(args, unsigned int);
1238 real_stack.arg4 = va_arg(args, unsigned int);
1239 real_stack.arg5 = va_arg(args, unsigned int);
1240 real_stack.arg6 = va_arg(args, unsigned int);
1241 real_stack.arg7 = va_arg(args, unsigned int);
1242 real_stack.arg8 = va_arg(args, unsigned int);
1243 real_stack.arg9 = va_arg(args, unsigned int);
1244 real_stack.arg10 = va_arg(args, unsigned int);
1245 real_stack.arg11 = va_arg(args, unsigned int);
1246 real_stack.arg12 = va_arg(args, unsigned int);
1247 real_stack.arg13 = va_arg(args, unsigned int);
1250 return real32_call_asm(&real_stack.sp, &real_stack.arg0, fn);
1254 /***************** 64-bit real-mode calls ***********/
1267 unsigned long arg10;
1268 unsigned long arg11;
1269 unsigned long arg12;
1270 unsigned long arg13;
1271 unsigned long frame_marker[2]; /* rp, previous sp */
1273 /* in reality, there's nearly 8k of stack after this */
1276 long real64_call(unsigned long fn, ...)
1279 extern struct wide_stack real64_stack __attribute__ ((alias ("real_stack")));
1280 extern unsigned long real64_call_asm(unsigned long *,
1285 real64_stack.arg0 = va_arg(args, unsigned long);
1286 real64_stack.arg1 = va_arg(args, unsigned long);
1287 real64_stack.arg2 = va_arg(args, unsigned long);
1288 real64_stack.arg3 = va_arg(args, unsigned long);
1289 real64_stack.arg4 = va_arg(args, unsigned long);
1290 real64_stack.arg5 = va_arg(args, unsigned long);
1291 real64_stack.arg6 = va_arg(args, unsigned long);
1292 real64_stack.arg7 = va_arg(args, unsigned long);
1293 real64_stack.arg8 = va_arg(args, unsigned long);
1294 real64_stack.arg9 = va_arg(args, unsigned long);
1295 real64_stack.arg10 = va_arg(args, unsigned long);
1296 real64_stack.arg11 = va_arg(args, unsigned long);
1297 real64_stack.arg12 = va_arg(args, unsigned long);
1298 real64_stack.arg13 = va_arg(args, unsigned long);
1301 return real64_call_asm(&real64_stack.sp, &real64_stack.arg0, fn);
1304 #endif /* __LP64__ */