1 /* arch/parisc/kernel/pdc.c - safe pdc access routines
3 * Copyright 1999 SuSE GmbH Nuernberg (Philipp Rumpf, prumpf@tux.org)
4 * portions Copyright 1999 The Puffin Group, (Alex deVries, David Kennedy)
6 * only these routines should be used out of the real kernel (i.e. everything
7 * using virtual addresses) for obvious reasons */
9 /* I think it would be in everyone's best interest to follow this
10 * guidelines when writing PDC wrappers:
12 * - the name of the pdc wrapper should match one of the macros
13 * used for the first two arguments
14 * - don't use caps for random parts of the name
15 * - use the static PDC result buffers and "copyout" to structs
16 * supplied by the caller to encapsulate alignment restrictions
17 * - hold pdc_lock while in PDC or using static result buffers
18 * - use __pa() to convert virtual (kernel) pointers to physical
20 * - the name of the struct used for pdc return values should equal
21 * one of the macros used for the first two arguments to the
22 * corresponding PDC call
23 * - keep the order of arguments
24 * - don't be smart (setting trailing NUL bytes for strings, return
25 * something useful even if the call failed) unless you are sure
26 * it's not going to affect functionality or performance
29 * int pdc_cache_info(struct pdc_cache_info *cache_info )
33 * spin_lock_irq(&pdc_lock);
34 * retval = mem_pdc_call(PDC_CACHE,PDC_CACHE_INFO,__pa(cache_info),0);
35 * convert_to_wide(pdc_result);
36 * memcpy(cache_info, pdc_result, sizeof(*cache_info));
37 * spin_unlock_irq(&pdc_lock);
46 #include <linux/delay.h>
47 #include <linux/init.h>
48 #include <linux/kernel.h>
49 #include <linux/module.h>
50 #include <linux/string.h>
51 #include <linux/spinlock.h>
55 #include <asm/system.h>
56 #include <asm/processor.h> /* for boot_cpu_data */
58 static spinlock_t pdc_lock = SPIN_LOCK_UNLOCKED;
59 static unsigned long pdc_result[32] __attribute__ ((aligned (8)));
60 static unsigned long pdc_result2[32] __attribute__ ((aligned (8)));
62 /* on all currently-supported platforms, IODC I/O calls are always
63 * 32-bit calls, and MEM_PDC calls are always the same width as the OS.
64 * This means Cxxx boxes can't run wide kernels right now. -PB
66 * CONFIG_PDC_NARROW has been added to allow 64-bit kernels to run on
67 * systems with 32-bit MEM_PDC calls. This will allow wide kernels to
68 * run on Cxxx boxes now. -RB
70 * Note that some PAT boxes may have 64-bit IODC I/O...
74 long real64_call(unsigned long function, ...);
76 long real32_call(unsigned long function, ...);
78 #if defined(__LP64__) && ! defined(CONFIG_PDC_NARROW)
79 #define MEM_PDC (unsigned long)(PAGE0->mem_pdc_hi) << 32 | PAGE0->mem_pdc
80 # define mem_pdc_call(args...) real64_call(MEM_PDC, args)
82 #define MEM_PDC (unsigned long)PAGE0->mem_pdc
83 # define mem_pdc_call(args...) real32_call(MEM_PDC, args)
88 * f_extend - Convert PDC addresses to kernel addresses.
89 * @address: Address returned from PDC.
91 * This function is used to convert PDC addresses into kernel addresses
92 * when the PDC address size and kernel address size are different.
94 static unsigned long f_extend(unsigned long address)
96 #ifdef CONFIG_PDC_NARROW
97 if((address & 0xff000000) == 0xf0000000)
98 return 0xf0f0f0f000000000 | (u32)address;
100 if((address & 0xf0000000) == 0xf0000000)
101 return 0xffffffff00000000 | (u32)address;
107 * convert_to_wide - Convert the return buffer addresses into kernel addresses.
108 * @address: The return buffer from PDC.
110 * This function is used to convert the return buffer addresses retrieved from PDC
111 * into kernel addresses when the PDC address size and kernel address size are
114 static void convert_to_wide(unsigned long *addr)
116 #ifdef CONFIG_PDC_NARROW
118 unsigned *p = (unsigned int *)addr;
119 for(i = 31; i >= 0; --i)
125 * pdc_emergency_unlock - Unlock the linux pdc lock
127 * This call unlocks the linux pdc lock in case we need some PDC functions
128 * (like pdc_add_valid) during kernel stack dump.
130 void pdc_emergency_unlock(void)
132 spin_unlock(&pdc_lock);
137 * pdc_add_valid - Verify address can be accessed without causing a HPMC.
138 * @address: Address to be verified.
140 * This PDC call attempts to read from the specified address and verifies
141 * if the address is valid.
143 * The return value is PDC_OK (0) in case accessing this address is valid.
145 int pdc_add_valid(unsigned long address)
149 spin_lock_irq(&pdc_lock);
150 retval = mem_pdc_call(PDC_ADD_VALID, PDC_ADD_VALID_VERIFY, address);
151 spin_unlock_irq(&pdc_lock);
155 EXPORT_SYMBOL(pdc_add_valid);
158 * pdc_chassis_info - Return chassis information.
159 * @result: The return buffer.
160 * @chassis_info: The memory buffer address.
161 * @len: The size of the memory buffer address.
163 * An HVERSION dependent call for returning the chassis information.
165 int __init pdc_chassis_info(struct pdc_chassis_info *chassis_info, void *led_info, unsigned long len)
169 spin_lock_irq(&pdc_lock);
170 memcpy(&pdc_result, chassis_info, sizeof(*chassis_info));
171 memcpy(&pdc_result2, led_info, len);
172 retval = mem_pdc_call(PDC_CHASSIS, PDC_RETURN_CHASSIS_INFO,
173 __pa(pdc_result), __pa(pdc_result2), len);
174 memcpy(chassis_info, pdc_result, sizeof(*chassis_info));
175 memcpy(led_info, pdc_result2, len);
176 spin_unlock_irq(&pdc_lock);
182 * pdc_pat_chassis_send_log - Sends a PDC PAT CHASSIS log message.
183 * @retval: -1 on error, 0 on success. Other value are PDC errors
185 * Must be correctly formatted or expect system crash
188 int pdc_pat_chassis_send_log(unsigned long state, unsigned long data)
195 spin_lock_irq(&pdc_lock);
196 retval = mem_pdc_call(PDC_PAT_CHASSIS_LOG, PDC_PAT_CHASSIS_WRITE_LOG, __pa(&state), __pa(&data));
197 spin_unlock_irq(&pdc_lock);
204 * pdc_chassis_disp - Updates display
205 * @retval: -1 on error, 0 on success
207 * Works on old PDC only (E class, others?)
209 int pdc_chassis_disp(unsigned long disp)
213 spin_lock_irq(&pdc_lock);
214 retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_DISP, disp);
215 spin_unlock_irq(&pdc_lock);
221 * pdc_coproc_cfg - To identify coprocessors attached to the processor.
222 * @pdc_coproc_info: Return buffer address.
224 * This PDC call returns the presence and status of all the coprocessors
225 * attached to the processor.
227 int __init pdc_coproc_cfg(struct pdc_coproc_cfg *pdc_coproc_info)
231 spin_lock_irq(&pdc_lock);
232 retval = mem_pdc_call(PDC_COPROC, PDC_COPROC_CFG, __pa(pdc_result));
233 convert_to_wide(pdc_result);
234 pdc_coproc_info->ccr_functional = pdc_result[0];
235 pdc_coproc_info->ccr_present = pdc_result[1];
236 pdc_coproc_info->revision = pdc_result[17];
237 pdc_coproc_info->model = pdc_result[18];
238 spin_unlock_irq(&pdc_lock);
244 * pdc_iodc_read - Read data from the modules IODC.
245 * @actcnt: The actual number of bytes.
246 * @hpa: The HPA of the module for the iodc read.
247 * @index: The iodc entry point.
248 * @iodc_data: A buffer memory for the iodc options.
249 * @iodc_data_size: Size of the memory buffer.
251 * This PDC call reads from the IODC of the module specified by the hpa
254 int pdc_iodc_read(unsigned long *actcnt, unsigned long hpa, unsigned int index,
255 void *iodc_data, unsigned int iodc_data_size)
259 spin_lock_irq(&pdc_lock);
260 retval = mem_pdc_call(PDC_IODC, PDC_IODC_READ, __pa(pdc_result), hpa,
261 index, __pa(pdc_result2), iodc_data_size);
262 convert_to_wide(pdc_result);
263 *actcnt = pdc_result[0];
264 memcpy(iodc_data, pdc_result2, iodc_data_size);
265 spin_unlock_irq(&pdc_lock);
269 EXPORT_SYMBOL(pdc_iodc_read);
272 * pdc_system_map_find_mods - Locate unarchitected modules.
273 * @pdc_mod_info: Return buffer address.
274 * @mod_path: pointer to dev path structure.
275 * @mod_index: fixed address module index.
277 * To locate and identify modules which reside at fixed I/O addresses, which
278 * do not self-identify via architected bus walks.
280 int pdc_system_map_find_mods(struct pdc_system_map_mod_info *pdc_mod_info,
281 struct pdc_module_path *mod_path, long mod_index)
285 spin_lock_irq(&pdc_lock);
286 retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_MODULE, __pa(pdc_result),
287 __pa(pdc_result2), mod_index);
288 convert_to_wide(pdc_result);
289 memcpy(pdc_mod_info, pdc_result, sizeof(*pdc_mod_info));
290 memcpy(mod_path, pdc_result2, sizeof(*mod_path));
291 spin_unlock_irq(&pdc_lock);
293 pdc_mod_info->mod_addr = f_extend(pdc_mod_info->mod_addr);
298 * pdc_system_map_find_addrs - Retrieve additional address ranges.
299 * @pdc_addr_info: Return buffer address.
300 * @mod_index: Fixed address module index.
301 * @addr_index: Address range index.
303 * Retrieve additional information about subsequent address ranges for modules
304 * with multiple address ranges.
306 int pdc_system_map_find_addrs(struct pdc_system_map_addr_info *pdc_addr_info,
307 long mod_index, long addr_index)
311 spin_lock_irq(&pdc_lock);
312 retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_ADDRESS, __pa(pdc_result),
313 mod_index, addr_index);
314 convert_to_wide(pdc_result);
315 memcpy(pdc_addr_info, pdc_result, sizeof(*pdc_addr_info));
316 spin_unlock_irq(&pdc_lock);
318 pdc_addr_info->mod_addr = f_extend(pdc_addr_info->mod_addr);
323 * pdc_model_info - Return model information about the processor.
324 * @model: The return buffer.
326 * Returns the version numbers, identifiers, and capabilities from the processor module.
328 int pdc_model_info(struct pdc_model *model)
332 spin_lock_irq(&pdc_lock);
333 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_INFO, __pa(pdc_result), 0);
334 convert_to_wide(pdc_result);
335 memcpy(model, pdc_result, sizeof(*model));
336 spin_unlock_irq(&pdc_lock);
342 * pdc_model_sysmodel - Get the system model name.
343 * @name: A char array of at least 81 characters.
345 * Get system model name from PDC ROM (e.g. 9000/715 or 9000/778/B160L)
347 int pdc_model_sysmodel(char *name)
351 spin_lock_irq(&pdc_lock);
352 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_SYSMODEL, __pa(pdc_result),
353 OS_ID_HPUX, __pa(name));
354 convert_to_wide(pdc_result);
356 if (retval == PDC_OK) {
357 name[pdc_result[0]] = '\0'; /* add trailing '\0' */
361 spin_unlock_irq(&pdc_lock);
367 * pdc_model_versions - Identify the version number of each processor.
368 * @cpu_id: The return buffer.
369 * @id: The id of the processor to check.
371 * Returns the version number for each processor component.
373 * This comment was here before, but I do not know what it means :( -RB
374 * id: 0 = cpu revision, 1 = boot-rom-version
376 int pdc_model_versions(unsigned long *versions, int id)
380 spin_lock_irq(&pdc_lock);
381 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_VERSIONS, __pa(pdc_result), id);
382 convert_to_wide(pdc_result);
383 *versions = pdc_result[0];
384 spin_unlock_irq(&pdc_lock);
390 * pdc_model_cpuid - Returns the CPU_ID.
391 * @cpu_id: The return buffer.
393 * Returns the CPU_ID value which uniquely identifies the cpu portion of
394 * the processor module.
396 int pdc_model_cpuid(unsigned long *cpu_id)
400 spin_lock_irq(&pdc_lock);
401 pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
402 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CPU_ID, __pa(pdc_result), 0);
403 convert_to_wide(pdc_result);
404 *cpu_id = pdc_result[0];
405 spin_unlock_irq(&pdc_lock);
411 * pdc_model_capabilities - Returns the platform capabilities.
412 * @capabilities: The return buffer.
414 * Returns information about platform support for 32- and/or 64-bit
415 * OSes, IO-PDIR coherency, and virtual aliasing.
417 int pdc_model_capabilities(unsigned long *capabilities)
421 spin_lock_irq(&pdc_lock);
422 pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
423 retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES, __pa(pdc_result), 0);
424 convert_to_wide(pdc_result);
425 *capabilities = pdc_result[0];
426 spin_unlock_irq(&pdc_lock);
432 * pdc_cache_info - Return cache and TLB information.
433 * @cache_info: The return buffer.
435 * Returns information about the processor's cache and TLB.
437 int pdc_cache_info(struct pdc_cache_info *cache_info)
441 spin_lock_irq(&pdc_lock);
442 retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_INFO, __pa(pdc_result), 0);
443 convert_to_wide(pdc_result);
444 memcpy(cache_info, pdc_result, sizeof(*cache_info));
445 spin_unlock_irq(&pdc_lock);
452 * pdc_btlb_info - Return block TLB information.
453 * @btlb: The return buffer.
455 * Returns information about the hardware Block TLB.
457 int pdc_btlb_info(struct pdc_btlb_info *btlb)
461 spin_lock_irq(&pdc_lock);
462 retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_INFO, __pa(pdc_result), 0);
463 memcpy(btlb, pdc_result, sizeof(*btlb));
464 spin_unlock_irq(&pdc_lock);
473 * pdc_mem_map_hpa - Find fixed module information.
474 * @address: The return buffer
475 * @mod_path: pointer to dev path structure.
477 * This call was developed for S700 workstations to allow the kernel to find
478 * the I/O devices (Core I/O). In the future (Kittyhawk and beyond) this
479 * call will be replaced (on workstations) by the architected PDC_SYSTEM_MAP
482 * This call is supported by all existing S700 workstations (up to Gecko).
484 int pdc_mem_map_hpa(struct pdc_memory_map *address,
485 struct pdc_module_path *mod_path)
489 spin_lock_irq(&pdc_lock);
490 memcpy(pdc_result2, mod_path, sizeof(*mod_path));
491 retval = mem_pdc_call(PDC_MEM_MAP, PDC_MEM_MAP_HPA, __pa(pdc_result),
493 memcpy(address, pdc_result, sizeof(*address));
494 spin_unlock_irq(&pdc_lock);
498 #endif /* !CONFIG_PA20 */
501 * pdc_lan_station_id - Get the LAN address.
502 * @lan_addr: The return buffer.
503 * @hpa: The network device HPA.
505 * Get the LAN station address when it is not directly available from the LAN hardware.
507 int pdc_lan_station_id(char *lan_addr, unsigned long hpa)
511 spin_lock_irq(&pdc_lock);
512 retval = mem_pdc_call(PDC_LAN_STATION_ID, PDC_LAN_STATION_ID_READ,
513 __pa(pdc_result), hpa);
515 /* FIXME: else read MAC from NVRAM */
516 memset(lan_addr, 0, PDC_LAN_STATION_ID_SIZE);
518 memcpy(lan_addr, pdc_result, PDC_LAN_STATION_ID_SIZE);
520 spin_unlock_irq(&pdc_lock);
524 EXPORT_SYMBOL(pdc_lan_station_id);
528 * pdc_get_initiator - Get the SCSI Interface Card params (SCSI ID, SDTR, SE or LVD)
529 * @hwpath: fully bc.mod style path to the device.
530 * @scsi_id: what someone told firmware the ID should be.
531 * @period: time in cycles
532 * @width: 8 or 16-bit wide bus
533 * @mode: 0,1,2 -> SE,HVD,LVD signalling mode
535 * Get the SCSI operational parameters from PDC.
536 * Needed since HPUX never used BIOS or symbios card NVRAM.
537 * Most ncr/sym cards won't have an entry and just use whatever
538 * capabilities of the card are (eg Ultra, LVD). But there are
539 * several cases where it's useful:
540 * o set SCSI id for Multi-initiator clusters,
541 * o cable too long (ie SE scsi 10Mhz won't support 6m length),
542 * o bus width exported is less than what the interface chip supports.
544 int pdc_get_initiator(struct hardware_path *hwpath, unsigned char *scsi_id,
545 unsigned long *period, char *width, char *mode)
549 spin_lock_irq(&pdc_lock);
551 /* BCJ-XXXX series boxes. E.G. "9000/785/C3000" */
552 #define IS_SPROCKETS() (strlen(boot_cpu_data.pdc.sys_model_name) == 14 && \
553 strncmp(boot_cpu_data.pdc.sys_model_name, "9000/785", 8) == 0)
555 retval = mem_pdc_call(PDC_INITIATOR, PDC_GET_INITIATOR,
556 __pa(pdc_result), __pa(hwpath));
561 *scsi_id = (unsigned char) pdc_result[0];
563 /* convert Bus speed in Mhz to period (in 1/10 ns) */
564 switch (pdc_result[1]) {
566 * case 0: driver determines rate
567 * case -1: Settings are uninitialized.
569 case 5: *period = 2000; break;
570 case 10: *period = 1000; break;
571 case 20: *period = 500; break;
572 case 40: *period = 250; break;
573 default: /* Do nothing */ break;
577 * pdc_result[2] PDC suggested SCSI id
578 * pdc_result[3] PDC suggested SCSI rate
581 if (IS_SPROCKETS()) {
582 /* 0 == 8-bit, 1 == 16-bit */
583 *width = (char) pdc_result[4];
585 /* ...in case someone needs it in the future.
586 * sym53c8xx.c comments say it can't autodetect
587 * for 825/825A/875 chips.
588 * 0 == SE, 1 == HVD, 2 == LVD
590 *mode = (char) pdc_result[5];
594 spin_unlock_irq(&pdc_lock);
595 return (retval >= PDC_OK);
597 EXPORT_SYMBOL(pdc_get_initiator);
601 * pdc_pci_irt_size - Get the number of entries in the interrupt routing table.
602 * @num_entries: The return value.
603 * @hpa: The HPA for the device.
605 * This PDC function returns the number of entries in the specified cell's
607 * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
609 int pdc_pci_irt_size(unsigned long *num_entries, unsigned long hpa)
613 spin_lock_irq(&pdc_lock);
614 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL_SIZE,
615 __pa(pdc_result), hpa);
616 convert_to_wide(pdc_result);
617 *num_entries = pdc_result[0];
618 spin_unlock_irq(&pdc_lock);
624 * pdc_pci_irt - Get the PCI interrupt routing table.
625 * @num_entries: The number of entries in the table.
626 * @hpa: The Hard Physical Address of the device.
629 * Get the PCI interrupt routing table for the device at the given HPA.
630 * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
632 int pdc_pci_irt(unsigned long num_entries, unsigned long hpa, void *tbl)
636 spin_lock_irq(&pdc_lock);
637 pdc_result[0] = num_entries;
638 retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL,
639 __pa(pdc_result), hpa, __pa(tbl));
640 spin_unlock_irq(&pdc_lock);
647 * pdc_tod_read - Read the Time-Of-Day clock.
648 * @tod: The return buffer:
650 * Read the Time-Of-Day clock
652 int pdc_tod_read(struct pdc_tod *tod)
656 spin_lock_irq(&pdc_lock);
657 retval = mem_pdc_call(PDC_TOD, PDC_TOD_READ, __pa(pdc_result), 0);
658 convert_to_wide(pdc_result);
659 memcpy(tod, pdc_result, sizeof(*tod));
660 spin_unlock_irq(&pdc_lock);
664 EXPORT_SYMBOL(pdc_tod_read);
667 * pdc_tod_set - Set the Time-Of-Day clock.
668 * @sec: The number of seconds since epoch.
669 * @usec: The number of micro seconds.
671 * Set the Time-Of-Day clock.
673 int pdc_tod_set(unsigned long sec, unsigned long usec)
677 spin_lock_irq(&pdc_lock);
678 retval = mem_pdc_call(PDC_TOD, PDC_TOD_WRITE, sec, usec);
679 spin_unlock_irq(&pdc_lock);
683 EXPORT_SYMBOL(pdc_tod_set);
686 int pdc_mem_mem_table(struct pdc_memory_table_raddr *r_addr,
687 struct pdc_memory_table *tbl, unsigned long entries)
691 spin_lock_irq(&pdc_lock);
692 retval = mem_pdc_call(PDC_MEM, PDC_MEM_TABLE, __pa(pdc_result), __pa(pdc_result2), entries);
693 convert_to_wide(pdc_result);
694 memcpy(r_addr, pdc_result, sizeof(*r_addr));
695 memcpy(tbl, pdc_result2, entries * sizeof(*tbl));
696 spin_unlock_irq(&pdc_lock);
700 #endif /* __LP64__ */
702 /* FIXME: Is this pdc used? I could not find type reference to ftc_bitmap
703 * so I guessed at unsigned long. Someone who knows what this does, can fix
706 int pdc_do_firm_test_reset(unsigned long ftc_bitmap)
710 spin_lock_irq(&pdc_lock);
711 retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_FIRM_TEST_RESET,
712 PDC_FIRM_TEST_MAGIC, ftc_bitmap);
713 spin_unlock_irq(&pdc_lock);
719 * pdc_do_reset - Reset the system.
727 spin_lock_irq(&pdc_lock);
728 retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_RESET);
729 spin_unlock_irq(&pdc_lock);
735 * pdc_soft_power_info - Enable soft power switch.
736 * @power_reg: address of soft power register
738 * Return the absolute address of the soft power switch register
740 int __init pdc_soft_power_info(unsigned long *power_reg)
744 *power_reg = (unsigned long) (-1);
746 spin_lock_irq(&pdc_lock);
747 retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_INFO, __pa(pdc_result), 0);
748 if (retval == PDC_OK) {
749 convert_to_wide(pdc_result);
750 *power_reg = f_extend(pdc_result[0]);
752 spin_unlock_irq(&pdc_lock);
758 * pdc_soft_power_button - Control the soft power button behaviour
759 * @sw_control: 0 for hardware control, 1 for software control
762 * This PDC function places the soft power button under software or
764 * Under software control the OS may control to when to allow to shut
765 * down the system. Under hardware control pressing the power button
766 * powers off the system immediately.
768 int pdc_soft_power_button(int sw_control)
771 spin_lock_irq(&pdc_lock);
772 retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
773 spin_unlock_irq(&pdc_lock);
778 * pdc_io_reset - Hack to avoid overlapping range registers of Bridges devices.
779 * Primarily a problem on T600 (which parisc-linux doesn't support) but
780 * who knows what other platform firmware might do with this OS "hook".
782 void pdc_io_reset(void)
784 spin_lock_irq(&pdc_lock);
785 mem_pdc_call(PDC_IO, PDC_IO_RESET, 0);
786 spin_unlock_irq(&pdc_lock);
790 * pdc_io_reset_devices - Hack to Stop USB controller
792 * If PDC used the usb controller, the usb controller
793 * is still running and will crash the machines during iommu
794 * setup, because of still running DMA. This PDC call
795 * stops the USB controller.
796 * Normally called after calling pdc_io_reset().
798 void pdc_io_reset_devices(void)
800 spin_lock_irq(&pdc_lock);
801 mem_pdc_call(PDC_IO, PDC_IO_RESET_DEVICES, 0);
802 spin_unlock_irq(&pdc_lock);
807 * pdc_iodc_putc - Console character print using IODC.
808 * @c: the character to output.
810 * Note that only these special chars are architected for console IODC io:
811 * BEL, BS, CR, and LF. Others are passed through.
812 * Since the HP console requires CR+LF to perform a 'newline', we translate
815 void pdc_iodc_putc(unsigned char c)
817 /* XXX Should we spinlock posx usage */
818 static int posx; /* for simple TAB-Simulation... */
819 static int __attribute__((aligned(8))) iodc_retbuf[32];
820 static char __attribute__((aligned(64))) iodc_dbuf[4096];
833 while (posx & 7) /* expand TAB */
835 return; /* return since IODC can't handle this */
845 spin_lock_irqsave(&pdc_lock, flags);
846 real32_call(PAGE0->mem_cons.iodc_io,
847 (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
848 PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
849 __pa(iodc_retbuf), 0, __pa(iodc_dbuf), n, 0);
850 spin_unlock_irqrestore(&pdc_lock, flags);
854 * pdc_iodc_outc - Console character print using IODC (without conversions).
855 * @c: the character to output.
857 * Write the character directly to the IODC console.
859 void pdc_iodc_outc(unsigned char c)
861 unsigned int n, flags;
863 /* fill buffer with one caracter and print it */
864 static int __attribute__((aligned(8))) iodc_retbuf[32];
865 static char __attribute__((aligned(64))) iodc_dbuf[4096];
870 spin_lock_irqsave(&pdc_lock, flags);
871 real32_call(PAGE0->mem_cons.iodc_io,
872 (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
873 PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
874 __pa(iodc_retbuf), 0, __pa(iodc_dbuf), n, 0);
875 spin_unlock_irqrestore(&pdc_lock, flags);
879 * pdc_iodc_getc - Read a character (non-blocking) from the PDC console.
881 * Read a character (non-blocking) from the PDC console, returns -1 if
882 * key is not present.
884 int pdc_iodc_getc(void)
887 static int __attribute__((aligned(8))) iodc_retbuf[32];
888 static char __attribute__((aligned(64))) iodc_dbuf[4096];
892 /* Bail if no console input device. */
893 if (!PAGE0->mem_kbd.iodc_io)
896 /* wait for a keyboard (rs232)-input */
897 spin_lock_irqsave(&pdc_lock, flags);
898 real32_call(PAGE0->mem_kbd.iodc_io,
899 (unsigned long)PAGE0->mem_kbd.hpa, ENTRY_IO_CIN,
900 PAGE0->mem_kbd.spa, __pa(PAGE0->mem_kbd.dp.layers),
901 __pa(iodc_retbuf), 0, __pa(iodc_dbuf), 1, 0);
904 status = *iodc_retbuf;
905 spin_unlock_irqrestore(&pdc_lock, flags);
913 int pdc_sti_call(unsigned long func, unsigned long flags,
914 unsigned long inptr, unsigned long outputr,
915 unsigned long glob_cfg)
919 spin_lock_irq(&pdc_lock);
920 retval = real32_call(func, flags, inptr, outputr, glob_cfg);
921 spin_unlock_irq(&pdc_lock);
925 EXPORT_SYMBOL(pdc_sti_call);
929 * pdc_pat_cell_get_number - Returns the cell number.
930 * @cell_info: The return buffer.
932 * This PDC call returns the cell number of the cell from which the call
935 int pdc_pat_cell_get_number(struct pdc_pat_cell_num *cell_info)
939 spin_lock_irq(&pdc_lock);
940 retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_GET_NUMBER, __pa(pdc_result));
941 memcpy(cell_info, pdc_result, sizeof(*cell_info));
942 spin_unlock_irq(&pdc_lock);
948 * pdc_pat_cell_module - Retrieve the cell's module information.
949 * @actcnt: The number of bytes written to mem_addr.
950 * @ploc: The physical location.
951 * @mod: The module index.
952 * @view_type: The view of the address type.
953 * @mem_addr: The return buffer.
955 * This PDC call returns information about each module attached to the cell
956 * at the specified location.
958 int pdc_pat_cell_module(unsigned long *actcnt, unsigned long ploc, unsigned long mod,
959 unsigned long view_type, void *mem_addr)
962 static struct pdc_pat_cell_mod_maddr_block result __attribute__ ((aligned (8)));
964 spin_lock_irq(&pdc_lock);
965 retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_MODULE, __pa(pdc_result),
966 ploc, mod, view_type, __pa(&result));
968 *actcnt = pdc_result[0];
969 memcpy(mem_addr, &result, *actcnt);
971 spin_unlock_irq(&pdc_lock);
977 * pdc_pat_cpu_get_number - Retrieve the cpu number.
978 * @cpu_info: The return buffer.
979 * @hpa: The Hard Physical Address of the CPU.
981 * Retrieve the cpu number for the cpu at the specified HPA.
983 int pdc_pat_cpu_get_number(struct pdc_pat_cpu_num *cpu_info, void *hpa)
987 spin_lock_irq(&pdc_lock);
988 retval = mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_GET_NUMBER,
989 __pa(&pdc_result), hpa);
990 memcpy(cpu_info, pdc_result, sizeof(*cpu_info));
991 spin_unlock_irq(&pdc_lock);
997 * pdc_pat_get_irt_size - Retrieve the number of entries in the cell's interrupt table.
998 * @num_entries: The return value.
999 * @cell_num: The target cell.
1001 * This PDC function returns the number of entries in the specified cell's
1004 int pdc_pat_get_irt_size(unsigned long *num_entries, unsigned long cell_num)
1008 spin_lock_irq(&pdc_lock);
1009 retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE_SIZE,
1010 __pa(pdc_result), cell_num);
1011 *num_entries = pdc_result[0];
1012 spin_unlock_irq(&pdc_lock);
1018 * pdc_pat_get_irt - Retrieve the cell's interrupt table.
1019 * @r_addr: The return buffer.
1020 * @cell_num: The target cell.
1022 * This PDC function returns the actual interrupt table for the specified cell.
1024 int pdc_pat_get_irt(void *r_addr, unsigned long cell_num)
1028 spin_lock_irq(&pdc_lock);
1029 retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE,
1030 __pa(r_addr), cell_num);
1031 spin_unlock_irq(&pdc_lock);
1037 * pdc_pat_pd_get_addr_map - Retrieve information about memory address ranges.
1038 * @actlen: The return buffer.
1039 * @mem_addr: Pointer to the memory buffer.
1040 * @count: The number of bytes to read from the buffer.
1041 * @offset: The offset with respect to the beginning of the buffer.
1044 int pdc_pat_pd_get_addr_map(unsigned long *actual_len, void *mem_addr,
1045 unsigned long count, unsigned long offset)
1049 spin_lock_irq(&pdc_lock);
1050 retval = mem_pdc_call(PDC_PAT_PD, PDC_PAT_PD_GET_ADDR_MAP, __pa(pdc_result),
1051 __pa(pdc_result2), count, offset);
1052 *actual_len = pdc_result[0];
1053 memcpy(mem_addr, pdc_result2, *actual_len);
1054 spin_unlock_irq(&pdc_lock);
1058 #endif /* __LP64__ */
1061 /***************** 32-bit real-mode calls ***********/
1062 /* The struct below is used
1063 * to overlay real_stack (real2.S), preparing a 32-bit call frame.
1064 * real32_call_asm() then uses this stack in narrow real mode
1067 struct narrow_stack {
1068 /* use int, not long which is 64 bits */
1083 unsigned int frame_marker[8];
1085 /* in reality, there's nearly 8k of stack after this */
1088 long real32_call(unsigned long fn, ...)
1091 extern struct narrow_stack real_stack;
1092 extern unsigned long real32_call_asm(unsigned int *,
1097 real_stack.arg0 = va_arg(args, unsigned int);
1098 real_stack.arg1 = va_arg(args, unsigned int);
1099 real_stack.arg2 = va_arg(args, unsigned int);
1100 real_stack.arg3 = va_arg(args, unsigned int);
1101 real_stack.arg4 = va_arg(args, unsigned int);
1102 real_stack.arg5 = va_arg(args, unsigned int);
1103 real_stack.arg6 = va_arg(args, unsigned int);
1104 real_stack.arg7 = va_arg(args, unsigned int);
1105 real_stack.arg8 = va_arg(args, unsigned int);
1106 real_stack.arg9 = va_arg(args, unsigned int);
1107 real_stack.arg10 = va_arg(args, unsigned int);
1108 real_stack.arg11 = va_arg(args, unsigned int);
1109 real_stack.arg12 = va_arg(args, unsigned int);
1110 real_stack.arg13 = va_arg(args, unsigned int);
1113 return real32_call_asm(&real_stack.sp, &real_stack.arg0, fn);
1117 /***************** 64-bit real-mode calls ***********/
1130 unsigned long arg10;
1131 unsigned long arg11;
1132 unsigned long arg12;
1133 unsigned long arg13;
1134 unsigned long frame_marker[2]; /* rp, previous sp */
1136 /* in reality, there's nearly 8k of stack after this */
1139 long real64_call(unsigned long fn, ...)
1142 extern struct wide_stack real_stack;
1143 extern unsigned long real64_call_asm(unsigned long *,
1148 real_stack.arg0 = va_arg(args, unsigned long);
1149 real_stack.arg1 = va_arg(args, unsigned long);
1150 real_stack.arg2 = va_arg(args, unsigned long);
1151 real_stack.arg3 = va_arg(args, unsigned long);
1152 real_stack.arg4 = va_arg(args, unsigned long);
1153 real_stack.arg5 = va_arg(args, unsigned long);
1154 real_stack.arg6 = va_arg(args, unsigned long);
1155 real_stack.arg7 = va_arg(args, unsigned long);
1156 real_stack.arg8 = va_arg(args, unsigned long);
1157 real_stack.arg9 = va_arg(args, unsigned long);
1158 real_stack.arg10 = va_arg(args, unsigned long);
1159 real_stack.arg11 = va_arg(args, unsigned long);
1160 real_stack.arg12 = va_arg(args, unsigned long);
1161 real_stack.arg13 = va_arg(args, unsigned long);
1164 return real64_call_asm(&real_stack.sp, &real_stack.arg0, fn);
1167 #endif /* __LP64__ */