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>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
21 /* I think it would be in everyone's best interest to follow this
22 * guidelines when writing PDC wrappers:
24 * - the name of the pdc wrapper should match one of the macros
25 * used for the first two arguments
26 * - don't use caps for random parts of the name
27 * - use the static PDC result buffers and "copyout" to structs
28 * supplied by the caller to encapsulate alignment restrictions
29 * - hold pdc_lock while in PDC or using static result buffers
30 * - use __pa() to convert virtual (kernel) pointers to physical
32 * - the name of the struct used for pdc return values should equal
33 * one of the macros used for the first two arguments to the
34 * corresponding PDC call
35 * - keep the order of arguments
36 * - don't be smart (setting trailing NUL bytes for strings, return
37 * something useful even if the call failed) unless you are sure
38 * it's not going to affect functionality or performance
41 * int pdc_cache_info(struct pdc_cache_info *cache_info )
45 * spin_lock_irq(&pdc_lock);
46 * retval = mem_pdc_call(PDC_CACHE,PDC_CACHE_INFO,__pa(cache_info),0);
47 * convert_to_wide(pdc_result);
48 * memcpy(cache_info, pdc_result, sizeof(*cache_info));
49 * spin_unlock_irq(&pdc_lock);
58 #include <linux/delay.h>
59 #include <linux/init.h>
60 #include <linux/kernel.h>
61 #include <linux/module.h>
62 #include <linux/string.h>
63 #include <linux/spinlock.h>
67 #include <asm/system.h>
68 #include <asm/processor.h> /* for boot_cpu_data */
70 static spinlock_t pdc_lock = SPIN_LOCK_UNLOCKED;
71 static unsigned long pdc_result[32] __attribute__ ((aligned (8)));
72 static unsigned long pdc_result2[32] __attribute__ ((aligned (8)));
74 /* on all currently-supported platforms, IODC I/O calls are always
75 * 32-bit calls, and MEM_PDC calls are always the same width as the OS.
76 * This means Cxxx boxes can't run wide kernels right now. -PB
78 * CONFIG_PDC_NARROW has been added to allow 64-bit kernels to run on
79 * systems with 32-bit MEM_PDC calls. This will allow wide kernels to
80 * run on Cxxx boxes now. -RB
82 * Note that some PAT boxes may have 64-bit IODC I/O...
86 long real64_call(unsigned long function, ...);
88 long real32_call(unsigned long function, ...);
90 #if defined(__LP64__) && ! defined(CONFIG_PDC_NARROW)
91 #define MEM_PDC (unsigned long)(PAGE0->mem_pdc_hi) << 32 | PAGE0->mem_pdc
92 # define mem_pdc_call(args...) real64_call(MEM_PDC, args)
94 #define MEM_PDC (unsigned long)PAGE0->mem_pdc
95 # define mem_pdc_call(args...) real32_call(MEM_PDC, args)
100 * f_extend - Convert PDC addresses to kernel addresses.
101 * @address: Address returned from PDC.
103 * This function is used to convert PDC addresses into kernel addresses
104 * when the PDC address size and kernel address size are different.
106 static unsigned long f_extend(unsigned long address)
108 #ifdef CONFIG_PDC_NARROW
109 if((address & 0xff000000) == 0xf0000000)
110 return 0xf0f0f0f000000000 | (u32)address;
112 if((address & 0xf0000000) == 0xf0000000)
113 return 0xffffffff00000000 | (u32)address;
119 * convert_to_wide - Convert the return buffer addresses into kernel addresses.
120 * @address: The return buffer from PDC.
122 * This function is used to convert the return buffer addresses retrieved from PDC
123 * into kernel addresses when the PDC address size and kernel address size are
126 static void convert_to_wide(unsigned long *addr)
128 #ifdef CONFIG_PDC_NARROW
130 unsigned *p = (unsigned int *)addr;
131 for(i = 31; i >= 0; --i)
137 * pdc_emergency_unlock - Unlock the linux pdc lock
139 * This call unlocks the linux pdc lock in case we need some PDC functions
140 * (like pdc_add_valid) during kernel stack dump.
142 void pdc_emergency_unlock(void)
144 spin_unlock(&pdc_lock);
149 * pdc_add_valid - Verify address can be accessed without causing a HPMC.
150 * @address: Address to be verified.
152 * This PDC call attempts to read from the specified address and verifies
153 * if the address is valid.
155 * The return value is PDC_OK (0) in case accessing this address is valid.
157 int pdc_add_valid(unsigned long address)
161 spin_lock_irq(&pdc_lock);
162 retval = mem_pdc_call(PDC_ADD_VALID, PDC_ADD_VALID_VERIFY, address);
163 spin_unlock_irq(&pdc_lock);
167 EXPORT_SYMBOL(pdc_add_valid);
170 * pdc_chassis_info - Return chassis information.
171 * @result: The return buffer.
172 * @chassis_info: The memory buffer address.
173 * @len: The size of the memory buffer address.
175 * An HVERSION dependent call for returning the chassis information.
177 int __init pdc_chassis_info(struct pdc_chassis_info *chassis_info, void *led_info, unsigned long len)
181 spin_lock_irq(&pdc_lock);
182 memcpy(&pdc_result, chassis_info, sizeof(*chassis_info));
183 memcpy(&pdc_result2, led_info, len);
184 retval = mem_pdc_call(PDC_CHASSIS, PDC_RETURN_CHASSIS_INFO,
185 __pa(pdc_result), __pa(pdc_result2), len);
186 memcpy(chassis_info, pdc_result, sizeof(*chassis_info));
187 memcpy(led_info, pdc_result2, len);
188 spin_unlock_irq(&pdc_lock);
194 * pdc_pat_chassis_send_log - Sends a PDC PAT CHASSIS log message.
195 * @retval: -1 on error, 0 on success. Other value are PDC errors
197 * Must be correctly formatted or expect system crash
200 int pdc_pat_chassis_send_log(unsigned long state, unsigned long data)
207 spin_lock_irq(&pdc_lock);
208 retval = mem_pdc_call(PDC_PAT_CHASSIS_LOG, PDC_PAT_CHASSIS_WRITE_LOG, __pa(&state), __pa(&data));
209 spin_unlock_irq(&pdc_lock);
216 * pdc_chassis_disp - Updates display
217 * @retval: -1 on error, 0 on success
219 * Works on old PDC only (E class, others?)
221 int pdc_chassis_disp(unsigned long disp)
225 spin_lock_irq(&pdc_lock);
226 retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_DISP, disp);
227 spin_unlock_irq(&pdc_lock);
233 * pdc_coproc_cfg - To identify coprocessors attached to the processor.
234 * @pdc_coproc_info: Return buffer address.
236 * This PDC call returns the presence and status of all the coprocessors
237 * attached to the processor.
239 int __init pdc_coproc_cfg(struct pdc_coproc_cfg *pdc_coproc_info)
243 spin_lock_irq(&pdc_lock);
244 retval = mem_pdc_call(PDC_COPROC, PDC_COPROC_CFG, __pa(pdc_result));
245 convert_to_wide(pdc_result);
246 pdc_coproc_info->ccr_functional = pdc_result[0];
247 pdc_coproc_info->ccr_present = pdc_result[1];
248 pdc_coproc_info->revision = pdc_result[17];
249 pdc_coproc_info->model = pdc_result[18];
250 spin_unlock_irq(&pdc_lock);
256 * pdc_iodc_read - Read data from the modules IODC.
257 * @actcnt: The actual number of bytes.
258 * @hpa: The HPA of the module for the iodc read.
259 * @index: The iodc entry point.
260 * @iodc_data: A buffer memory for the iodc options.
261 * @iodc_data_size: Size of the memory buffer.
263 * This PDC call reads from the IODC of the module specified by the hpa
266 int pdc_iodc_read(unsigned long *actcnt, unsigned long hpa, unsigned int index,
267 void *iodc_data, unsigned int iodc_data_size)
271 spin_lock_irq(&pdc_lock);
272 retval = mem_pdc_call(PDC_IODC, PDC_IODC_READ, __pa(pdc_result), hpa,
273 index, __pa(pdc_result2), iodc_data_size);
274 convert_to_wide(pdc_result);
275 *actcnt = pdc_result[0];
276 memcpy(iodc_data, pdc_result2, iodc_data_size);
277 spin_unlock_irq(&pdc_lock);
281 EXPORT_SYMBOL(pdc_iodc_read);
284 * pdc_system_map_find_mods - Locate unarchitected modules.
285 * @pdc_mod_info: Return buffer address.
286 * @mod_path: pointer to dev path structure.
287 * @mod_index: fixed address module index.
289 * To locate and identify modules which reside at fixed I/O addresses, which
290 * do not self-identify via architected bus walks.
292 int pdc_system_map_find_mods(struct pdc_system_map_mod_info *pdc_mod_info,
293 struct pdc_module_path *mod_path, long mod_index)
297 spin_lock_irq(&pdc_lock);
298 retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_MODULE, __pa(pdc_result),
299 __pa(pdc_result2), mod_index);
300 convert_to_wide(pdc_result);
301 memcpy(pdc_mod_info, pdc_result, sizeof(*pdc_mod_info));
302 memcpy(mod_path, pdc_result2, sizeof(*mod_path));
303 spin_unlock_irq(&pdc_lock);
305 pdc_mod_info->mod_addr = f_extend(pdc_mod_info->mod_addr);
310 * pdc_system_map_find_addrs - Retrieve additional address ranges.
311 * @pdc_addr_info: Return buffer address.
312 * @mod_index: Fixed address module index.
313 * @addr_index: Address range index.
315 * Retrieve additional information about subsequent address ranges for modules
316 * with multiple address ranges.
318 int pdc_system_map_find_addrs(struct pdc_system_map_addr_info *pdc_addr_info,
319 long mod_index, long addr_index)
323 spin_lock_irq(&pdc_lock);
324 retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_ADDRESS, __pa(pdc_result),
325 mod_index, addr_index);
326 convert_to_wide(pdc_result);
327 memcpy(pdc_addr_info, pdc_result, sizeof(*pdc_addr_info));
328 spin_unlock_irq(&pdc_lock);
330 pdc_addr_info->mod_addr = f_extend(pdc_addr_info->mod_addr);
335 * pdc_model_info - Return model information about the processor.
336 * @model: The return buffer.
338 * Returns the version numbers, identifiers, and capabilities from the processor module.
340 int pdc_model_info(struct pdc_model *model)
344 spin_lock_irq(&pdc_lock);
345 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_INFO, __pa(pdc_result), 0);
346 convert_to_wide(pdc_result);
347 memcpy(model, pdc_result, sizeof(*model));
348 spin_unlock_irq(&pdc_lock);
354 * pdc_model_sysmodel - Get the system model name.
355 * @name: A char array of at least 81 characters.
357 * Get system model name from PDC ROM (e.g. 9000/715 or 9000/778/B160L)
359 int pdc_model_sysmodel(char *name)
363 spin_lock_irq(&pdc_lock);
364 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_SYSMODEL, __pa(pdc_result),
365 OS_ID_HPUX, __pa(name));
366 convert_to_wide(pdc_result);
368 if (retval == PDC_OK) {
369 name[pdc_result[0]] = '\0'; /* add trailing '\0' */
373 spin_unlock_irq(&pdc_lock);
379 * pdc_model_versions - Identify the version number of each processor.
380 * @cpu_id: The return buffer.
381 * @id: The id of the processor to check.
383 * Returns the version number for each processor component.
385 * This comment was here before, but I do not know what it means :( -RB
386 * id: 0 = cpu revision, 1 = boot-rom-version
388 int pdc_model_versions(unsigned long *versions, int id)
392 spin_lock_irq(&pdc_lock);
393 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_VERSIONS, __pa(pdc_result), id);
394 convert_to_wide(pdc_result);
395 *versions = pdc_result[0];
396 spin_unlock_irq(&pdc_lock);
402 * pdc_model_cpuid - Returns the CPU_ID.
403 * @cpu_id: The return buffer.
405 * Returns the CPU_ID value which uniquely identifies the cpu portion of
406 * the processor module.
408 int pdc_model_cpuid(unsigned long *cpu_id)
412 spin_lock_irq(&pdc_lock);
413 pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
414 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CPU_ID, __pa(pdc_result), 0);
415 convert_to_wide(pdc_result);
416 *cpu_id = pdc_result[0];
417 spin_unlock_irq(&pdc_lock);
423 * pdc_model_capabilities - Returns the platform capabilities.
424 * @capabilities: The return buffer.
426 * Returns information about platform support for 32- and/or 64-bit
427 * OSes, IO-PDIR coherency, and virtual aliasing.
429 int pdc_model_capabilities(unsigned long *capabilities)
433 spin_lock_irq(&pdc_lock);
434 pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
435 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES, __pa(pdc_result), 0);
436 convert_to_wide(pdc_result);
437 *capabilities = pdc_result[0];
438 spin_unlock_irq(&pdc_lock);
444 * pdc_cache_info - Return cache and TLB information.
445 * @cache_info: The return buffer.
447 * Returns information about the processor's cache and TLB.
449 int pdc_cache_info(struct pdc_cache_info *cache_info)
453 spin_lock_irq(&pdc_lock);
454 retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_INFO, __pa(pdc_result), 0);
455 convert_to_wide(pdc_result);
456 memcpy(cache_info, pdc_result, sizeof(*cache_info));
457 spin_unlock_irq(&pdc_lock);
464 * pdc_btlb_info - Return block TLB information.
465 * @btlb: The return buffer.
467 * Returns information about the hardware Block TLB.
469 int pdc_btlb_info(struct pdc_btlb_info *btlb)
473 spin_lock_irq(&pdc_lock);
474 retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_INFO, __pa(pdc_result), 0);
475 memcpy(btlb, pdc_result, sizeof(*btlb));
476 spin_unlock_irq(&pdc_lock);
485 * pdc_mem_map_hpa - Find fixed module information.
486 * @address: The return buffer
487 * @mod_path: pointer to dev path structure.
489 * This call was developed for S700 workstations to allow the kernel to find
490 * the I/O devices (Core I/O). In the future (Kittyhawk and beyond) this
491 * call will be replaced (on workstations) by the architected PDC_SYSTEM_MAP
494 * This call is supported by all existing S700 workstations (up to Gecko).
496 int pdc_mem_map_hpa(struct pdc_memory_map *address,
497 struct pdc_module_path *mod_path)
501 spin_lock_irq(&pdc_lock);
502 memcpy(pdc_result2, mod_path, sizeof(*mod_path));
503 retval = mem_pdc_call(PDC_MEM_MAP, PDC_MEM_MAP_HPA, __pa(pdc_result),
505 memcpy(address, pdc_result, sizeof(*address));
506 spin_unlock_irq(&pdc_lock);
510 #endif /* !CONFIG_PA20 */
513 * pdc_lan_station_id - Get the LAN address.
514 * @lan_addr: The return buffer.
515 * @hpa: The network device HPA.
517 * Get the LAN station address when it is not directly available from the LAN hardware.
519 int pdc_lan_station_id(char *lan_addr, unsigned long hpa)
523 spin_lock_irq(&pdc_lock);
524 retval = mem_pdc_call(PDC_LAN_STATION_ID, PDC_LAN_STATION_ID_READ,
525 __pa(pdc_result), hpa);
527 /* FIXME: else read MAC from NVRAM */
528 memset(lan_addr, 0, PDC_LAN_STATION_ID_SIZE);
530 memcpy(lan_addr, pdc_result, PDC_LAN_STATION_ID_SIZE);
532 spin_unlock_irq(&pdc_lock);
536 EXPORT_SYMBOL(pdc_lan_station_id);
540 * pdc_get_initiator - Get the SCSI Interface Card params (SCSI ID, SDTR, SE or LVD)
541 * @hwpath: fully bc.mod style path to the device.
542 * @scsi_id: what someone told firmware the ID should be.
543 * @period: time in cycles
544 * @width: 8 or 16-bit wide bus
545 * @mode: 0,1,2 -> SE,HVD,LVD signalling mode
547 * Get the SCSI operational parameters from PDC.
548 * Needed since HPUX never used BIOS or symbios card NVRAM.
549 * Most ncr/sym cards won't have an entry and just use whatever
550 * capabilities of the card are (eg Ultra, LVD). But there are
551 * several cases where it's useful:
552 * o set SCSI id for Multi-initiator clusters,
553 * o cable too long (ie SE scsi 10Mhz won't support 6m length),
554 * o bus width exported is less than what the interface chip supports.
556 int pdc_get_initiator(struct hardware_path *hwpath, unsigned char *scsi_id,
557 unsigned long *period, char *width, char *mode)
561 spin_lock_irq(&pdc_lock);
563 /* BCJ-XXXX series boxes. E.G. "9000/785/C3000" */
564 #define IS_SPROCKETS() (strlen(boot_cpu_data.pdc.sys_model_name) == 14 && \
565 strncmp(boot_cpu_data.pdc.sys_model_name, "9000/785", 8) == 0)
567 retval = mem_pdc_call(PDC_INITIATOR, PDC_GET_INITIATOR,
568 __pa(pdc_result), __pa(hwpath));
573 *scsi_id = (unsigned char) pdc_result[0];
575 /* convert Bus speed in Mhz to period (in 1/10 ns) */
576 switch (pdc_result[1]) {
578 * case 0: driver determines rate
579 * case -1: Settings are uninitialized.
581 case 5: *period = 2000; break;
582 case 10: *period = 1000; break;
583 case 20: *period = 500; break;
584 case 40: *period = 250; break;
585 default: /* Do nothing */ break;
589 * pdc_result[2] PDC suggested SCSI id
590 * pdc_result[3] PDC suggested SCSI rate
593 if (IS_SPROCKETS()) {
594 /* 0 == 8-bit, 1 == 16-bit */
595 *width = (char) pdc_result[4];
597 /* ...in case someone needs it in the future.
598 * sym53c8xx.c comments say it can't autodetect
599 * for 825/825A/875 chips.
600 * 0 == SE, 1 == HVD, 2 == LVD
602 *mode = (char) pdc_result[5];
606 spin_unlock_irq(&pdc_lock);
607 return (retval >= PDC_OK);
609 EXPORT_SYMBOL(pdc_get_initiator);
613 * pdc_pci_irt_size - Get the number of entries in the interrupt routing table.
614 * @num_entries: The return value.
615 * @hpa: The HPA for the device.
617 * This PDC function returns the number of entries in the specified cell's
619 * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
621 int pdc_pci_irt_size(unsigned long *num_entries, unsigned long hpa)
625 spin_lock_irq(&pdc_lock);
626 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL_SIZE,
627 __pa(pdc_result), hpa);
628 convert_to_wide(pdc_result);
629 *num_entries = pdc_result[0];
630 spin_unlock_irq(&pdc_lock);
636 * pdc_pci_irt - Get the PCI interrupt routing table.
637 * @num_entries: The number of entries in the table.
638 * @hpa: The Hard Physical Address of the device.
641 * Get the PCI interrupt routing table for the device at the given HPA.
642 * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
644 int pdc_pci_irt(unsigned long num_entries, unsigned long hpa, void *tbl)
648 spin_lock_irq(&pdc_lock);
649 pdc_result[0] = num_entries;
650 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL,
651 __pa(pdc_result), hpa, __pa(tbl));
652 spin_unlock_irq(&pdc_lock);
658 #if 0 /* UNTEST CODE - left here in case someone needs it */
661 * pdc_pci_config_read - read PCI config space.
662 * @hpa token from PDC to indicate which PCI device
663 * @pci_addr configuration space address to read from
665 * Read PCI Configuration space *before* linux PCI subsystem is running.
667 unsigned int pdc_pci_config_read(void *hpa, unsigned long cfg_addr)
670 spin_lock_irq(&pdc_lock);
673 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_READ_CONFIG,
674 __pa(pdc_result), hpa, cfg_addr&~3UL, 4UL);
675 spin_unlock_irq(&pdc_lock);
676 return retval ? ~0 : (unsigned int) pdc_result[0];
681 * pdc_pci_config_write - read PCI config space.
682 * @hpa token from PDC to indicate which PCI device
683 * @pci_addr configuration space address to write
684 * @val value we want in the 32-bit register
686 * Write PCI Configuration space *before* linux PCI subsystem is running.
688 void pdc_pci_config_write(void *hpa, unsigned long cfg_addr, unsigned int val)
691 spin_lock_irq(&pdc_lock);
693 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_WRITE_CONFIG,
694 __pa(pdc_result), hpa,
695 cfg_addr&~3UL, 4UL, (unsigned long) val);
696 spin_unlock_irq(&pdc_lock);
699 #endif /* UNTESTED CODE */
702 * pdc_tod_read - Read the Time-Of-Day clock.
703 * @tod: The return buffer:
705 * Read the Time-Of-Day clock
707 int pdc_tod_read(struct pdc_tod *tod)
711 spin_lock_irq(&pdc_lock);
712 retval = mem_pdc_call(PDC_TOD, PDC_TOD_READ, __pa(pdc_result), 0);
713 convert_to_wide(pdc_result);
714 memcpy(tod, pdc_result, sizeof(*tod));
715 spin_unlock_irq(&pdc_lock);
719 EXPORT_SYMBOL(pdc_tod_read);
722 * pdc_tod_set - Set the Time-Of-Day clock.
723 * @sec: The number of seconds since epoch.
724 * @usec: The number of micro seconds.
726 * Set the Time-Of-Day clock.
728 int pdc_tod_set(unsigned long sec, unsigned long usec)
732 spin_lock_irq(&pdc_lock);
733 retval = mem_pdc_call(PDC_TOD, PDC_TOD_WRITE, sec, usec);
734 spin_unlock_irq(&pdc_lock);
738 EXPORT_SYMBOL(pdc_tod_set);
741 int pdc_mem_mem_table(struct pdc_memory_table_raddr *r_addr,
742 struct pdc_memory_table *tbl, unsigned long entries)
746 spin_lock_irq(&pdc_lock);
747 retval = mem_pdc_call(PDC_MEM, PDC_MEM_TABLE, __pa(pdc_result), __pa(pdc_result2), entries);
748 convert_to_wide(pdc_result);
749 memcpy(r_addr, pdc_result, sizeof(*r_addr));
750 memcpy(tbl, pdc_result2, entries * sizeof(*tbl));
751 spin_unlock_irq(&pdc_lock);
755 #endif /* __LP64__ */
757 /* FIXME: Is this pdc used? I could not find type reference to ftc_bitmap
758 * so I guessed at unsigned long. Someone who knows what this does, can fix
761 int pdc_do_firm_test_reset(unsigned long ftc_bitmap)
765 spin_lock_irq(&pdc_lock);
766 retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_FIRM_TEST_RESET,
767 PDC_FIRM_TEST_MAGIC, ftc_bitmap);
768 spin_unlock_irq(&pdc_lock);
774 * pdc_do_reset - Reset the system.
782 spin_lock_irq(&pdc_lock);
783 retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_RESET);
784 spin_unlock_irq(&pdc_lock);
790 * pdc_soft_power_info - Enable soft power switch.
791 * @power_reg: address of soft power register
793 * Return the absolute address of the soft power switch register
795 int __init pdc_soft_power_info(unsigned long *power_reg)
799 *power_reg = (unsigned long) (-1);
801 spin_lock_irq(&pdc_lock);
802 retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_INFO, __pa(pdc_result), 0);
803 if (retval == PDC_OK) {
804 convert_to_wide(pdc_result);
805 *power_reg = f_extend(pdc_result[0]);
807 spin_unlock_irq(&pdc_lock);
813 * pdc_soft_power_button - Control the soft power button behaviour
814 * @sw_control: 0 for hardware control, 1 for software control
817 * This PDC function places the soft power button under software or
819 * Under software control the OS may control to when to allow to shut
820 * down the system. Under hardware control pressing the power button
821 * powers off the system immediately.
823 int pdc_soft_power_button(int sw_control)
826 spin_lock_irq(&pdc_lock);
827 retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
828 spin_unlock_irq(&pdc_lock);
833 * pdc_io_reset - Hack to avoid overlapping range registers of Bridges devices.
834 * Primarily a problem on T600 (which parisc-linux doesn't support) but
835 * who knows what other platform firmware might do with this OS "hook".
837 void pdc_io_reset(void)
839 spin_lock_irq(&pdc_lock);
840 mem_pdc_call(PDC_IO, PDC_IO_RESET, 0);
841 spin_unlock_irq(&pdc_lock);
845 * pdc_io_reset_devices - Hack to Stop USB controller
847 * If PDC used the usb controller, the usb controller
848 * is still running and will crash the machines during iommu
849 * setup, because of still running DMA. This PDC call
850 * stops the USB controller.
851 * Normally called after calling pdc_io_reset().
853 void pdc_io_reset_devices(void)
855 spin_lock_irq(&pdc_lock);
856 mem_pdc_call(PDC_IO, PDC_IO_RESET_DEVICES, 0);
857 spin_unlock_irq(&pdc_lock);
862 * pdc_iodc_putc - Console character print using IODC.
863 * @c: the character to output.
865 * Note that only these special chars are architected for console IODC io:
866 * BEL, BS, CR, and LF. Others are passed through.
867 * Since the HP console requires CR+LF to perform a 'newline', we translate
870 void pdc_iodc_putc(unsigned char c)
872 /* XXX Should we spinlock posx usage */
873 static int posx; /* for simple TAB-Simulation... */
874 static int __attribute__((aligned(8))) iodc_retbuf[32];
875 static char __attribute__((aligned(64))) iodc_dbuf[4096];
888 while (posx & 7) /* expand TAB */
890 return; /* return since IODC can't handle this */
900 spin_lock_irqsave(&pdc_lock, flags);
901 real32_call(PAGE0->mem_cons.iodc_io,
902 (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
903 PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
904 __pa(iodc_retbuf), 0, __pa(iodc_dbuf), n, 0);
905 spin_unlock_irqrestore(&pdc_lock, flags);
909 * pdc_iodc_outc - Console character print using IODC (without conversions).
910 * @c: the character to output.
912 * Write the character directly to the IODC console.
914 void pdc_iodc_outc(unsigned char c)
916 unsigned int n, flags;
918 /* fill buffer with one caracter and print it */
919 static int __attribute__((aligned(8))) iodc_retbuf[32];
920 static char __attribute__((aligned(64))) iodc_dbuf[4096];
925 spin_lock_irqsave(&pdc_lock, flags);
926 real32_call(PAGE0->mem_cons.iodc_io,
927 (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
928 PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
929 __pa(iodc_retbuf), 0, __pa(iodc_dbuf), n, 0);
930 spin_unlock_irqrestore(&pdc_lock, flags);
934 * pdc_iodc_getc - Read a character (non-blocking) from the PDC console.
936 * Read a character (non-blocking) from the PDC console, returns -1 if
937 * key is not present.
939 int pdc_iodc_getc(void)
942 static int __attribute__((aligned(8))) iodc_retbuf[32];
943 static char __attribute__((aligned(64))) iodc_dbuf[4096];
947 /* Bail if no console input device. */
948 if (!PAGE0->mem_kbd.iodc_io)
951 /* wait for a keyboard (rs232)-input */
952 spin_lock_irqsave(&pdc_lock, flags);
953 real32_call(PAGE0->mem_kbd.iodc_io,
954 (unsigned long)PAGE0->mem_kbd.hpa, ENTRY_IO_CIN,
955 PAGE0->mem_kbd.spa, __pa(PAGE0->mem_kbd.dp.layers),
956 __pa(iodc_retbuf), 0, __pa(iodc_dbuf), 1, 0);
959 status = *iodc_retbuf;
960 spin_unlock_irqrestore(&pdc_lock, flags);
968 int pdc_sti_call(unsigned long func, unsigned long flags,
969 unsigned long inptr, unsigned long outputr,
970 unsigned long glob_cfg)
974 spin_lock_irq(&pdc_lock);
975 retval = real32_call(func, flags, inptr, outputr, glob_cfg);
976 spin_unlock_irq(&pdc_lock);
980 EXPORT_SYMBOL(pdc_sti_call);
984 * pdc_pat_cell_get_number - Returns the cell number.
985 * @cell_info: The return buffer.
987 * This PDC call returns the cell number of the cell from which the call
990 int pdc_pat_cell_get_number(struct pdc_pat_cell_num *cell_info)
994 spin_lock_irq(&pdc_lock);
995 retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_GET_NUMBER, __pa(pdc_result));
996 memcpy(cell_info, pdc_result, sizeof(*cell_info));
997 spin_unlock_irq(&pdc_lock);
1003 * pdc_pat_cell_module - Retrieve the cell's module information.
1004 * @actcnt: The number of bytes written to mem_addr.
1005 * @ploc: The physical location.
1006 * @mod: The module index.
1007 * @view_type: The view of the address type.
1008 * @mem_addr: The return buffer.
1010 * This PDC call returns information about each module attached to the cell
1011 * at the specified location.
1013 int pdc_pat_cell_module(unsigned long *actcnt, unsigned long ploc, unsigned long mod,
1014 unsigned long view_type, void *mem_addr)
1017 static struct pdc_pat_cell_mod_maddr_block result __attribute__ ((aligned (8)));
1019 spin_lock_irq(&pdc_lock);
1020 retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_MODULE, __pa(pdc_result),
1021 ploc, mod, view_type, __pa(&result));
1023 *actcnt = pdc_result[0];
1024 memcpy(mem_addr, &result, *actcnt);
1026 spin_unlock_irq(&pdc_lock);
1032 * pdc_pat_cpu_get_number - Retrieve the cpu number.
1033 * @cpu_info: The return buffer.
1034 * @hpa: The Hard Physical Address of the CPU.
1036 * Retrieve the cpu number for the cpu at the specified HPA.
1038 int pdc_pat_cpu_get_number(struct pdc_pat_cpu_num *cpu_info, void *hpa)
1042 spin_lock_irq(&pdc_lock);
1043 retval = mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_GET_NUMBER,
1044 __pa(&pdc_result), hpa);
1045 memcpy(cpu_info, pdc_result, sizeof(*cpu_info));
1046 spin_unlock_irq(&pdc_lock);
1052 * pdc_pat_get_irt_size - Retrieve the number of entries in the cell's interrupt table.
1053 * @num_entries: The return value.
1054 * @cell_num: The target cell.
1056 * This PDC function returns the number of entries in the specified cell's
1059 int pdc_pat_get_irt_size(unsigned long *num_entries, unsigned long cell_num)
1063 spin_lock_irq(&pdc_lock);
1064 retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE_SIZE,
1065 __pa(pdc_result), cell_num);
1066 *num_entries = pdc_result[0];
1067 spin_unlock_irq(&pdc_lock);
1073 * pdc_pat_get_irt - Retrieve the cell's interrupt table.
1074 * @r_addr: The return buffer.
1075 * @cell_num: The target cell.
1077 * This PDC function returns the actual interrupt table for the specified cell.
1079 int pdc_pat_get_irt(void *r_addr, unsigned long cell_num)
1083 spin_lock_irq(&pdc_lock);
1084 retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE,
1085 __pa(r_addr), cell_num);
1086 spin_unlock_irq(&pdc_lock);
1092 * pdc_pat_pd_get_addr_map - Retrieve information about memory address ranges.
1093 * @actlen: The return buffer.
1094 * @mem_addr: Pointer to the memory buffer.
1095 * @count: The number of bytes to read from the buffer.
1096 * @offset: The offset with respect to the beginning of the buffer.
1099 int pdc_pat_pd_get_addr_map(unsigned long *actual_len, void *mem_addr,
1100 unsigned long count, unsigned long offset)
1104 spin_lock_irq(&pdc_lock);
1105 retval = mem_pdc_call(PDC_PAT_PD, PDC_PAT_PD_GET_ADDR_MAP, __pa(pdc_result),
1106 __pa(pdc_result2), count, offset);
1107 *actual_len = pdc_result[0];
1108 memcpy(mem_addr, pdc_result2, *actual_len);
1109 spin_unlock_irq(&pdc_lock);
1113 #endif /* __LP64__ */
1116 /***************** 32-bit real-mode calls ***********/
1117 /* The struct below is used
1118 * to overlay real_stack (real2.S), preparing a 32-bit call frame.
1119 * real32_call_asm() then uses this stack in narrow real mode
1122 struct narrow_stack {
1123 /* use int, not long which is 64 bits */
1138 unsigned int frame_marker[8];
1140 /* in reality, there's nearly 8k of stack after this */
1143 long real32_call(unsigned long fn, ...)
1146 extern struct narrow_stack real_stack;
1147 extern unsigned long real32_call_asm(unsigned int *,
1152 real_stack.arg0 = va_arg(args, unsigned int);
1153 real_stack.arg1 = va_arg(args, unsigned int);
1154 real_stack.arg2 = va_arg(args, unsigned int);
1155 real_stack.arg3 = va_arg(args, unsigned int);
1156 real_stack.arg4 = va_arg(args, unsigned int);
1157 real_stack.arg5 = va_arg(args, unsigned int);
1158 real_stack.arg6 = va_arg(args, unsigned int);
1159 real_stack.arg7 = va_arg(args, unsigned int);
1160 real_stack.arg8 = va_arg(args, unsigned int);
1161 real_stack.arg9 = va_arg(args, unsigned int);
1162 real_stack.arg10 = va_arg(args, unsigned int);
1163 real_stack.arg11 = va_arg(args, unsigned int);
1164 real_stack.arg12 = va_arg(args, unsigned int);
1165 real_stack.arg13 = va_arg(args, unsigned int);
1168 return real32_call_asm(&real_stack.sp, &real_stack.arg0, fn);
1172 /***************** 64-bit real-mode calls ***********/
1185 unsigned long arg10;
1186 unsigned long arg11;
1187 unsigned long arg12;
1188 unsigned long arg13;
1189 unsigned long frame_marker[2]; /* rp, previous sp */
1191 /* in reality, there's nearly 8k of stack after this */
1194 long real64_call(unsigned long fn, ...)
1197 extern struct wide_stack real_stack;
1198 extern unsigned long real64_call_asm(unsigned long *,
1203 real_stack.arg0 = va_arg(args, unsigned long);
1204 real_stack.arg1 = va_arg(args, unsigned long);
1205 real_stack.arg2 = va_arg(args, unsigned long);
1206 real_stack.arg3 = va_arg(args, unsigned long);
1207 real_stack.arg4 = va_arg(args, unsigned long);
1208 real_stack.arg5 = va_arg(args, unsigned long);
1209 real_stack.arg6 = va_arg(args, unsigned long);
1210 real_stack.arg7 = va_arg(args, unsigned long);
1211 real_stack.arg8 = va_arg(args, unsigned long);
1212 real_stack.arg9 = va_arg(args, unsigned long);
1213 real_stack.arg10 = va_arg(args, unsigned long);
1214 real_stack.arg11 = va_arg(args, unsigned long);
1215 real_stack.arg12 = va_arg(args, unsigned long);
1216 real_stack.arg13 = va_arg(args, unsigned long);
1219 return real64_call_asm(&real_stack.sp, &real_stack.arg0, fn);
1222 #endif /* __LP64__ */