xref: /linux/arch/parisc/kernel/firmware.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * arch/parisc/kernel/firmware.c  - safe PDC access routines
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *	PDC == Processor Dependent Code
61da177e4SLinus Torvalds  *
7861e93cfSHelge Deller  * See PDC documentation at
8861e93cfSHelge Deller  * https://parisc.wiki.kernel.org/index.php/Technical_Documentation
91da177e4SLinus Torvalds  * for documentation describing the entry points and calling
101da177e4SLinus Torvalds  * conventions defined below.
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  * Copyright 1999 SuSE GmbH Nuernberg (Philipp Rumpf, prumpf@tux.org)
131da177e4SLinus Torvalds  * Copyright 1999 The Puffin Group, (Alex deVries, David Kennedy)
141da177e4SLinus Torvalds  * Copyright 2003 Grant Grundler <grundler parisc-linux org>
151da177e4SLinus Torvalds  * Copyright 2003,2004 Ryan Bradetich <rbrad@parisc-linux.org>
168ffaeaf4SThibaut Varene  * Copyright 2004,2006 Thibaut VARENE <varenet@parisc-linux.org>
171da177e4SLinus Torvalds  */
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds /*	I think it would be in everyone's best interest to follow this
201da177e4SLinus Torvalds  *	guidelines when writing PDC wrappers:
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  *	 - the name of the pdc wrapper should match one of the macros
231da177e4SLinus Torvalds  *	   used for the first two arguments
241da177e4SLinus Torvalds  *	 - don't use caps for random parts of the name
251da177e4SLinus Torvalds  *	 - use the static PDC result buffers and "copyout" to structs
261da177e4SLinus Torvalds  *	   supplied by the caller to encapsulate alignment restrictions
271da177e4SLinus Torvalds  *	 - hold pdc_lock while in PDC or using static result buffers
281da177e4SLinus Torvalds  *	 - use __pa() to convert virtual (kernel) pointers to physical
291da177e4SLinus Torvalds  *	   ones.
301da177e4SLinus Torvalds  *	 - the name of the struct used for pdc return values should equal
311da177e4SLinus Torvalds  *	   one of the macros used for the first two arguments to the
321da177e4SLinus Torvalds  *	   corresponding PDC call
331da177e4SLinus Torvalds  *	 - keep the order of arguments
341da177e4SLinus Torvalds  *	 - don't be smart (setting trailing NUL bytes for strings, return
351da177e4SLinus Torvalds  *	   something useful even if the call failed) unless you are sure
361da177e4SLinus Torvalds  *	   it's not going to affect functionality or performance
371da177e4SLinus Torvalds  *
381da177e4SLinus Torvalds  *	Example:
391da177e4SLinus Torvalds  *	int pdc_cache_info(struct pdc_cache_info *cache_info )
401da177e4SLinus Torvalds  *	{
411da177e4SLinus Torvalds  *		int retval;
421da177e4SLinus Torvalds  *
431da177e4SLinus Torvalds  *		spin_lock_irq(&pdc_lock);
441da177e4SLinus Torvalds  *		retval = mem_pdc_call(PDC_CACHE,PDC_CACHE_INFO,__pa(cache_info),0);
451da177e4SLinus Torvalds  *		convert_to_wide(pdc_result);
461da177e4SLinus Torvalds  *		memcpy(cache_info, pdc_result, sizeof(*cache_info));
471da177e4SLinus Torvalds  *		spin_unlock_irq(&pdc_lock);
481da177e4SLinus Torvalds  *
491da177e4SLinus Torvalds  *		return retval;
501da177e4SLinus Torvalds  *	}
511da177e4SLinus Torvalds  *					prumpf	991016
521da177e4SLinus Torvalds  */
531da177e4SLinus Torvalds 
54c0891ac1SAlexey Dobriyan #include <linux/stdarg.h>
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds #include <linux/delay.h>
571da177e4SLinus Torvalds #include <linux/init.h>
581da177e4SLinus Torvalds #include <linux/kernel.h>
591da177e4SLinus Torvalds #include <linux/module.h>
601da177e4SLinus Torvalds #include <linux/string.h>
611da177e4SLinus Torvalds #include <linux/spinlock.h>
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds #include <asm/page.h>
641da177e4SLinus Torvalds #include <asm/pdc.h>
651da177e4SLinus Torvalds #include <asm/pdcpat.h>
661da177e4SLinus Torvalds #include <asm/processor.h>	/* for boot_cpu_data */
671da177e4SLinus Torvalds 
68f5213b2cSHelge Deller #if defined(BOOTLOADER)
69f5213b2cSHelge Deller # undef  spin_lock_irqsave
70f5213b2cSHelge Deller # define spin_lock_irqsave(a, b) { b = 1; }
71f5213b2cSHelge Deller # undef  spin_unlock_irqrestore
72f5213b2cSHelge Deller # define spin_unlock_irqrestore(a, b)
73f5213b2cSHelge Deller #else
741da177e4SLinus Torvalds static DEFINE_SPINLOCK(pdc_lock);
75f5213b2cSHelge Deller #endif
76f5213b2cSHelge Deller 
77eed869aaSHelge Deller static unsigned long pdc_result[NUM_PDC_RESULT]  __aligned(8);
78eed869aaSHelge Deller static unsigned long pdc_result2[NUM_PDC_RESULT] __aligned(8);
791da177e4SLinus Torvalds 
80a8f44e38SHelge Deller #ifdef CONFIG_64BIT
819f5989d7SHelge Deller #define WIDE_FIRMWARE		PDC_MODEL_OS64
829f5989d7SHelge Deller #define NARROW_FIRMWARE		PDC_MODEL_OS32
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds /* Firmware needs to be initially set to narrow to determine the
851da177e4SLinus Torvalds  * actual firmware width. */
869f5989d7SHelge Deller int parisc_narrow_firmware __ro_after_init = NARROW_FIRMWARE;
871da177e4SLinus Torvalds #endif
881da177e4SLinus Torvalds 
89675ec7a5SGrant Grundler /* On most currently-supported platforms, IODC I/O calls are 32-bit calls
90675ec7a5SGrant Grundler  * and MEM_PDC calls are always the same width as the OS.
91675ec7a5SGrant Grundler  * Some PAT boxes may have 64-bit IODC I/O.
921da177e4SLinus Torvalds  *
93675ec7a5SGrant Grundler  * Ryan Bradetich added the now obsolete CONFIG_PDC_NARROW to allow
94675ec7a5SGrant Grundler  * 64-bit kernels to run on systems with 32-bit MEM_PDC calls.
95675ec7a5SGrant Grundler  * This allowed wide kernels to run on Cxxx boxes.
96675ec7a5SGrant Grundler  * We now detect 32-bit-only PDC and dynamically switch to 32-bit mode
97675ec7a5SGrant Grundler  * when running a 64-bit kernel on such boxes (e.g. C200 or C360).
981da177e4SLinus Torvalds  */
991da177e4SLinus Torvalds 
100a8f44e38SHelge Deller #ifdef CONFIG_64BIT
1011da177e4SLinus Torvalds long real64_call(unsigned long function, ...);
1021da177e4SLinus Torvalds #endif
1031da177e4SLinus Torvalds long real32_call(unsigned long function, ...);
1041da177e4SLinus Torvalds 
105a8f44e38SHelge Deller #ifdef CONFIG_64BIT
1061da177e4SLinus Torvalds #   define MEM_PDC (unsigned long)(PAGE0->mem_pdc_hi) << 32 | PAGE0->mem_pdc
1071da177e4SLinus Torvalds #   define mem_pdc_call(args...) unlikely(parisc_narrow_firmware) ? real32_call(MEM_PDC, args) : real64_call(MEM_PDC, args)
1081da177e4SLinus Torvalds #else
1091da177e4SLinus Torvalds #   define MEM_PDC (unsigned long)PAGE0->mem_pdc
1101da177e4SLinus Torvalds #   define mem_pdc_call(args...) real32_call(MEM_PDC, args)
1111da177e4SLinus Torvalds #endif
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds /**
1151da177e4SLinus Torvalds  * f_extend - Convert PDC addresses to kernel addresses.
1161da177e4SLinus Torvalds  * @address: Address returned from PDC.
1171da177e4SLinus Torvalds  *
1181da177e4SLinus Torvalds  * This function is used to convert PDC addresses into kernel addresses
1191da177e4SLinus Torvalds  * when the PDC address size and kernel address size are different.
1201da177e4SLinus Torvalds  */
f_extend(unsigned long address)1211da177e4SLinus Torvalds static unsigned long f_extend(unsigned long address)
1221da177e4SLinus Torvalds {
123a8f44e38SHelge Deller #ifdef CONFIG_64BIT
1241da177e4SLinus Torvalds 	if(unlikely(parisc_narrow_firmware)) {
1251da177e4SLinus Torvalds 		if((address & 0xff000000) == 0xf0000000)
126*735ae74fSHelge Deller 			return (0xfffffff0UL << 32) | (u32)address;
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds 		if((address & 0xf0000000) == 0xf0000000)
129*735ae74fSHelge Deller 			return (0xffffffffUL << 32) | (u32)address;
1301da177e4SLinus Torvalds 	}
1311da177e4SLinus Torvalds #endif
1321da177e4SLinus Torvalds 	return address;
1331da177e4SLinus Torvalds }
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds /**
1361da177e4SLinus Torvalds  * convert_to_wide - Convert the return buffer addresses into kernel addresses.
13742758522SHelge Deller  * @addr: The return buffer from PDC.
1381da177e4SLinus Torvalds  *
1391da177e4SLinus Torvalds  * This function is used to convert the return buffer addresses retrieved from PDC
1401da177e4SLinus Torvalds  * into kernel addresses when the PDC address size and kernel address size are
1411da177e4SLinus Torvalds  * different.
1421da177e4SLinus Torvalds  */
convert_to_wide(unsigned long * addr)1431da177e4SLinus Torvalds static void convert_to_wide(unsigned long *addr)
1441da177e4SLinus Torvalds {
145a8f44e38SHelge Deller #ifdef CONFIG_64BIT
1461da177e4SLinus Torvalds 	int i;
1471da177e4SLinus Torvalds 	unsigned int *p = (unsigned int *)addr;
1481da177e4SLinus Torvalds 
1491da177e4SLinus Torvalds 	if (unlikely(parisc_narrow_firmware)) {
1508a5aa00eSHelge Deller 		for (i = (NUM_PDC_RESULT-1); i >= 0; --i)
1511da177e4SLinus Torvalds 			addr[i] = p[i];
1521da177e4SLinus Torvalds 	}
1531da177e4SLinus Torvalds #endif
1541da177e4SLinus Torvalds }
1551da177e4SLinus Torvalds 
156a8f44e38SHelge Deller #ifdef CONFIG_64BIT
set_firmware_width_unlocked(void)15760ffef06SPaul Gortmaker void set_firmware_width_unlocked(void)
15824b574d0SKyle McMartin {
15924b574d0SKyle McMartin 	int ret;
1601da177e4SLinus Torvalds 
16124b574d0SKyle McMartin 	ret = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES,
16224b574d0SKyle McMartin 		__pa(pdc_result), 0);
16342758522SHelge Deller 	if (ret < 0)
16442758522SHelge Deller 		return;
1651da177e4SLinus Torvalds 	convert_to_wide(pdc_result);
1661da177e4SLinus Torvalds 	if (pdc_result[0] != NARROW_FIRMWARE)
1671da177e4SLinus Torvalds 		parisc_narrow_firmware = 0;
1681da177e4SLinus Torvalds }
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds /**
17124b574d0SKyle McMartin  * set_firmware_width - Determine if the firmware is wide or narrow.
17224b574d0SKyle McMartin  *
17324b574d0SKyle McMartin  * This function must be called before any pdc_* function that uses the
17424b574d0SKyle McMartin  * convert_to_wide function.
17524b574d0SKyle McMartin  */
set_firmware_width(void)17660ffef06SPaul Gortmaker void set_firmware_width(void)
17724b574d0SKyle McMartin {
17824b574d0SKyle McMartin 	unsigned long flags;
1791e93848aSHelge Deller 
1801e93848aSHelge Deller 	/* already initialized? */
1819f5989d7SHelge Deller 	if (parisc_narrow_firmware != NARROW_FIRMWARE)
1821e93848aSHelge Deller 		return;
1831e93848aSHelge Deller 
18424b574d0SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
18524b574d0SKyle McMartin 	set_firmware_width_unlocked();
18624b574d0SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
18724b574d0SKyle McMartin }
18824b574d0SKyle McMartin #else
set_firmware_width_unlocked(void)18960ffef06SPaul Gortmaker void set_firmware_width_unlocked(void)
19060ffef06SPaul Gortmaker {
19124b574d0SKyle McMartin 	return;
19224b574d0SKyle McMartin }
19324b574d0SKyle McMartin 
set_firmware_width(void)19460ffef06SPaul Gortmaker void set_firmware_width(void)
19560ffef06SPaul Gortmaker {
19624b574d0SKyle McMartin 	return;
19724b574d0SKyle McMartin }
19824b574d0SKyle McMartin #endif /*CONFIG_64BIT*/
19924b574d0SKyle McMartin 
200f5213b2cSHelge Deller 
201f5213b2cSHelge Deller #if !defined(BOOTLOADER)
20224b574d0SKyle McMartin /**
2031da177e4SLinus Torvalds  * pdc_emergency_unlock - Unlock the linux pdc lock
2041da177e4SLinus Torvalds  *
2051da177e4SLinus Torvalds  * This call unlocks the linux pdc lock in case we need some PDC functions
2061da177e4SLinus Torvalds  * (like pdc_add_valid) during kernel stack dump.
2071da177e4SLinus Torvalds  */
pdc_emergency_unlock(void)2081da177e4SLinus Torvalds void pdc_emergency_unlock(void)
2091da177e4SLinus Torvalds {
2101da177e4SLinus Torvalds  	/* Spinlock DEBUG code freaks out if we unconditionally unlock */
2111da177e4SLinus Torvalds         if (spin_is_locked(&pdc_lock))
2121da177e4SLinus Torvalds 		spin_unlock(&pdc_lock);
2131da177e4SLinus Torvalds }
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds /**
2171da177e4SLinus Torvalds  * pdc_add_valid - Verify address can be accessed without causing a HPMC.
2181da177e4SLinus Torvalds  * @address: Address to be verified.
2191da177e4SLinus Torvalds  *
2201da177e4SLinus Torvalds  * This PDC call attempts to read from the specified address and verifies
2211da177e4SLinus Torvalds  * if the address is valid.
2221da177e4SLinus Torvalds  *
2231da177e4SLinus Torvalds  * The return value is PDC_OK (0) in case accessing this address is valid.
2241da177e4SLinus Torvalds  */
pdc_add_valid(unsigned long address)2251da177e4SLinus Torvalds int pdc_add_valid(unsigned long address)
2261da177e4SLinus Torvalds {
2271da177e4SLinus Torvalds         int retval;
22809690b18SKyle McMartin 	unsigned long flags;
2291da177e4SLinus Torvalds 
23009690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
2311da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_ADD_VALID, PDC_ADD_VALID_VERIFY, address);
23209690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds         return retval;
2351da177e4SLinus Torvalds }
2361da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_add_valid);
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds /**
23977089c52SHelge Deller  * pdc_instr - Get instruction that invokes PDCE_CHECK in HPMC handler.
24077089c52SHelge Deller  * @instr: Pointer to variable which will get instruction opcode.
24177089c52SHelge Deller  *
24277089c52SHelge Deller  * The return value is PDC_OK (0) in case call succeeded.
24377089c52SHelge Deller  */
pdc_instr(unsigned int * instr)24477089c52SHelge Deller int __init pdc_instr(unsigned int *instr)
24577089c52SHelge Deller {
24677089c52SHelge Deller 	int retval;
24777089c52SHelge Deller 	unsigned long flags;
24877089c52SHelge Deller 
24977089c52SHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
25077089c52SHelge Deller 	retval = mem_pdc_call(PDC_INSTR, 0UL, __pa(pdc_result));
25177089c52SHelge Deller 	convert_to_wide(pdc_result);
25277089c52SHelge Deller 	*instr = pdc_result[0];
25377089c52SHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
25477089c52SHelge Deller 
25577089c52SHelge Deller 	return retval;
25677089c52SHelge Deller }
25777089c52SHelge Deller 
25877089c52SHelge Deller /**
2591da177e4SLinus Torvalds  * pdc_chassis_info - Return chassis information.
2601da177e4SLinus Torvalds  * @chassis_info: The memory buffer address.
26142758522SHelge Deller  * @led_info: The size of the memory buffer address.
2621da177e4SLinus Torvalds  * @len: The size of the memory buffer address.
2631da177e4SLinus Torvalds  *
2641da177e4SLinus Torvalds  * An HVERSION dependent call for returning the chassis information.
2651da177e4SLinus Torvalds  */
pdc_chassis_info(struct pdc_chassis_info * chassis_info,void * led_info,unsigned long len)2661da177e4SLinus Torvalds int __init pdc_chassis_info(struct pdc_chassis_info *chassis_info, void *led_info, unsigned long len)
2671da177e4SLinus Torvalds {
2681da177e4SLinus Torvalds         int retval;
26909690b18SKyle McMartin 	unsigned long flags;
2701da177e4SLinus Torvalds 
27109690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
2721da177e4SLinus Torvalds         memcpy(&pdc_result, chassis_info, sizeof(*chassis_info));
2731da177e4SLinus Torvalds         memcpy(&pdc_result2, led_info, len);
2741da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_CHASSIS, PDC_RETURN_CHASSIS_INFO,
2751da177e4SLinus Torvalds                               __pa(pdc_result), __pa(pdc_result2), len);
2761da177e4SLinus Torvalds         memcpy(chassis_info, pdc_result, sizeof(*chassis_info));
2771da177e4SLinus Torvalds         memcpy(led_info, pdc_result2, len);
27809690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
2791da177e4SLinus Torvalds 
2801da177e4SLinus Torvalds         return retval;
2811da177e4SLinus Torvalds }
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds /**
2841da177e4SLinus Torvalds  * pdc_pat_chassis_send_log - Sends a PDC PAT CHASSIS log message.
28542758522SHelge Deller  * @state: state of the machine
28642758522SHelge Deller  * @data: value for that state
2871da177e4SLinus Torvalds  *
2881da177e4SLinus Torvalds  * Must be correctly formatted or expect system crash
2891da177e4SLinus Torvalds  */
290a8f44e38SHelge Deller #ifdef CONFIG_64BIT
pdc_pat_chassis_send_log(unsigned long state,unsigned long data)2911da177e4SLinus Torvalds int pdc_pat_chassis_send_log(unsigned long state, unsigned long data)
2921da177e4SLinus Torvalds {
2931da177e4SLinus Torvalds 	int retval = 0;
29409690b18SKyle McMartin 	unsigned long flags;
2951da177e4SLinus Torvalds 
2961da177e4SLinus Torvalds 	if (!is_pdc_pat())
2971da177e4SLinus Torvalds 		return -1;
2981da177e4SLinus Torvalds 
29909690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
3001da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PAT_CHASSIS_LOG, PDC_PAT_CHASSIS_WRITE_LOG, __pa(&state), __pa(&data));
30109690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds 	return retval;
3041da177e4SLinus Torvalds }
3051da177e4SLinus Torvalds #endif
3061da177e4SLinus Torvalds 
3071da177e4SLinus Torvalds /**
3088ffaeaf4SThibaut Varene  * pdc_chassis_disp - Updates chassis code
30942758522SHelge Deller  * @disp: value to show on display
3101da177e4SLinus Torvalds  */
pdc_chassis_disp(unsigned long disp)3111da177e4SLinus Torvalds int pdc_chassis_disp(unsigned long disp)
3121da177e4SLinus Torvalds {
3131da177e4SLinus Torvalds 	int retval = 0;
31409690b18SKyle McMartin 	unsigned long flags;
3151da177e4SLinus Torvalds 
31609690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
3171da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_DISP, disp);
31809690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
3191da177e4SLinus Torvalds 
3201da177e4SLinus Torvalds 	return retval;
3211da177e4SLinus Torvalds }
3221da177e4SLinus Torvalds 
3231da177e4SLinus Torvalds /**
32442758522SHelge Deller  * __pdc_cpu_rendezvous - Stop currently executing CPU and do not return.
325507efd63SSven Schnelle  */
__pdc_cpu_rendezvous(void)326507efd63SSven Schnelle int __pdc_cpu_rendezvous(void)
327507efd63SSven Schnelle {
328507efd63SSven Schnelle 	if (is_pdc_pat())
329507efd63SSven Schnelle 		return mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_RENDEZVOUS);
330507efd63SSven Schnelle 	else
331507efd63SSven Schnelle 		return mem_pdc_call(PDC_PROC, 1, 0);
332507efd63SSven Schnelle }
333507efd63SSven Schnelle 
334db2b0d76SHelge Deller /**
335db2b0d76SHelge Deller  * pdc_cpu_rendezvous_lock - Lock PDC while transitioning to rendezvous state
336db2b0d76SHelge Deller  */
pdc_cpu_rendezvous_lock(void)337a07c03e8SHelge Deller void pdc_cpu_rendezvous_lock(void) __acquires(&pdc_lock)
338db2b0d76SHelge Deller {
339db2b0d76SHelge Deller 	spin_lock(&pdc_lock);
340db2b0d76SHelge Deller }
341507efd63SSven Schnelle 
342507efd63SSven Schnelle /**
343db2b0d76SHelge Deller  * pdc_cpu_rendezvous_unlock - Unlock PDC after reaching rendezvous state
344db2b0d76SHelge Deller  */
pdc_cpu_rendezvous_unlock(void)345a07c03e8SHelge Deller void pdc_cpu_rendezvous_unlock(void) __releases(&pdc_lock)
346db2b0d76SHelge Deller {
347db2b0d76SHelge Deller 	spin_unlock(&pdc_lock);
348db2b0d76SHelge Deller }
349db2b0d76SHelge Deller 
350db2b0d76SHelge Deller /**
351db2b0d76SHelge Deller  * pdc_pat_get_PDC_entrypoint - Get PDC entry point for current CPU
35242758522SHelge Deller  * @pdc_entry: pointer to where the PDC entry point should be stored
353db2b0d76SHelge Deller  */
pdc_pat_get_PDC_entrypoint(unsigned long * pdc_entry)354db2b0d76SHelge Deller int pdc_pat_get_PDC_entrypoint(unsigned long *pdc_entry)
355db2b0d76SHelge Deller {
356db2b0d76SHelge Deller 	int retval = 0;
357db2b0d76SHelge Deller 	unsigned long flags;
358db2b0d76SHelge Deller 
359db2b0d76SHelge Deller 	if (!IS_ENABLED(CONFIG_SMP) || !is_pdc_pat()) {
360db2b0d76SHelge Deller 		*pdc_entry = MEM_PDC;
361db2b0d76SHelge Deller 		return 0;
362db2b0d76SHelge Deller 	}
363db2b0d76SHelge Deller 
364db2b0d76SHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
365db2b0d76SHelge Deller 	retval = mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_GET_PDC_ENTRYPOINT,
366db2b0d76SHelge Deller 			__pa(pdc_result));
367db2b0d76SHelge Deller 	*pdc_entry = pdc_result[0];
368db2b0d76SHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
369db2b0d76SHelge Deller 
370db2b0d76SHelge Deller 	return retval;
371db2b0d76SHelge Deller }
372db2b0d76SHelge Deller /**
3738ffaeaf4SThibaut Varene  * pdc_chassis_warn - Fetches chassis warnings
37442758522SHelge Deller  * @warn: The warning value to be shown
3758ffaeaf4SThibaut Varene  */
pdc_chassis_warn(unsigned long * warn)3768ffaeaf4SThibaut Varene int pdc_chassis_warn(unsigned long *warn)
3778ffaeaf4SThibaut Varene {
3788ffaeaf4SThibaut Varene 	int retval = 0;
37909690b18SKyle McMartin 	unsigned long flags;
3808ffaeaf4SThibaut Varene 
38109690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
3828ffaeaf4SThibaut Varene 	retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_WARN, __pa(pdc_result));
3838ffaeaf4SThibaut Varene 	*warn = pdc_result[0];
38409690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
3858ffaeaf4SThibaut Varene 
3868ffaeaf4SThibaut Varene 	return retval;
3878ffaeaf4SThibaut Varene }
3888ffaeaf4SThibaut Varene 
pdc_coproc_cfg_unlocked(struct pdc_coproc_cfg * pdc_coproc_info)38960ffef06SPaul Gortmaker int pdc_coproc_cfg_unlocked(struct pdc_coproc_cfg *pdc_coproc_info)
39024b574d0SKyle McMartin {
39124b574d0SKyle McMartin 	int ret;
39224b574d0SKyle McMartin 
39324b574d0SKyle McMartin 	ret = mem_pdc_call(PDC_COPROC, PDC_COPROC_CFG, __pa(pdc_result));
39424b574d0SKyle McMartin 	convert_to_wide(pdc_result);
39524b574d0SKyle McMartin 	pdc_coproc_info->ccr_functional = pdc_result[0];
39624b574d0SKyle McMartin 	pdc_coproc_info->ccr_present = pdc_result[1];
39724b574d0SKyle McMartin 	pdc_coproc_info->revision = pdc_result[17];
39824b574d0SKyle McMartin 	pdc_coproc_info->model = pdc_result[18];
39924b574d0SKyle McMartin 
40024b574d0SKyle McMartin 	return ret;
40124b574d0SKyle McMartin }
40224b574d0SKyle McMartin 
4038ffaeaf4SThibaut Varene /**
4041da177e4SLinus Torvalds  * pdc_coproc_cfg - To identify coprocessors attached to the processor.
4051da177e4SLinus Torvalds  * @pdc_coproc_info: Return buffer address.
4061da177e4SLinus Torvalds  *
4071da177e4SLinus Torvalds  * This PDC call returns the presence and status of all the coprocessors
4081da177e4SLinus Torvalds  * attached to the processor.
4091da177e4SLinus Torvalds  */
pdc_coproc_cfg(struct pdc_coproc_cfg * pdc_coproc_info)41060ffef06SPaul Gortmaker int pdc_coproc_cfg(struct pdc_coproc_cfg *pdc_coproc_info)
4111da177e4SLinus Torvalds {
41224b574d0SKyle McMartin 	int ret;
41309690b18SKyle McMartin 	unsigned long flags;
4141da177e4SLinus Torvalds 
41509690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
41624b574d0SKyle McMartin 	ret = pdc_coproc_cfg_unlocked(pdc_coproc_info);
41709690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
4181da177e4SLinus Torvalds 
41924b574d0SKyle McMartin 	return ret;
4201da177e4SLinus Torvalds }
4211da177e4SLinus Torvalds 
4221da177e4SLinus Torvalds /**
4231da177e4SLinus Torvalds  * pdc_iodc_read - Read data from the modules IODC.
4241da177e4SLinus Torvalds  * @actcnt: The actual number of bytes.
4251da177e4SLinus Torvalds  * @hpa: The HPA of the module for the iodc read.
4261da177e4SLinus Torvalds  * @index: The iodc entry point.
4271da177e4SLinus Torvalds  * @iodc_data: A buffer memory for the iodc options.
4281da177e4SLinus Torvalds  * @iodc_data_size: Size of the memory buffer.
4291da177e4SLinus Torvalds  *
4301da177e4SLinus Torvalds  * This PDC call reads from the IODC of the module specified by the hpa
4311da177e4SLinus Torvalds  * argument.
4321da177e4SLinus Torvalds  */
pdc_iodc_read(unsigned long * actcnt,unsigned long hpa,unsigned int index,void * iodc_data,unsigned int iodc_data_size)4331da177e4SLinus Torvalds int pdc_iodc_read(unsigned long *actcnt, unsigned long hpa, unsigned int index,
4341da177e4SLinus Torvalds 		  void *iodc_data, unsigned int iodc_data_size)
4351da177e4SLinus Torvalds {
4361da177e4SLinus Torvalds 	int retval;
43709690b18SKyle McMartin 	unsigned long flags;
4381da177e4SLinus Torvalds 
43909690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
4401da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_IODC, PDC_IODC_READ, __pa(pdc_result), hpa,
4411da177e4SLinus Torvalds 			      index, __pa(pdc_result2), iodc_data_size);
4421da177e4SLinus Torvalds 	convert_to_wide(pdc_result);
4431da177e4SLinus Torvalds 	*actcnt = pdc_result[0];
4441da177e4SLinus Torvalds 	memcpy(iodc_data, pdc_result2, iodc_data_size);
44509690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
4461da177e4SLinus Torvalds 
4471da177e4SLinus Torvalds 	return retval;
4481da177e4SLinus Torvalds }
4491da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_iodc_read);
4501da177e4SLinus Torvalds 
4511da177e4SLinus Torvalds /**
4521da177e4SLinus Torvalds  * pdc_system_map_find_mods - Locate unarchitected modules.
4531da177e4SLinus Torvalds  * @pdc_mod_info: Return buffer address.
4541da177e4SLinus Torvalds  * @mod_path: pointer to dev path structure.
4551da177e4SLinus Torvalds  * @mod_index: fixed address module index.
4561da177e4SLinus Torvalds  *
4571da177e4SLinus Torvalds  * To locate and identify modules which reside at fixed I/O addresses, which
4581da177e4SLinus Torvalds  * do not self-identify via architected bus walks.
4591da177e4SLinus Torvalds  */
pdc_system_map_find_mods(struct pdc_system_map_mod_info * pdc_mod_info,struct pdc_module_path * mod_path,long mod_index)4601da177e4SLinus Torvalds int pdc_system_map_find_mods(struct pdc_system_map_mod_info *pdc_mod_info,
4611da177e4SLinus Torvalds 			     struct pdc_module_path *mod_path, long mod_index)
4621da177e4SLinus Torvalds {
4631da177e4SLinus Torvalds 	int retval;
46409690b18SKyle McMartin 	unsigned long flags;
4651da177e4SLinus Torvalds 
46609690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
4671da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_MODULE, __pa(pdc_result),
4681da177e4SLinus Torvalds 			      __pa(pdc_result2), mod_index);
4691da177e4SLinus Torvalds 	convert_to_wide(pdc_result);
4701da177e4SLinus Torvalds 	memcpy(pdc_mod_info, pdc_result, sizeof(*pdc_mod_info));
4711da177e4SLinus Torvalds 	memcpy(mod_path, pdc_result2, sizeof(*mod_path));
47209690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
4731da177e4SLinus Torvalds 
4741da177e4SLinus Torvalds 	pdc_mod_info->mod_addr = f_extend(pdc_mod_info->mod_addr);
4751da177e4SLinus Torvalds 	return retval;
4761da177e4SLinus Torvalds }
4771da177e4SLinus Torvalds 
4781da177e4SLinus Torvalds /**
4791da177e4SLinus Torvalds  * pdc_system_map_find_addrs - Retrieve additional address ranges.
4801da177e4SLinus Torvalds  * @pdc_addr_info: Return buffer address.
4811da177e4SLinus Torvalds  * @mod_index: Fixed address module index.
4821da177e4SLinus Torvalds  * @addr_index: Address range index.
4831da177e4SLinus Torvalds  *
4841da177e4SLinus Torvalds  * Retrieve additional information about subsequent address ranges for modules
4851da177e4SLinus Torvalds  * with multiple address ranges.
4861da177e4SLinus Torvalds  */
pdc_system_map_find_addrs(struct pdc_system_map_addr_info * pdc_addr_info,long mod_index,long addr_index)4871da177e4SLinus Torvalds int pdc_system_map_find_addrs(struct pdc_system_map_addr_info *pdc_addr_info,
4881da177e4SLinus Torvalds 			      long mod_index, long addr_index)
4891da177e4SLinus Torvalds {
4901da177e4SLinus Torvalds 	int retval;
49109690b18SKyle McMartin 	unsigned long flags;
4921da177e4SLinus Torvalds 
49309690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
4941da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_ADDRESS, __pa(pdc_result),
4951da177e4SLinus Torvalds 			      mod_index, addr_index);
4961da177e4SLinus Torvalds 	convert_to_wide(pdc_result);
4971da177e4SLinus Torvalds 	memcpy(pdc_addr_info, pdc_result, sizeof(*pdc_addr_info));
49809690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
4991da177e4SLinus Torvalds 
5001da177e4SLinus Torvalds 	pdc_addr_info->mod_addr = f_extend(pdc_addr_info->mod_addr);
5011da177e4SLinus Torvalds 	return retval;
5021da177e4SLinus Torvalds }
5031da177e4SLinus Torvalds 
5041da177e4SLinus Torvalds /**
5051da177e4SLinus Torvalds  * pdc_model_info - Return model information about the processor.
5061da177e4SLinus Torvalds  * @model: The return buffer.
5071da177e4SLinus Torvalds  *
5081da177e4SLinus Torvalds  * Returns the version numbers, identifiers, and capabilities from the processor module.
5091da177e4SLinus Torvalds  */
pdc_model_info(struct pdc_model * model)5101da177e4SLinus Torvalds int pdc_model_info(struct pdc_model *model)
5111da177e4SLinus Torvalds {
5121da177e4SLinus Torvalds 	int retval;
51309690b18SKyle McMartin 	unsigned long flags;
5141da177e4SLinus Torvalds 
51509690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
5161da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_INFO, __pa(pdc_result), 0);
5171da177e4SLinus Torvalds 	convert_to_wide(pdc_result);
5181da177e4SLinus Torvalds 	memcpy(model, pdc_result, sizeof(*model));
51909690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
5201da177e4SLinus Torvalds 
5211da177e4SLinus Torvalds 	return retval;
5221da177e4SLinus Torvalds }
5231da177e4SLinus Torvalds 
5241da177e4SLinus Torvalds /**
5251da177e4SLinus Torvalds  * pdc_model_sysmodel - Get the system model name.
52642758522SHelge Deller  * @os_id: The operating system ID asked for (an OS_ID_* value)
5271da177e4SLinus Torvalds  * @name: A char array of at least 81 characters.
5281da177e4SLinus Torvalds  *
529ec1fdc24SKyle McMartin  * Get system model name from PDC ROM (e.g. 9000/715 or 9000/778/B160L).
530ec1fdc24SKyle McMartin  * Using OS_ID_HPUX will return the equivalent of the 'modelname' command
531ec1fdc24SKyle McMartin  * on HP/UX.
5321da177e4SLinus Torvalds  */
pdc_model_sysmodel(unsigned int os_id,char * name)5334934fbfbSHelge Deller int pdc_model_sysmodel(unsigned int os_id, char *name)
5341da177e4SLinus Torvalds {
5351da177e4SLinus Torvalds         int retval;
53609690b18SKyle McMartin 	unsigned long flags;
5371da177e4SLinus Torvalds 
53809690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
5391da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_SYSMODEL, __pa(pdc_result),
5404934fbfbSHelge Deller                               os_id, __pa(name));
5411da177e4SLinus Torvalds         convert_to_wide(pdc_result);
5421da177e4SLinus Torvalds 
5431da177e4SLinus Torvalds         if (retval == PDC_OK) {
5441da177e4SLinus Torvalds                 name[pdc_result[0]] = '\0'; /* add trailing '\0' */
5451da177e4SLinus Torvalds         } else {
5461da177e4SLinus Torvalds                 name[0] = 0;
5471da177e4SLinus Torvalds         }
54809690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
5491da177e4SLinus Torvalds 
5501da177e4SLinus Torvalds         return retval;
5511da177e4SLinus Torvalds }
5521da177e4SLinus Torvalds 
5531da177e4SLinus Torvalds /**
5541da177e4SLinus Torvalds  * pdc_model_versions - Identify the version number of each processor.
55542758522SHelge Deller  * @versions: The return buffer.
5561da177e4SLinus Torvalds  * @id: The id of the processor to check.
5571da177e4SLinus Torvalds  *
5581da177e4SLinus Torvalds  * Returns the version number for each processor component.
5591da177e4SLinus Torvalds  *
5601da177e4SLinus Torvalds  * This comment was here before, but I do not know what it means :( -RB
5611da177e4SLinus Torvalds  * id: 0 = cpu revision, 1 = boot-rom-version
5621da177e4SLinus Torvalds  */
pdc_model_versions(unsigned long * versions,int id)5631da177e4SLinus Torvalds int pdc_model_versions(unsigned long *versions, int id)
5641da177e4SLinus Torvalds {
5651da177e4SLinus Torvalds         int retval;
56609690b18SKyle McMartin 	unsigned long flags;
5671da177e4SLinus Torvalds 
56809690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
5691da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_VERSIONS, __pa(pdc_result), id);
5701da177e4SLinus Torvalds         convert_to_wide(pdc_result);
5711da177e4SLinus Torvalds         *versions = pdc_result[0];
57209690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
5731da177e4SLinus Torvalds 
5741da177e4SLinus Torvalds         return retval;
5751da177e4SLinus Torvalds }
5761da177e4SLinus Torvalds 
5771da177e4SLinus Torvalds /**
5781da177e4SLinus Torvalds  * pdc_model_cpuid - Returns the CPU_ID.
5791da177e4SLinus Torvalds  * @cpu_id: The return buffer.
5801da177e4SLinus Torvalds  *
5811da177e4SLinus Torvalds  * Returns the CPU_ID value which uniquely identifies the cpu portion of
5821da177e4SLinus Torvalds  * the processor module.
5831da177e4SLinus Torvalds  */
pdc_model_cpuid(unsigned long * cpu_id)5841da177e4SLinus Torvalds int pdc_model_cpuid(unsigned long *cpu_id)
5851da177e4SLinus Torvalds {
5861da177e4SLinus Torvalds         int retval;
58709690b18SKyle McMartin 	unsigned long flags;
5881da177e4SLinus Torvalds 
58909690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
5901da177e4SLinus Torvalds         pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
5911da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CPU_ID, __pa(pdc_result), 0);
5921da177e4SLinus Torvalds         convert_to_wide(pdc_result);
5931da177e4SLinus Torvalds         *cpu_id = pdc_result[0];
59409690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
5951da177e4SLinus Torvalds 
5961da177e4SLinus Torvalds         return retval;
5971da177e4SLinus Torvalds }
5981da177e4SLinus Torvalds 
5991da177e4SLinus Torvalds /**
6001da177e4SLinus Torvalds  * pdc_model_capabilities - Returns the platform capabilities.
6011da177e4SLinus Torvalds  * @capabilities: The return buffer.
6021da177e4SLinus Torvalds  *
6031da177e4SLinus Torvalds  * Returns information about platform support for 32- and/or 64-bit
6041da177e4SLinus Torvalds  * OSes, IO-PDIR coherency, and virtual aliasing.
6051da177e4SLinus Torvalds  */
pdc_model_capabilities(unsigned long * capabilities)6061da177e4SLinus Torvalds int pdc_model_capabilities(unsigned long *capabilities)
6071da177e4SLinus Torvalds {
6081da177e4SLinus Torvalds         int retval;
60909690b18SKyle McMartin 	unsigned long flags;
6101da177e4SLinus Torvalds 
61109690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
6121da177e4SLinus Torvalds         pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
6131da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES, __pa(pdc_result), 0);
6141da177e4SLinus Torvalds         convert_to_wide(pdc_result);
615445c088fSColin Watson         if (retval == PDC_OK) {
6161da177e4SLinus Torvalds                 *capabilities = pdc_result[0];
617445c088fSColin Watson         } else {
618445c088fSColin Watson                 *capabilities = PDC_MODEL_OS32;
619445c088fSColin Watson         }
62009690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
6211da177e4SLinus Torvalds 
6221da177e4SLinus Torvalds         return retval;
6231da177e4SLinus Torvalds }
6241da177e4SLinus Torvalds 
6251da177e4SLinus Torvalds /**
6268207d4eeSHelge Deller  * pdc_model_platform_info - Returns machine product and serial number.
6278207d4eeSHelge Deller  * @orig_prod_num: Return buffer for original product number.
6288207d4eeSHelge Deller  * @current_prod_num: Return buffer for current product number.
6298207d4eeSHelge Deller  * @serial_no: Return buffer for serial number.
6308207d4eeSHelge Deller  *
6318207d4eeSHelge Deller  * Returns strings containing the original and current product numbers and the
6328207d4eeSHelge Deller  * serial number of the system.
6338207d4eeSHelge Deller  */
pdc_model_platform_info(char * orig_prod_num,char * current_prod_num,char * serial_no)6348207d4eeSHelge Deller int pdc_model_platform_info(char *orig_prod_num, char *current_prod_num,
6358207d4eeSHelge Deller 		char *serial_no)
6368207d4eeSHelge Deller {
6378207d4eeSHelge Deller 	int retval;
6388207d4eeSHelge Deller 	unsigned long flags;
6398207d4eeSHelge Deller 
6408207d4eeSHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
6418207d4eeSHelge Deller 	retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_GET_PLATFORM_INFO,
6428207d4eeSHelge Deller 		__pa(orig_prod_num), __pa(current_prod_num), __pa(serial_no));
6438207d4eeSHelge Deller 	convert_to_wide(pdc_result);
6448207d4eeSHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
6458207d4eeSHelge Deller 
6468207d4eeSHelge Deller 	return retval;
6478207d4eeSHelge Deller }
6488207d4eeSHelge Deller 
6498207d4eeSHelge Deller /**
6501da177e4SLinus Torvalds  * pdc_cache_info - Return cache and TLB information.
6511da177e4SLinus Torvalds  * @cache_info: The return buffer.
6521da177e4SLinus Torvalds  *
6531da177e4SLinus Torvalds  * Returns information about the processor's cache and TLB.
6541da177e4SLinus Torvalds  */
pdc_cache_info(struct pdc_cache_info * cache_info)6551da177e4SLinus Torvalds int pdc_cache_info(struct pdc_cache_info *cache_info)
6561da177e4SLinus Torvalds {
6571da177e4SLinus Torvalds         int retval;
65809690b18SKyle McMartin 	unsigned long flags;
6591da177e4SLinus Torvalds 
66009690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
6611da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_INFO, __pa(pdc_result), 0);
6621da177e4SLinus Torvalds         convert_to_wide(pdc_result);
6631da177e4SLinus Torvalds         memcpy(cache_info, pdc_result, sizeof(*cache_info));
66409690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
6651da177e4SLinus Torvalds 
6661da177e4SLinus Torvalds         return retval;
6671da177e4SLinus Torvalds }
6681da177e4SLinus Torvalds 
669a9d2d386SKyle McMartin /**
670a9d2d386SKyle McMartin  * pdc_spaceid_bits - Return whether Space ID hashing is turned on.
671a9d2d386SKyle McMartin  * @space_bits: Should be 0, if not, bad mojo!
672a9d2d386SKyle McMartin  *
673a9d2d386SKyle McMartin  * Returns information about Space ID hashing.
674a9d2d386SKyle McMartin  */
pdc_spaceid_bits(unsigned long * space_bits)675a9d2d386SKyle McMartin int pdc_spaceid_bits(unsigned long *space_bits)
676a9d2d386SKyle McMartin {
677a9d2d386SKyle McMartin 	int retval;
67809690b18SKyle McMartin 	unsigned long flags;
679a9d2d386SKyle McMartin 
68009690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
681a9d2d386SKyle McMartin 	pdc_result[0] = 0;
682a9d2d386SKyle McMartin 	retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_RET_SPID, __pa(pdc_result), 0);
683a9d2d386SKyle McMartin 	convert_to_wide(pdc_result);
684a9d2d386SKyle McMartin 	*space_bits = pdc_result[0];
68509690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
686a9d2d386SKyle McMartin 
687a9d2d386SKyle McMartin 	return retval;
688a9d2d386SKyle McMartin }
689a9d2d386SKyle McMartin 
6901da177e4SLinus Torvalds /**
6911da177e4SLinus Torvalds  * pdc_btlb_info - Return block TLB information.
6921da177e4SLinus Torvalds  * @btlb: The return buffer.
6931da177e4SLinus Torvalds  *
6941da177e4SLinus Torvalds  * Returns information about the hardware Block TLB.
6951da177e4SLinus Torvalds  */
pdc_btlb_info(struct pdc_btlb_info * btlb)6961da177e4SLinus Torvalds int pdc_btlb_info(struct pdc_btlb_info *btlb)
6971da177e4SLinus Torvalds {
6981da177e4SLinus Torvalds 	int retval;
69909690b18SKyle McMartin 	unsigned long flags;
7001da177e4SLinus Torvalds 
7013756597aSHelge Deller 	if (IS_ENABLED(CONFIG_PA20))
7023756597aSHelge Deller 		return PDC_BAD_PROC;
7033756597aSHelge Deller 
70409690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
7051da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_INFO, __pa(pdc_result), 0);
7061da177e4SLinus Torvalds 	memcpy(btlb, pdc_result, sizeof(*btlb));
70709690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
7081da177e4SLinus Torvalds 
7091da177e4SLinus Torvalds 	if(retval < 0) {
7101da177e4SLinus Torvalds 		btlb->max_size = 0;
7111da177e4SLinus Torvalds 	}
7121da177e4SLinus Torvalds 	return retval;
713510610f9SHelge Deller }
714510610f9SHelge Deller 
pdc_btlb_insert(unsigned long long vpage,unsigned long physpage,unsigned long len,unsigned long entry_info,unsigned long slot)715510610f9SHelge Deller int pdc_btlb_insert(unsigned long long vpage, unsigned long physpage, unsigned long len,
716510610f9SHelge Deller 		    unsigned long entry_info, unsigned long slot)
717510610f9SHelge Deller {
718510610f9SHelge Deller 	int retval;
719510610f9SHelge Deller 	unsigned long flags;
720510610f9SHelge Deller 
7213756597aSHelge Deller 	if (IS_ENABLED(CONFIG_PA20))
7223756597aSHelge Deller 		return PDC_BAD_PROC;
7233756597aSHelge Deller 
724510610f9SHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
725510610f9SHelge Deller 	retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_INSERT, (unsigned long) (vpage >> 32),
726510610f9SHelge Deller 			      (unsigned long) vpage, physpage, len, entry_info, slot);
727510610f9SHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
728510610f9SHelge Deller 	return retval;
729510610f9SHelge Deller }
730510610f9SHelge Deller 
pdc_btlb_purge_all(void)731510610f9SHelge Deller int pdc_btlb_purge_all(void)
732510610f9SHelge Deller {
733510610f9SHelge Deller 	int retval;
734510610f9SHelge Deller 	unsigned long flags;
735510610f9SHelge Deller 
7363756597aSHelge Deller 	if (IS_ENABLED(CONFIG_PA20))
7373756597aSHelge Deller 		return PDC_BAD_PROC;
7383756597aSHelge Deller 
739510610f9SHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
740510610f9SHelge Deller 	retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_PURGE_ALL);
741510610f9SHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
742510610f9SHelge Deller 	return retval;
7431da177e4SLinus Torvalds }
7441da177e4SLinus Torvalds 
7451da177e4SLinus Torvalds /**
7461da177e4SLinus Torvalds  * pdc_mem_map_hpa - Find fixed module information.
7471da177e4SLinus Torvalds  * @address: The return buffer
7481da177e4SLinus Torvalds  * @mod_path: pointer to dev path structure.
7491da177e4SLinus Torvalds  *
7501da177e4SLinus Torvalds  * This call was developed for S700 workstations to allow the kernel to find
7511da177e4SLinus Torvalds  * the I/O devices (Core I/O). In the future (Kittyhawk and beyond) this
7521da177e4SLinus Torvalds  * call will be replaced (on workstations) by the architected PDC_SYSTEM_MAP
7531da177e4SLinus Torvalds  * call.
7541da177e4SLinus Torvalds  *
7551da177e4SLinus Torvalds  * This call is supported by all existing S700 workstations (up to  Gecko).
7561da177e4SLinus Torvalds  */
pdc_mem_map_hpa(struct pdc_memory_map * address,struct pdc_module_path * mod_path)7571da177e4SLinus Torvalds int pdc_mem_map_hpa(struct pdc_memory_map *address,
7581da177e4SLinus Torvalds 		struct pdc_module_path *mod_path)
7591da177e4SLinus Torvalds {
7601da177e4SLinus Torvalds         int retval;
76109690b18SKyle McMartin 	unsigned long flags;
7621da177e4SLinus Torvalds 
7633756597aSHelge Deller 	if (IS_ENABLED(CONFIG_PA20))
7643756597aSHelge Deller 		return PDC_BAD_PROC;
7653756597aSHelge Deller 
76609690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
7671da177e4SLinus Torvalds         memcpy(pdc_result2, mod_path, sizeof(*mod_path));
7681da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_MEM_MAP, PDC_MEM_MAP_HPA, __pa(pdc_result),
7691da177e4SLinus Torvalds 				__pa(pdc_result2));
7701da177e4SLinus Torvalds         memcpy(address, pdc_result, sizeof(*address));
77109690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
7721da177e4SLinus Torvalds 
7731da177e4SLinus Torvalds         return retval;
7741da177e4SLinus Torvalds }
7751da177e4SLinus Torvalds 
7761da177e4SLinus Torvalds /**
7771da177e4SLinus Torvalds  * pdc_lan_station_id - Get the LAN address.
7781da177e4SLinus Torvalds  * @lan_addr: The return buffer.
7791da177e4SLinus Torvalds  * @hpa: The network device HPA.
7801da177e4SLinus Torvalds  *
7811da177e4SLinus Torvalds  * Get the LAN station address when it is not directly available from the LAN hardware.
7821da177e4SLinus Torvalds  */
pdc_lan_station_id(char * lan_addr,unsigned long hpa)7831da177e4SLinus Torvalds int pdc_lan_station_id(char *lan_addr, unsigned long hpa)
7841da177e4SLinus Torvalds {
7851da177e4SLinus Torvalds 	int retval;
78609690b18SKyle McMartin 	unsigned long flags;
7871da177e4SLinus Torvalds 
78809690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
7891da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_LAN_STATION_ID, PDC_LAN_STATION_ID_READ,
7901da177e4SLinus Torvalds 			__pa(pdc_result), hpa);
7911da177e4SLinus Torvalds 	if (retval < 0) {
7921da177e4SLinus Torvalds 		/* FIXME: else read MAC from NVRAM */
7931da177e4SLinus Torvalds 		memset(lan_addr, 0, PDC_LAN_STATION_ID_SIZE);
7941da177e4SLinus Torvalds 	} else {
7951da177e4SLinus Torvalds 		memcpy(lan_addr, pdc_result, PDC_LAN_STATION_ID_SIZE);
7961da177e4SLinus Torvalds 	}
79709690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
7981da177e4SLinus Torvalds 
7991da177e4SLinus Torvalds 	return retval;
8001da177e4SLinus Torvalds }
8011da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_lan_station_id);
8021da177e4SLinus Torvalds 
8031da177e4SLinus Torvalds /**
8041da177e4SLinus Torvalds  * pdc_stable_read - Read data from Stable Storage.
8051da177e4SLinus Torvalds  * @staddr: Stable Storage address to access.
8061da177e4SLinus Torvalds  * @memaddr: The memory address where Stable Storage data shall be copied.
8077022672eSSimon Arlott  * @count: number of bytes to transfer. count is multiple of 4.
8081da177e4SLinus Torvalds  *
8091da177e4SLinus Torvalds  * This PDC call reads from the Stable Storage address supplied in staddr
8101da177e4SLinus Torvalds  * and copies count bytes to the memory address memaddr.
8111da177e4SLinus Torvalds  * The call will fail if staddr+count > PDC_STABLE size.
8121da177e4SLinus Torvalds  */
pdc_stable_read(unsigned long staddr,void * memaddr,unsigned long count)8131da177e4SLinus Torvalds int pdc_stable_read(unsigned long staddr, void *memaddr, unsigned long count)
8141da177e4SLinus Torvalds {
8151da177e4SLinus Torvalds        int retval;
81609690b18SKyle McMartin 	unsigned long flags;
8171da177e4SLinus Torvalds 
81809690b18SKyle McMartin        spin_lock_irqsave(&pdc_lock, flags);
8191da177e4SLinus Torvalds        retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_READ, staddr,
8201da177e4SLinus Torvalds                __pa(pdc_result), count);
8211da177e4SLinus Torvalds        convert_to_wide(pdc_result);
8221da177e4SLinus Torvalds        memcpy(memaddr, pdc_result, count);
82309690b18SKyle McMartin        spin_unlock_irqrestore(&pdc_lock, flags);
8241da177e4SLinus Torvalds 
8251da177e4SLinus Torvalds        return retval;
8261da177e4SLinus Torvalds }
8271da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_stable_read);
8281da177e4SLinus Torvalds 
8291da177e4SLinus Torvalds /**
8301da177e4SLinus Torvalds  * pdc_stable_write - Write data to Stable Storage.
8311da177e4SLinus Torvalds  * @staddr: Stable Storage address to access.
8321da177e4SLinus Torvalds  * @memaddr: The memory address where Stable Storage data shall be read from.
8337022672eSSimon Arlott  * @count: number of bytes to transfer. count is multiple of 4.
8341da177e4SLinus Torvalds  *
8351da177e4SLinus Torvalds  * This PDC call reads count bytes from the supplied memaddr address,
8361da177e4SLinus Torvalds  * and copies count bytes to the Stable Storage address staddr.
8371da177e4SLinus Torvalds  * The call will fail if staddr+count > PDC_STABLE size.
8381da177e4SLinus Torvalds  */
pdc_stable_write(unsigned long staddr,void * memaddr,unsigned long count)8391da177e4SLinus Torvalds int pdc_stable_write(unsigned long staddr, void *memaddr, unsigned long count)
8401da177e4SLinus Torvalds {
8411da177e4SLinus Torvalds        int retval;
84209690b18SKyle McMartin 	unsigned long flags;
8431da177e4SLinus Torvalds 
84409690b18SKyle McMartin        spin_lock_irqsave(&pdc_lock, flags);
8451da177e4SLinus Torvalds        memcpy(pdc_result, memaddr, count);
8461da177e4SLinus Torvalds        convert_to_wide(pdc_result);
8471da177e4SLinus Torvalds        retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_WRITE, staddr,
8481da177e4SLinus Torvalds                __pa(pdc_result), count);
84909690b18SKyle McMartin        spin_unlock_irqrestore(&pdc_lock, flags);
8501da177e4SLinus Torvalds 
8511da177e4SLinus Torvalds        return retval;
8521da177e4SLinus Torvalds }
8531da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_stable_write);
8541da177e4SLinus Torvalds 
8551da177e4SLinus Torvalds /**
8561da177e4SLinus Torvalds  * pdc_stable_get_size - Get Stable Storage size in bytes.
8571da177e4SLinus Torvalds  * @size: pointer where the size will be stored.
8581da177e4SLinus Torvalds  *
8591da177e4SLinus Torvalds  * This PDC call returns the number of bytes in the processor's Stable
8601da177e4SLinus Torvalds  * Storage, which is the number of contiguous bytes implemented in Stable
8611da177e4SLinus Torvalds  * Storage starting from staddr=0. size in an unsigned 64-bit integer
8621da177e4SLinus Torvalds  * which is a multiple of four.
8631da177e4SLinus Torvalds  */
pdc_stable_get_size(unsigned long * size)8641da177e4SLinus Torvalds int pdc_stable_get_size(unsigned long *size)
8651da177e4SLinus Torvalds {
8661da177e4SLinus Torvalds        int retval;
86709690b18SKyle McMartin 	unsigned long flags;
8681da177e4SLinus Torvalds 
86909690b18SKyle McMartin        spin_lock_irqsave(&pdc_lock, flags);
8701da177e4SLinus Torvalds        retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_RETURN_SIZE, __pa(pdc_result));
8711da177e4SLinus Torvalds        *size = pdc_result[0];
87209690b18SKyle McMartin        spin_unlock_irqrestore(&pdc_lock, flags);
8731da177e4SLinus Torvalds 
8741da177e4SLinus Torvalds        return retval;
8751da177e4SLinus Torvalds }
8761da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_stable_get_size);
8771da177e4SLinus Torvalds 
8781da177e4SLinus Torvalds /**
8791da177e4SLinus Torvalds  * pdc_stable_verify_contents - Checks that Stable Storage contents are valid.
8801da177e4SLinus Torvalds  *
8811da177e4SLinus Torvalds  * This PDC call is meant to be used to check the integrity of the current
8821da177e4SLinus Torvalds  * contents of Stable Storage.
8831da177e4SLinus Torvalds  */
pdc_stable_verify_contents(void)8841da177e4SLinus Torvalds int pdc_stable_verify_contents(void)
8851da177e4SLinus Torvalds {
8861da177e4SLinus Torvalds        int retval;
88709690b18SKyle McMartin 	unsigned long flags;
8881da177e4SLinus Torvalds 
88909690b18SKyle McMartin        spin_lock_irqsave(&pdc_lock, flags);
8901da177e4SLinus Torvalds        retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_VERIFY_CONTENTS);
89109690b18SKyle McMartin        spin_unlock_irqrestore(&pdc_lock, flags);
8921da177e4SLinus Torvalds 
8931da177e4SLinus Torvalds        return retval;
8941da177e4SLinus Torvalds }
8951da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_stable_verify_contents);
8961da177e4SLinus Torvalds 
8971da177e4SLinus Torvalds /**
8981da177e4SLinus Torvalds  * pdc_stable_initialize - Sets Stable Storage contents to zero and initialize
8991da177e4SLinus Torvalds  * the validity indicator.
9001da177e4SLinus Torvalds  *
9011da177e4SLinus Torvalds  * This PDC call will erase all contents of Stable Storage. Use with care!
9021da177e4SLinus Torvalds  */
pdc_stable_initialize(void)9031da177e4SLinus Torvalds int pdc_stable_initialize(void)
9041da177e4SLinus Torvalds {
9051da177e4SLinus Torvalds        int retval;
90609690b18SKyle McMartin 	unsigned long flags;
9071da177e4SLinus Torvalds 
90809690b18SKyle McMartin        spin_lock_irqsave(&pdc_lock, flags);
9091da177e4SLinus Torvalds        retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_INITIALIZE);
91009690b18SKyle McMartin        spin_unlock_irqrestore(&pdc_lock, flags);
9111da177e4SLinus Torvalds 
9121da177e4SLinus Torvalds        return retval;
9131da177e4SLinus Torvalds }
9141da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_stable_initialize);
9151da177e4SLinus Torvalds 
9161da177e4SLinus Torvalds /**
9171da177e4SLinus Torvalds  * pdc_get_initiator - Get the SCSI Interface Card params (SCSI ID, SDTR, SE or LVD)
9181da177e4SLinus Torvalds  * @hwpath: fully bc.mod style path to the device.
9191da177e4SLinus Torvalds  * @initiator: the array to return the result into
9201da177e4SLinus Torvalds  *
9211da177e4SLinus Torvalds  * Get the SCSI operational parameters from PDC.
9221da177e4SLinus Torvalds  * Needed since HPUX never used BIOS or symbios card NVRAM.
9231da177e4SLinus Torvalds  * Most ncr/sym cards won't have an entry and just use whatever
9241da177e4SLinus Torvalds  * capabilities of the card are (eg Ultra, LVD). But there are
9251da177e4SLinus Torvalds  * several cases where it's useful:
9261da177e4SLinus Torvalds  *    o set SCSI id for Multi-initiator clusters,
9271da177e4SLinus Torvalds  *    o cable too long (ie SE scsi 10Mhz won't support 6m length),
9281da177e4SLinus Torvalds  *    o bus width exported is less than what the interface chip supports.
9291da177e4SLinus Torvalds  */
pdc_get_initiator(struct hardware_path * hwpath,struct pdc_initiator * initiator)9301da177e4SLinus Torvalds int pdc_get_initiator(struct hardware_path *hwpath, struct pdc_initiator *initiator)
9311da177e4SLinus Torvalds {
9321da177e4SLinus Torvalds 	int retval;
93309690b18SKyle McMartin 	unsigned long flags;
9341da177e4SLinus Torvalds 
93509690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
9361da177e4SLinus Torvalds 
9371da177e4SLinus Torvalds /* BCJ-XXXX series boxes. E.G. "9000/785/C3000" */
9381da177e4SLinus Torvalds #define IS_SPROCKETS() (strlen(boot_cpu_data.pdc.sys_model_name) == 14 && \
9391da177e4SLinus Torvalds 	strncmp(boot_cpu_data.pdc.sys_model_name, "9000/785", 8) == 0)
9401da177e4SLinus Torvalds 
9411da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_INITIATOR, PDC_GET_INITIATOR,
9421da177e4SLinus Torvalds 			      __pa(pdc_result), __pa(hwpath));
9431da177e4SLinus Torvalds 	if (retval < PDC_OK)
9441da177e4SLinus Torvalds 		goto out;
9451da177e4SLinus Torvalds 
9461da177e4SLinus Torvalds 	if (pdc_result[0] < 16) {
9471da177e4SLinus Torvalds 		initiator->host_id = pdc_result[0];
9481da177e4SLinus Torvalds 	} else {
9491da177e4SLinus Torvalds 		initiator->host_id = -1;
9501da177e4SLinus Torvalds 	}
9511da177e4SLinus Torvalds 
9521da177e4SLinus Torvalds 	/*
9531da177e4SLinus Torvalds 	 * Sprockets and Piranha return 20 or 40 (MT/s).  Prelude returns
9541da177e4SLinus Torvalds 	 * 1, 2, 5 or 10 for 5, 10, 20 or 40 MT/s, respectively
9551da177e4SLinus Torvalds 	 */
9561da177e4SLinus Torvalds 	switch (pdc_result[1]) {
9571da177e4SLinus Torvalds 		case  1: initiator->factor = 50; break;
9581da177e4SLinus Torvalds 		case  2: initiator->factor = 25; break;
9591da177e4SLinus Torvalds 		case  5: initiator->factor = 12; break;
9601da177e4SLinus Torvalds 		case 25: initiator->factor = 10; break;
9611da177e4SLinus Torvalds 		case 20: initiator->factor = 12; break;
9621da177e4SLinus Torvalds 		case 40: initiator->factor = 10; break;
9631da177e4SLinus Torvalds 		default: initiator->factor = -1; break;
9641da177e4SLinus Torvalds 	}
9651da177e4SLinus Torvalds 
9661da177e4SLinus Torvalds 	if (IS_SPROCKETS()) {
9671da177e4SLinus Torvalds 		initiator->width = pdc_result[4];
9681da177e4SLinus Torvalds 		initiator->mode = pdc_result[5];
9691da177e4SLinus Torvalds 	} else {
9701da177e4SLinus Torvalds 		initiator->width = -1;
9711da177e4SLinus Torvalds 		initiator->mode = -1;
9721da177e4SLinus Torvalds 	}
9731da177e4SLinus Torvalds 
9741da177e4SLinus Torvalds  out:
97509690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
97609690b18SKyle McMartin 
9771da177e4SLinus Torvalds 	return (retval >= PDC_OK);
9781da177e4SLinus Torvalds }
9791da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_get_initiator);
9801da177e4SLinus Torvalds 
9811da177e4SLinus Torvalds 
9821da177e4SLinus Torvalds /**
9831da177e4SLinus Torvalds  * pdc_pci_irt_size - Get the number of entries in the interrupt routing table.
9841da177e4SLinus Torvalds  * @num_entries: The return value.
9851da177e4SLinus Torvalds  * @hpa: The HPA for the device.
9861da177e4SLinus Torvalds  *
9871da177e4SLinus Torvalds  * This PDC function returns the number of entries in the specified cell's
9881da177e4SLinus Torvalds  * interrupt table.
9891da177e4SLinus Torvalds  * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
9901da177e4SLinus Torvalds  */
pdc_pci_irt_size(unsigned long * num_entries,unsigned long hpa)9911da177e4SLinus Torvalds int pdc_pci_irt_size(unsigned long *num_entries, unsigned long hpa)
9921da177e4SLinus Torvalds {
9931da177e4SLinus Torvalds 	int retval;
99409690b18SKyle McMartin 	unsigned long flags;
9951da177e4SLinus Torvalds 
99609690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
9971da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL_SIZE,
9981da177e4SLinus Torvalds 			      __pa(pdc_result), hpa);
9991da177e4SLinus Torvalds 	convert_to_wide(pdc_result);
10001da177e4SLinus Torvalds 	*num_entries = pdc_result[0];
100109690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
10021da177e4SLinus Torvalds 
10031da177e4SLinus Torvalds 	return retval;
10041da177e4SLinus Torvalds }
10051da177e4SLinus Torvalds 
10061da177e4SLinus Torvalds /**
10071da177e4SLinus Torvalds  * pdc_pci_irt - Get the PCI interrupt routing table.
10081da177e4SLinus Torvalds  * @num_entries: The number of entries in the table.
10091da177e4SLinus Torvalds  * @hpa: The Hard Physical Address of the device.
10101da177e4SLinus Torvalds  * @tbl:
10111da177e4SLinus Torvalds  *
10121da177e4SLinus Torvalds  * Get the PCI interrupt routing table for the device at the given HPA.
10131da177e4SLinus Torvalds  * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
10141da177e4SLinus Torvalds  */
pdc_pci_irt(unsigned long num_entries,unsigned long hpa,void * tbl)10151da177e4SLinus Torvalds int pdc_pci_irt(unsigned long num_entries, unsigned long hpa, void *tbl)
10161da177e4SLinus Torvalds {
10171da177e4SLinus Torvalds 	int retval;
101809690b18SKyle McMartin 	unsigned long flags;
10191da177e4SLinus Torvalds 
10201da177e4SLinus Torvalds 	BUG_ON((unsigned long)tbl & 0x7);
10211da177e4SLinus Torvalds 
102209690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
10231da177e4SLinus Torvalds 	pdc_result[0] = num_entries;
10241da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL,
10251da177e4SLinus Torvalds 			      __pa(pdc_result), hpa, __pa(tbl));
102609690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
10271da177e4SLinus Torvalds 
10281da177e4SLinus Torvalds 	return retval;
10291da177e4SLinus Torvalds }
10301da177e4SLinus Torvalds 
10311da177e4SLinus Torvalds 
10321da177e4SLinus Torvalds #if 0	/* UNTEST CODE - left here in case someone needs it */
10331da177e4SLinus Torvalds 
10341da177e4SLinus Torvalds /**
10351da177e4SLinus Torvalds  * pdc_pci_config_read - read PCI config space.
103642758522SHelge Deller  * @hpa: Token from PDC to indicate which PCI device
103742758522SHelge Deller  * @cfg_addr: Configuration space address to read from
10381da177e4SLinus Torvalds  *
10391da177e4SLinus Torvalds  * Read PCI Configuration space *before* linux PCI subsystem is running.
10401da177e4SLinus Torvalds  */
10411da177e4SLinus Torvalds unsigned int pdc_pci_config_read(void *hpa, unsigned long cfg_addr)
10421da177e4SLinus Torvalds {
10431da177e4SLinus Torvalds 	int retval;
104409690b18SKyle McMartin 	unsigned long flags;
104509690b18SKyle McMartin 
104609690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
10471da177e4SLinus Torvalds 	pdc_result[0] = 0;
10481da177e4SLinus Torvalds 	pdc_result[1] = 0;
10491da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_READ_CONFIG,
10501da177e4SLinus Torvalds 			      __pa(pdc_result), hpa, cfg_addr&~3UL, 4UL);
105109690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
105209690b18SKyle McMartin 
10531da177e4SLinus Torvalds 	return retval ? ~0 : (unsigned int) pdc_result[0];
10541da177e4SLinus Torvalds }
10551da177e4SLinus Torvalds 
10561da177e4SLinus Torvalds 
10571da177e4SLinus Torvalds /**
10581da177e4SLinus Torvalds  * pdc_pci_config_write - read PCI config space.
105942758522SHelge Deller  * @hpa: Token from PDC to indicate which PCI device
106042758522SHelge Deller  * @cfg_addr: Configuration space address to write
106142758522SHelge Deller  * @val: Value we want in the 32-bit register
10621da177e4SLinus Torvalds  *
10631da177e4SLinus Torvalds  * Write PCI Configuration space *before* linux PCI subsystem is running.
10641da177e4SLinus Torvalds  */
10651da177e4SLinus Torvalds void pdc_pci_config_write(void *hpa, unsigned long cfg_addr, unsigned int val)
10661da177e4SLinus Torvalds {
10671da177e4SLinus Torvalds 	int retval;
106809690b18SKyle McMartin 	unsigned long flags;
106909690b18SKyle McMartin 
107009690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
10711da177e4SLinus Torvalds 	pdc_result[0] = 0;
10721da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_WRITE_CONFIG,
10731da177e4SLinus Torvalds 			      __pa(pdc_result), hpa,
10741da177e4SLinus Torvalds 			      cfg_addr&~3UL, 4UL, (unsigned long) val);
107509690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
107609690b18SKyle McMartin 
10771da177e4SLinus Torvalds 	return retval;
10781da177e4SLinus Torvalds }
10791da177e4SLinus Torvalds #endif /* UNTESTED CODE */
10801da177e4SLinus Torvalds 
10811da177e4SLinus Torvalds /**
10821da177e4SLinus Torvalds  * pdc_tod_read - Read the Time-Of-Day clock.
10831da177e4SLinus Torvalds  * @tod: The return buffer:
10841da177e4SLinus Torvalds  *
10851da177e4SLinus Torvalds  * Read the Time-Of-Day clock
10861da177e4SLinus Torvalds  */
pdc_tod_read(struct pdc_tod * tod)10871da177e4SLinus Torvalds int pdc_tod_read(struct pdc_tod *tod)
10881da177e4SLinus Torvalds {
10891da177e4SLinus Torvalds         int retval;
109009690b18SKyle McMartin 	unsigned long flags;
10911da177e4SLinus Torvalds 
109209690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
10931da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_TOD, PDC_TOD_READ, __pa(pdc_result), 0);
10941da177e4SLinus Torvalds         convert_to_wide(pdc_result);
10951da177e4SLinus Torvalds         memcpy(tod, pdc_result, sizeof(*tod));
109609690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
10971da177e4SLinus Torvalds 
10981da177e4SLinus Torvalds         return retval;
10991da177e4SLinus Torvalds }
11001da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_tod_read);
11011da177e4SLinus Torvalds 
pdc_mem_pdt_info(struct pdc_mem_retinfo * rinfo)1102c9c2877dSHelge Deller int pdc_mem_pdt_info(struct pdc_mem_retinfo *rinfo)
1103c9c2877dSHelge Deller {
1104c9c2877dSHelge Deller 	int retval;
1105c9c2877dSHelge Deller 	unsigned long flags;
1106c9c2877dSHelge Deller 
1107c9c2877dSHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
1108c9c2877dSHelge Deller 	retval = mem_pdc_call(PDC_MEM, PDC_MEM_MEMINFO, __pa(pdc_result), 0);
1109c9c2877dSHelge Deller 	convert_to_wide(pdc_result);
1110c9c2877dSHelge Deller 	memcpy(rinfo, pdc_result, sizeof(*rinfo));
1111c9c2877dSHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
1112c9c2877dSHelge Deller 
1113c9c2877dSHelge Deller 	return retval;
1114c9c2877dSHelge Deller }
1115c9c2877dSHelge Deller 
pdc_mem_pdt_read_entries(struct pdc_mem_read_pdt * pret,unsigned long * pdt_entries_ptr)1116c9c2877dSHelge Deller int pdc_mem_pdt_read_entries(struct pdc_mem_read_pdt *pret,
1117c9c2877dSHelge Deller 		unsigned long *pdt_entries_ptr)
1118c9c2877dSHelge Deller {
1119c9c2877dSHelge Deller 	int retval;
1120c9c2877dSHelge Deller 	unsigned long flags;
1121c9c2877dSHelge Deller 
1122c9c2877dSHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
1123c9c2877dSHelge Deller 	retval = mem_pdc_call(PDC_MEM, PDC_MEM_READ_PDT, __pa(pdc_result),
11248a5aa00eSHelge Deller 			__pa(pdt_entries_ptr));
1125c9c2877dSHelge Deller 	if (retval == PDC_OK) {
1126c9c2877dSHelge Deller 		convert_to_wide(pdc_result);
1127c9c2877dSHelge Deller 		memcpy(pret, pdc_result, sizeof(*pret));
1128c9c2877dSHelge Deller 	}
1129c9c2877dSHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
1130c9c2877dSHelge Deller 
11318a5aa00eSHelge Deller #ifdef CONFIG_64BIT
11328a5aa00eSHelge Deller 	/*
11338a5aa00eSHelge Deller 	 * 64-bit kernels should not call this PDT function in narrow mode.
11348a5aa00eSHelge Deller 	 * The pdt_entries_ptr array above will now contain 32-bit values
11358a5aa00eSHelge Deller 	 */
11368a5aa00eSHelge Deller 	if (WARN_ON_ONCE((retval == PDC_OK) && parisc_narrow_firmware))
11378a5aa00eSHelge Deller 		return PDC_ERROR;
11388a5aa00eSHelge Deller #endif
11398a5aa00eSHelge Deller 
1140c9c2877dSHelge Deller 	return retval;
1141c9c2877dSHelge Deller }
1142c9c2877dSHelge Deller 
11431da177e4SLinus Torvalds /**
1144ecac7036SSven Schnelle  * pdc_pim_toc11 - Fetch TOC PIM 1.1 data from firmware.
1145ecac7036SSven Schnelle  * @ret: pointer to return buffer
1146ecac7036SSven Schnelle  */
pdc_pim_toc11(struct pdc_toc_pim_11 * ret)1147ecac7036SSven Schnelle int pdc_pim_toc11(struct pdc_toc_pim_11 *ret)
1148ecac7036SSven Schnelle {
1149ecac7036SSven Schnelle 	int retval;
1150ecac7036SSven Schnelle 	unsigned long flags;
1151ecac7036SSven Schnelle 
1152ecac7036SSven Schnelle 	spin_lock_irqsave(&pdc_lock, flags);
1153ecac7036SSven Schnelle 	retval = mem_pdc_call(PDC_PIM, PDC_PIM_TOC, __pa(pdc_result),
1154ecac7036SSven Schnelle 			      __pa(ret), sizeof(*ret));
1155ecac7036SSven Schnelle 	spin_unlock_irqrestore(&pdc_lock, flags);
1156ecac7036SSven Schnelle 	return retval;
1157ecac7036SSven Schnelle }
1158ecac7036SSven Schnelle 
1159ecac7036SSven Schnelle /**
1160ecac7036SSven Schnelle  * pdc_pim_toc20 - Fetch TOC PIM 2.0 data from firmware.
1161ecac7036SSven Schnelle  * @ret: pointer to return buffer
1162ecac7036SSven Schnelle  */
pdc_pim_toc20(struct pdc_toc_pim_20 * ret)1163ecac7036SSven Schnelle int pdc_pim_toc20(struct pdc_toc_pim_20 *ret)
1164ecac7036SSven Schnelle {
1165ecac7036SSven Schnelle 	int retval;
1166ecac7036SSven Schnelle 	unsigned long flags;
1167ecac7036SSven Schnelle 
1168ecac7036SSven Schnelle 	spin_lock_irqsave(&pdc_lock, flags);
1169ecac7036SSven Schnelle 	retval = mem_pdc_call(PDC_PIM, PDC_PIM_TOC, __pa(pdc_result),
1170ecac7036SSven Schnelle 			      __pa(ret), sizeof(*ret));
1171ecac7036SSven Schnelle 	spin_unlock_irqrestore(&pdc_lock, flags);
1172ecac7036SSven Schnelle 	return retval;
1173ecac7036SSven Schnelle }
1174ecac7036SSven Schnelle 
1175ecac7036SSven Schnelle /**
11761da177e4SLinus Torvalds  * pdc_tod_set - Set the Time-Of-Day clock.
11771da177e4SLinus Torvalds  * @sec: The number of seconds since epoch.
11781da177e4SLinus Torvalds  * @usec: The number of micro seconds.
11791da177e4SLinus Torvalds  *
11801da177e4SLinus Torvalds  * Set the Time-Of-Day clock.
11811da177e4SLinus Torvalds  */
pdc_tod_set(unsigned long sec,unsigned long usec)11821da177e4SLinus Torvalds int pdc_tod_set(unsigned long sec, unsigned long usec)
11831da177e4SLinus Torvalds {
11841da177e4SLinus Torvalds         int retval;
118509690b18SKyle McMartin 	unsigned long flags;
11861da177e4SLinus Torvalds 
118709690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
11881da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_TOD, PDC_TOD_WRITE, sec, usec);
118909690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
11901da177e4SLinus Torvalds 
11911da177e4SLinus Torvalds         return retval;
11921da177e4SLinus Torvalds }
11931da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_tod_set);
11941da177e4SLinus Torvalds 
1195a8f44e38SHelge Deller #ifdef CONFIG_64BIT
pdc_mem_mem_table(struct pdc_memory_table_raddr * r_addr,struct pdc_memory_table * tbl,unsigned long entries)11961da177e4SLinus Torvalds int pdc_mem_mem_table(struct pdc_memory_table_raddr *r_addr,
11971da177e4SLinus Torvalds 		struct pdc_memory_table *tbl, unsigned long entries)
11981da177e4SLinus Torvalds {
11991da177e4SLinus Torvalds 	int retval;
120009690b18SKyle McMartin 	unsigned long flags;
12011da177e4SLinus Torvalds 
120209690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
12031da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_MEM, PDC_MEM_TABLE, __pa(pdc_result), __pa(pdc_result2), entries);
12041da177e4SLinus Torvalds 	convert_to_wide(pdc_result);
12051da177e4SLinus Torvalds 	memcpy(r_addr, pdc_result, sizeof(*r_addr));
12061da177e4SLinus Torvalds 	memcpy(tbl, pdc_result2, entries * sizeof(*tbl));
120709690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
12081da177e4SLinus Torvalds 
12091da177e4SLinus Torvalds 	return retval;
12101da177e4SLinus Torvalds }
1211a8f44e38SHelge Deller #endif /* CONFIG_64BIT */
12121da177e4SLinus Torvalds 
12131da177e4SLinus Torvalds /* FIXME: Is this pdc used?  I could not find type reference to ftc_bitmap
12141da177e4SLinus Torvalds  * so I guessed at unsigned long.  Someone who knows what this does, can fix
12151da177e4SLinus Torvalds  * it later. :)
12161da177e4SLinus Torvalds  */
pdc_do_firm_test_reset(unsigned long ftc_bitmap)12171da177e4SLinus Torvalds int pdc_do_firm_test_reset(unsigned long ftc_bitmap)
12181da177e4SLinus Torvalds {
12191da177e4SLinus Torvalds         int retval;
122009690b18SKyle McMartin 	unsigned long flags;
12211da177e4SLinus Torvalds 
122209690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
12231da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_FIRM_TEST_RESET,
12241da177e4SLinus Torvalds                               PDC_FIRM_TEST_MAGIC, ftc_bitmap);
122509690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
12261da177e4SLinus Torvalds 
12271da177e4SLinus Torvalds         return retval;
12281da177e4SLinus Torvalds }
12291da177e4SLinus Torvalds 
12301da177e4SLinus Torvalds /*
12311da177e4SLinus Torvalds  * pdc_do_reset - Reset the system.
12321da177e4SLinus Torvalds  *
12331da177e4SLinus Torvalds  * Reset the system.
12341da177e4SLinus Torvalds  */
pdc_do_reset(void)12351da177e4SLinus Torvalds int pdc_do_reset(void)
12361da177e4SLinus Torvalds {
12371da177e4SLinus Torvalds         int retval;
123809690b18SKyle McMartin 	unsigned long flags;
12391da177e4SLinus Torvalds 
124009690b18SKyle McMartin         spin_lock_irqsave(&pdc_lock, flags);
12411da177e4SLinus Torvalds         retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_RESET);
124209690b18SKyle McMartin         spin_unlock_irqrestore(&pdc_lock, flags);
12431da177e4SLinus Torvalds 
12441da177e4SLinus Torvalds         return retval;
12451da177e4SLinus Torvalds }
12461da177e4SLinus Torvalds 
12471da177e4SLinus Torvalds /*
12481da177e4SLinus Torvalds  * pdc_soft_power_info - Enable soft power switch.
12491da177e4SLinus Torvalds  * @power_reg: address of soft power register
12501da177e4SLinus Torvalds  *
12511da177e4SLinus Torvalds  * Return the absolute address of the soft power switch register
12521da177e4SLinus Torvalds  */
pdc_soft_power_info(unsigned long * power_reg)12531da177e4SLinus Torvalds int __init pdc_soft_power_info(unsigned long *power_reg)
12541da177e4SLinus Torvalds {
12551da177e4SLinus Torvalds 	int retval;
125609690b18SKyle McMartin 	unsigned long flags;
12571da177e4SLinus Torvalds 
12581da177e4SLinus Torvalds 	*power_reg = (unsigned long) (-1);
12591da177e4SLinus Torvalds 
126009690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
12611da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_INFO, __pa(pdc_result), 0);
12621da177e4SLinus Torvalds 	if (retval == PDC_OK) {
12631da177e4SLinus Torvalds                 convert_to_wide(pdc_result);
12641da177e4SLinus Torvalds                 *power_reg = f_extend(pdc_result[0]);
12651da177e4SLinus Torvalds 	}
126609690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
12671da177e4SLinus Torvalds 
12681da177e4SLinus Torvalds 	return retval;
12691da177e4SLinus Torvalds }
12701da177e4SLinus Torvalds 
12711da177e4SLinus Torvalds /*
1272829632daSGuilherme G. Piccoli  * pdc_soft_power_button{_panic} - Control the soft power button behaviour
12731da177e4SLinus Torvalds  * @sw_control: 0 for hardware control, 1 for software control
12741da177e4SLinus Torvalds  *
12751da177e4SLinus Torvalds  *
12761da177e4SLinus Torvalds  * This PDC function places the soft power button under software or
12771da177e4SLinus Torvalds  * hardware control.
12781da177e4SLinus Torvalds  * Under software control the OS may control to when to allow to shut
12791da177e4SLinus Torvalds  * down the system. Under hardware control pressing the power button
12801da177e4SLinus Torvalds  * powers off the system immediately.
1281829632daSGuilherme G. Piccoli  *
1282829632daSGuilherme G. Piccoli  * The _panic version relies on spin_trylock to prevent deadlock
1283829632daSGuilherme G. Piccoli  * on panic path.
12841da177e4SLinus Torvalds  */
pdc_soft_power_button(int sw_control)12851da177e4SLinus Torvalds int pdc_soft_power_button(int sw_control)
12861da177e4SLinus Torvalds {
12871da177e4SLinus Torvalds 	int retval;
128809690b18SKyle McMartin 	unsigned long flags;
128909690b18SKyle McMartin 
129009690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
12911da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
129209690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
129309690b18SKyle McMartin 
12941da177e4SLinus Torvalds 	return retval;
12951da177e4SLinus Torvalds }
12961da177e4SLinus Torvalds 
pdc_soft_power_button_panic(int sw_control)1297829632daSGuilherme G. Piccoli int pdc_soft_power_button_panic(int sw_control)
1298829632daSGuilherme G. Piccoli {
1299829632daSGuilherme G. Piccoli 	int retval;
1300829632daSGuilherme G. Piccoli 	unsigned long flags;
1301829632daSGuilherme G. Piccoli 
1302829632daSGuilherme G. Piccoli 	if (!spin_trylock_irqsave(&pdc_lock, flags)) {
1303829632daSGuilherme G. Piccoli 		pr_emerg("Couldn't enable soft power button\n");
1304829632daSGuilherme G. Piccoli 		return -EBUSY; /* ignored by the panic notifier */
1305829632daSGuilherme G. Piccoli 	}
1306829632daSGuilherme G. Piccoli 
1307829632daSGuilherme G. Piccoli 	retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
1308829632daSGuilherme G. Piccoli 	spin_unlock_irqrestore(&pdc_lock, flags);
1309829632daSGuilherme G. Piccoli 
1310829632daSGuilherme G. Piccoli 	return retval;
1311829632daSGuilherme G. Piccoli }
1312829632daSGuilherme G. Piccoli 
13131da177e4SLinus Torvalds /*
13141da177e4SLinus Torvalds  * pdc_io_reset - Hack to avoid overlapping range registers of Bridges devices.
13151da177e4SLinus Torvalds  * Primarily a problem on T600 (which parisc-linux doesn't support) but
13161da177e4SLinus Torvalds  * who knows what other platform firmware might do with this OS "hook".
13171da177e4SLinus Torvalds  */
pdc_io_reset(void)13181da177e4SLinus Torvalds void pdc_io_reset(void)
13191da177e4SLinus Torvalds {
132009690b18SKyle McMartin 	unsigned long flags;
132109690b18SKyle McMartin 
132209690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
13231da177e4SLinus Torvalds 	mem_pdc_call(PDC_IO, PDC_IO_RESET, 0);
132409690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
13251da177e4SLinus Torvalds }
13261da177e4SLinus Torvalds 
13271da177e4SLinus Torvalds /*
13281da177e4SLinus Torvalds  * pdc_io_reset_devices - Hack to Stop USB controller
13291da177e4SLinus Torvalds  *
13301da177e4SLinus Torvalds  * If PDC used the usb controller, the usb controller
13311da177e4SLinus Torvalds  * is still running and will crash the machines during iommu
13321da177e4SLinus Torvalds  * setup, because of still running DMA. This PDC call
13331da177e4SLinus Torvalds  * stops the USB controller.
13341da177e4SLinus Torvalds  * Normally called after calling pdc_io_reset().
13351da177e4SLinus Torvalds  */
pdc_io_reset_devices(void)13361da177e4SLinus Torvalds void pdc_io_reset_devices(void)
13371da177e4SLinus Torvalds {
133809690b18SKyle McMartin 	unsigned long flags;
133909690b18SKyle McMartin 
134009690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
13411da177e4SLinus Torvalds 	mem_pdc_call(PDC_IO, PDC_IO_RESET_DEVICES, 0);
134209690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
13431da177e4SLinus Torvalds }
13441da177e4SLinus Torvalds 
1345f5213b2cSHelge Deller #endif /* defined(BOOTLOADER) */
1346f5213b2cSHelge Deller 
13477236aae5SHelge Deller /* locked by pdc_lock */
13487236aae5SHelge Deller static char iodc_dbuf[4096] __page_aligned_bss;
13491da177e4SLinus Torvalds 
13501da177e4SLinus Torvalds /**
1351721fdf34SKyle McMartin  * pdc_iodc_print - Console print using IODC.
1352721fdf34SKyle McMartin  * @str: the string to output.
1353721fdf34SKyle McMartin  * @count: length of str
13541da177e4SLinus Torvalds  *
13551da177e4SLinus Torvalds  * Note that only these special chars are architected for console IODC io:
13561da177e4SLinus Torvalds  * BEL, BS, CR, and LF. Others are passed through.
13571da177e4SLinus Torvalds  * Since the HP console requires CR+LF to perform a 'newline', we translate
13581da177e4SLinus Torvalds  * "\n" to "\r\n".
13591da177e4SLinus Torvalds  */
pdc_iodc_print(const unsigned char * str,unsigned count)1360ef1afd4dSKyle McMartin int pdc_iodc_print(const unsigned char *str, unsigned count)
13611da177e4SLinus Torvalds {
13625d1335daSHelge Deller 	unsigned int i, found = 0;
1363c53421b1SAlexey Dobriyan 	unsigned long flags;
13641da177e4SLinus Torvalds 
13657236aae5SHelge Deller 	count = min_t(unsigned int, count, sizeof(iodc_dbuf));
13667236aae5SHelge Deller 
13677236aae5SHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
1368fbea6684SGuy Martin 	for (i = 0; i < count;) {
1369721fdf34SKyle McMartin 		switch(str[i]) {
13701da177e4SLinus Torvalds 		case '\n':
1371721fdf34SKyle McMartin 			iodc_dbuf[i+0] = '\r';
1372721fdf34SKyle McMartin 			iodc_dbuf[i+1] = '\n';
1373721fdf34SKyle McMartin 			i += 2;
13745d1335daSHelge Deller 			found = 1;
1375ef1afd4dSKyle McMartin 			goto print;
13761da177e4SLinus Torvalds 		default:
1377721fdf34SKyle McMartin 			iodc_dbuf[i] = str[i];
1378d9b68e5eSKyle McMartin 			i++;
13791da177e4SLinus Torvalds 			break;
13801da177e4SLinus Torvalds 		}
13811da177e4SLinus Torvalds 	}
13821da177e4SLinus Torvalds 
1383ef1afd4dSKyle McMartin print:
13841da177e4SLinus Torvalds 	real32_call(PAGE0->mem_cons.iodc_io,
13851da177e4SLinus Torvalds 		(unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
13861da177e4SLinus Torvalds 		PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
13877236aae5SHelge Deller 		__pa(pdc_result), 0, __pa(iodc_dbuf), i, 0);
13881da177e4SLinus Torvalds 	spin_unlock_irqrestore(&pdc_lock, flags);
1389721fdf34SKyle McMartin 
13905d1335daSHelge Deller 	return i - found;
13911da177e4SLinus Torvalds }
13921da177e4SLinus Torvalds 
1393f5213b2cSHelge Deller #if !defined(BOOTLOADER)
13941da177e4SLinus Torvalds /**
13951da177e4SLinus Torvalds  * pdc_iodc_getc - Read a character (non-blocking) from the PDC console.
13961da177e4SLinus Torvalds  *
13971da177e4SLinus Torvalds  * Read a character (non-blocking) from the PDC console, returns -1 if
13981da177e4SLinus Torvalds  * key is not present.
13991da177e4SLinus Torvalds  */
pdc_iodc_getc(void)14001da177e4SLinus Torvalds int pdc_iodc_getc(void)
14011da177e4SLinus Torvalds {
14021da177e4SLinus Torvalds 	int ch;
14031da177e4SLinus Torvalds 	int status;
1404ef1afd4dSKyle McMartin 	unsigned long flags;
14051da177e4SLinus Torvalds 
14061da177e4SLinus Torvalds 	/* Bail if no console input device. */
14071da177e4SLinus Torvalds 	if (!PAGE0->mem_kbd.iodc_io)
14081da177e4SLinus Torvalds 		return 0;
14091da177e4SLinus Torvalds 
14101da177e4SLinus Torvalds 	/* wait for a keyboard (rs232)-input */
14111da177e4SLinus Torvalds 	spin_lock_irqsave(&pdc_lock, flags);
14121da177e4SLinus Torvalds 	real32_call(PAGE0->mem_kbd.iodc_io,
14131da177e4SLinus Torvalds 		    (unsigned long)PAGE0->mem_kbd.hpa, ENTRY_IO_CIN,
14141da177e4SLinus Torvalds 		    PAGE0->mem_kbd.spa, __pa(PAGE0->mem_kbd.dp.layers),
14157236aae5SHelge Deller 		    __pa(pdc_result), 0, __pa(iodc_dbuf), 1, 0);
14161da177e4SLinus Torvalds 
14171da177e4SLinus Torvalds 	ch = *iodc_dbuf;
14187236aae5SHelge Deller 	/* like convert_to_wide() but for first return value only: */
14197236aae5SHelge Deller 	status = *(int *)&pdc_result;
14201da177e4SLinus Torvalds 	spin_unlock_irqrestore(&pdc_lock, flags);
14211da177e4SLinus Torvalds 
14221da177e4SLinus Torvalds 	if (status == 0)
14231da177e4SLinus Torvalds 	    return -1;
14241da177e4SLinus Torvalds 
14251da177e4SLinus Torvalds 	return ch;
14261da177e4SLinus Torvalds }
14271da177e4SLinus Torvalds 
pdc_sti_call(unsigned long func,unsigned long flags,unsigned long inptr,unsigned long outputr,unsigned long glob_cfg,int do_call64)14281da177e4SLinus Torvalds int pdc_sti_call(unsigned long func, unsigned long flags,
14291da177e4SLinus Torvalds 		unsigned long inptr, unsigned long outputr,
1430ededd9d2SHelge Deller 		unsigned long glob_cfg, int do_call64)
14311da177e4SLinus Torvalds {
1432ededd9d2SHelge Deller 	int retval = 0;
143309690b18SKyle McMartin 	unsigned long irqflags;
14341da177e4SLinus Torvalds 
143509690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, irqflags);
1436ededd9d2SHelge Deller 	if (IS_ENABLED(CONFIG_64BIT) && do_call64) {
1437ededd9d2SHelge Deller #ifdef CONFIG_64BIT
1438ededd9d2SHelge Deller 		retval = real64_call(func, flags, inptr, outputr, glob_cfg);
1439ededd9d2SHelge Deller #else
1440ededd9d2SHelge Deller 		WARN_ON(1);
1441ededd9d2SHelge Deller #endif
1442ededd9d2SHelge Deller 	} else {
14431da177e4SLinus Torvalds 		retval = real32_call(func, flags, inptr, outputr, glob_cfg);
1444ededd9d2SHelge Deller 	}
144509690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, irqflags);
14461da177e4SLinus Torvalds 
14471da177e4SLinus Torvalds 	return retval;
14481da177e4SLinus Torvalds }
14491da177e4SLinus Torvalds EXPORT_SYMBOL(pdc_sti_call);
14501da177e4SLinus Torvalds 
1451a8f44e38SHelge Deller #ifdef CONFIG_64BIT
14521da177e4SLinus Torvalds /**
14531da177e4SLinus Torvalds  * pdc_pat_cell_get_number - Returns the cell number.
14541da177e4SLinus Torvalds  * @cell_info: The return buffer.
14551da177e4SLinus Torvalds  *
14561da177e4SLinus Torvalds  * This PDC call returns the cell number of the cell from which the call
14571da177e4SLinus Torvalds  * is made.
14581da177e4SLinus Torvalds  */
pdc_pat_cell_get_number(struct pdc_pat_cell_num * cell_info)14591da177e4SLinus Torvalds int pdc_pat_cell_get_number(struct pdc_pat_cell_num *cell_info)
14601da177e4SLinus Torvalds {
14611da177e4SLinus Torvalds 	int retval;
146209690b18SKyle McMartin 	unsigned long flags;
14631da177e4SLinus Torvalds 
146409690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
14651da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_GET_NUMBER, __pa(pdc_result));
14661da177e4SLinus Torvalds 	memcpy(cell_info, pdc_result, sizeof(*cell_info));
146709690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
14681da177e4SLinus Torvalds 
14691da177e4SLinus Torvalds 	return retval;
14701da177e4SLinus Torvalds }
14711da177e4SLinus Torvalds 
14721da177e4SLinus Torvalds /**
14731da177e4SLinus Torvalds  * pdc_pat_cell_module - Retrieve the cell's module information.
14741da177e4SLinus Torvalds  * @actcnt: The number of bytes written to mem_addr.
14751da177e4SLinus Torvalds  * @ploc: The physical location.
14761da177e4SLinus Torvalds  * @mod: The module index.
14771da177e4SLinus Torvalds  * @view_type: The view of the address type.
14781da177e4SLinus Torvalds  * @mem_addr: The return buffer.
14791da177e4SLinus Torvalds  *
14801da177e4SLinus Torvalds  * This PDC call returns information about each module attached to the cell
14811da177e4SLinus Torvalds  * at the specified location.
14821da177e4SLinus Torvalds  */
pdc_pat_cell_module(unsigned long * actcnt,unsigned long ploc,unsigned long mod,unsigned long view_type,void * mem_addr)14831da177e4SLinus Torvalds int pdc_pat_cell_module(unsigned long *actcnt, unsigned long ploc, unsigned long mod,
14841da177e4SLinus Torvalds 			unsigned long view_type, void *mem_addr)
14851da177e4SLinus Torvalds {
14861da177e4SLinus Torvalds 	int retval;
148709690b18SKyle McMartin 	unsigned long flags;
14881da177e4SLinus Torvalds 	static struct pdc_pat_cell_mod_maddr_block result __attribute__ ((aligned (8)));
14891da177e4SLinus Torvalds 
149009690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
14911da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_MODULE, __pa(pdc_result),
14921da177e4SLinus Torvalds 			      ploc, mod, view_type, __pa(&result));
14931da177e4SLinus Torvalds 	if(!retval) {
14941da177e4SLinus Torvalds 		*actcnt = pdc_result[0];
14951da177e4SLinus Torvalds 		memcpy(mem_addr, &result, *actcnt);
14961da177e4SLinus Torvalds 	}
149709690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
14981da177e4SLinus Torvalds 
14991da177e4SLinus Torvalds 	return retval;
15001da177e4SLinus Torvalds }
15011da177e4SLinus Torvalds 
15021da177e4SLinus Torvalds /**
1503fe8376dbSHelge Deller  * pdc_pat_cell_info - Retrieve the cell's information.
1504fe8376dbSHelge Deller  * @info: The pointer to a struct pdc_pat_cell_info_rtn_block.
1505fe8376dbSHelge Deller  * @actcnt: The number of bytes which should be written to info.
1506fe8376dbSHelge Deller  * @offset: offset of the structure.
1507fe8376dbSHelge Deller  * @cell_number: The cell number which should be asked, or -1 for current cell.
1508fe8376dbSHelge Deller  *
1509fe8376dbSHelge Deller  * This PDC call returns information about the given cell (or all cells).
1510fe8376dbSHelge Deller  */
pdc_pat_cell_info(struct pdc_pat_cell_info_rtn_block * info,unsigned long * actcnt,unsigned long offset,unsigned long cell_number)1511fe8376dbSHelge Deller int pdc_pat_cell_info(struct pdc_pat_cell_info_rtn_block *info,
1512fe8376dbSHelge Deller 		unsigned long *actcnt, unsigned long offset,
1513fe8376dbSHelge Deller 		unsigned long cell_number)
1514fe8376dbSHelge Deller {
1515fe8376dbSHelge Deller 	int retval;
1516fe8376dbSHelge Deller 	unsigned long flags;
1517fe8376dbSHelge Deller 	struct pdc_pat_cell_info_rtn_block result;
1518fe8376dbSHelge Deller 
1519fe8376dbSHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
1520fe8376dbSHelge Deller 	retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_GET_INFO,
1521fe8376dbSHelge Deller 			__pa(pdc_result), __pa(&result), *actcnt,
1522fe8376dbSHelge Deller 			offset, cell_number);
1523fe8376dbSHelge Deller 	if (!retval) {
1524fe8376dbSHelge Deller 		*actcnt = pdc_result[0];
1525fe8376dbSHelge Deller 		memcpy(info, &result, *actcnt);
1526fe8376dbSHelge Deller 	}
1527fe8376dbSHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
1528fe8376dbSHelge Deller 
1529fe8376dbSHelge Deller 	return retval;
1530fe8376dbSHelge Deller }
1531fe8376dbSHelge Deller 
1532fe8376dbSHelge Deller /**
15331da177e4SLinus Torvalds  * pdc_pat_cpu_get_number - Retrieve the cpu number.
15341da177e4SLinus Torvalds  * @cpu_info: The return buffer.
15351da177e4SLinus Torvalds  * @hpa: The Hard Physical Address of the CPU.
15361da177e4SLinus Torvalds  *
15371da177e4SLinus Torvalds  * Retrieve the cpu number for the cpu at the specified HPA.
15381da177e4SLinus Torvalds  */
pdc_pat_cpu_get_number(struct pdc_pat_cpu_num * cpu_info,unsigned long hpa)1539637250ccSHelge Deller int pdc_pat_cpu_get_number(struct pdc_pat_cpu_num *cpu_info, unsigned long hpa)
15401da177e4SLinus Torvalds {
15411da177e4SLinus Torvalds 	int retval;
154209690b18SKyle McMartin 	unsigned long flags;
15431da177e4SLinus Torvalds 
154409690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
15451da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_GET_NUMBER,
15461da177e4SLinus Torvalds 			      __pa(&pdc_result), hpa);
15471da177e4SLinus Torvalds 	memcpy(cpu_info, pdc_result, sizeof(*cpu_info));
154809690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
15491da177e4SLinus Torvalds 
15501da177e4SLinus Torvalds 	return retval;
15511da177e4SLinus Torvalds }
15521da177e4SLinus Torvalds 
15531da177e4SLinus Torvalds /**
15541da177e4SLinus Torvalds  * pdc_pat_get_irt_size - Retrieve the number of entries in the cell's interrupt table.
15551da177e4SLinus Torvalds  * @num_entries: The return value.
15561da177e4SLinus Torvalds  * @cell_num: The target cell.
15571da177e4SLinus Torvalds  *
15581da177e4SLinus Torvalds  * This PDC function returns the number of entries in the specified cell's
15591da177e4SLinus Torvalds  * interrupt table.
15601da177e4SLinus Torvalds  */
pdc_pat_get_irt_size(unsigned long * num_entries,unsigned long cell_num)15611da177e4SLinus Torvalds int pdc_pat_get_irt_size(unsigned long *num_entries, unsigned long cell_num)
15621da177e4SLinus Torvalds {
15631da177e4SLinus Torvalds 	int retval;
156409690b18SKyle McMartin 	unsigned long flags;
15651da177e4SLinus Torvalds 
156609690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
15671da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE_SIZE,
15681da177e4SLinus Torvalds 			      __pa(pdc_result), cell_num);
15691da177e4SLinus Torvalds 	*num_entries = pdc_result[0];
157009690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
15711da177e4SLinus Torvalds 
15721da177e4SLinus Torvalds 	return retval;
15731da177e4SLinus Torvalds }
15741da177e4SLinus Torvalds 
15751da177e4SLinus Torvalds /**
15761da177e4SLinus Torvalds  * pdc_pat_get_irt - Retrieve the cell's interrupt table.
15771da177e4SLinus Torvalds  * @r_addr: The return buffer.
15781da177e4SLinus Torvalds  * @cell_num: The target cell.
15791da177e4SLinus Torvalds  *
15801da177e4SLinus Torvalds  * This PDC function returns the actual interrupt table for the specified cell.
15811da177e4SLinus Torvalds  */
pdc_pat_get_irt(void * r_addr,unsigned long cell_num)15821da177e4SLinus Torvalds int pdc_pat_get_irt(void *r_addr, unsigned long cell_num)
15831da177e4SLinus Torvalds {
15841da177e4SLinus Torvalds 	int retval;
158509690b18SKyle McMartin 	unsigned long flags;
15861da177e4SLinus Torvalds 
158709690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
15881da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE,
15891da177e4SLinus Torvalds 			      __pa(r_addr), cell_num);
159009690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
15911da177e4SLinus Torvalds 
15921da177e4SLinus Torvalds 	return retval;
15931da177e4SLinus Torvalds }
15941da177e4SLinus Torvalds 
15951da177e4SLinus Torvalds /**
15961da177e4SLinus Torvalds  * pdc_pat_pd_get_addr_map - Retrieve information about memory address ranges.
159742758522SHelge Deller  * @actual_len: The return buffer.
15981da177e4SLinus Torvalds  * @mem_addr: Pointer to the memory buffer.
15991da177e4SLinus Torvalds  * @count: The number of bytes to read from the buffer.
16001da177e4SLinus Torvalds  * @offset: The offset with respect to the beginning of the buffer.
16011da177e4SLinus Torvalds  *
16021da177e4SLinus Torvalds  */
pdc_pat_pd_get_addr_map(unsigned long * actual_len,void * mem_addr,unsigned long count,unsigned long offset)16031da177e4SLinus Torvalds int pdc_pat_pd_get_addr_map(unsigned long *actual_len, void *mem_addr,
16041da177e4SLinus Torvalds 			    unsigned long count, unsigned long offset)
16051da177e4SLinus Torvalds {
16061da177e4SLinus Torvalds 	int retval;
160709690b18SKyle McMartin 	unsigned long flags;
16081da177e4SLinus Torvalds 
160909690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
16101da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PAT_PD, PDC_PAT_PD_GET_ADDR_MAP, __pa(pdc_result),
16111da177e4SLinus Torvalds 			      __pa(pdc_result2), count, offset);
16121da177e4SLinus Torvalds 	*actual_len = pdc_result[0];
16131da177e4SLinus Torvalds 	memcpy(mem_addr, pdc_result2, *actual_len);
161409690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
16151da177e4SLinus Torvalds 
16161da177e4SLinus Torvalds 	return retval;
16171da177e4SLinus Torvalds }
16181da177e4SLinus Torvalds 
16191da177e4SLinus Torvalds /**
162042758522SHelge Deller  * pdc_pat_pd_get_pdc_revisions - Retrieve PDC interface revisions.
1621fe8376dbSHelge Deller  * @legacy_rev: The legacy revision.
1622fe8376dbSHelge Deller  * @pat_rev: The PAT revision.
1623fe8376dbSHelge Deller  * @pdc_cap: The PDC capabilities.
1624fe8376dbSHelge Deller  *
1625fe8376dbSHelge Deller  */
pdc_pat_pd_get_pdc_revisions(unsigned long * legacy_rev,unsigned long * pat_rev,unsigned long * pdc_cap)1626fe8376dbSHelge Deller int pdc_pat_pd_get_pdc_revisions(unsigned long *legacy_rev,
1627fe8376dbSHelge Deller 		unsigned long *pat_rev, unsigned long *pdc_cap)
1628fe8376dbSHelge Deller {
1629fe8376dbSHelge Deller 	int retval;
1630fe8376dbSHelge Deller 	unsigned long flags;
1631fe8376dbSHelge Deller 
1632fe8376dbSHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
1633fe8376dbSHelge Deller 	retval = mem_pdc_call(PDC_PAT_PD, PDC_PAT_PD_GET_PDC_INTERF_REV,
1634fe8376dbSHelge Deller 				__pa(pdc_result));
1635fe8376dbSHelge Deller 	if (retval == PDC_OK) {
1636fe8376dbSHelge Deller 		*legacy_rev = pdc_result[0];
1637fe8376dbSHelge Deller 		*pat_rev = pdc_result[1];
1638fe8376dbSHelge Deller 		*pdc_cap = pdc_result[2];
1639fe8376dbSHelge Deller 	}
1640fe8376dbSHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
1641fe8376dbSHelge Deller 
1642fe8376dbSHelge Deller 	return retval;
1643fe8376dbSHelge Deller }
1644fe8376dbSHelge Deller 
1645fe8376dbSHelge Deller 
1646fe8376dbSHelge Deller /**
16471da177e4SLinus Torvalds  * pdc_pat_io_pci_cfg_read - Read PCI configuration space.
16481da177e4SLinus Torvalds  * @pci_addr: PCI configuration space address for which the read request is being made.
16491da177e4SLinus Torvalds  * @pci_size: Size of read in bytes. Valid values are 1, 2, and 4.
16501da177e4SLinus Torvalds  * @mem_addr: Pointer to return memory buffer.
16511da177e4SLinus Torvalds  *
16521da177e4SLinus Torvalds  */
pdc_pat_io_pci_cfg_read(unsigned long pci_addr,int pci_size,u32 * mem_addr)16531da177e4SLinus Torvalds int pdc_pat_io_pci_cfg_read(unsigned long pci_addr, int pci_size, u32 *mem_addr)
16541da177e4SLinus Torvalds {
16551da177e4SLinus Torvalds 	int retval;
165609690b18SKyle McMartin 	unsigned long flags;
165709690b18SKyle McMartin 
165809690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
16591da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_READ,
16601da177e4SLinus Torvalds 					__pa(pdc_result), pci_addr, pci_size);
16611da177e4SLinus Torvalds 	switch(pci_size) {
166249ea1480SHelge Deller 		case 1: *(u8 *) mem_addr =  (u8)  pdc_result[0]; break;
166349ea1480SHelge Deller 		case 2: *(u16 *)mem_addr =  (u16) pdc_result[0]; break;
166449ea1480SHelge Deller 		case 4: *(u32 *)mem_addr =  (u32) pdc_result[0]; break;
16651da177e4SLinus Torvalds 	}
166609690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
16671da177e4SLinus Torvalds 
16681da177e4SLinus Torvalds 	return retval;
16691da177e4SLinus Torvalds }
16701da177e4SLinus Torvalds 
16711da177e4SLinus Torvalds /**
16721da177e4SLinus Torvalds  * pdc_pat_io_pci_cfg_write - Retrieve information about memory address ranges.
16731da177e4SLinus Torvalds  * @pci_addr: PCI configuration space address for which the write  request is being made.
16741da177e4SLinus Torvalds  * @pci_size: Size of write in bytes. Valid values are 1, 2, and 4.
167542758522SHelge Deller  * @val: Pointer to 1, 2, or 4 byte value in low order end of argument to be
16761da177e4SLinus Torvalds  *         written to PCI Config space.
16771da177e4SLinus Torvalds  *
16781da177e4SLinus Torvalds  */
pdc_pat_io_pci_cfg_write(unsigned long pci_addr,int pci_size,u32 val)16791da177e4SLinus Torvalds int pdc_pat_io_pci_cfg_write(unsigned long pci_addr, int pci_size, u32 val)
16801da177e4SLinus Torvalds {
16811da177e4SLinus Torvalds 	int retval;
168209690b18SKyle McMartin 	unsigned long flags;
16831da177e4SLinus Torvalds 
168409690b18SKyle McMartin 	spin_lock_irqsave(&pdc_lock, flags);
16851da177e4SLinus Torvalds 	retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_WRITE,
16861da177e4SLinus Torvalds 				pci_addr, pci_size, val);
168709690b18SKyle McMartin 	spin_unlock_irqrestore(&pdc_lock, flags);
16881da177e4SLinus Torvalds 
16891da177e4SLinus Torvalds 	return retval;
16901da177e4SLinus Torvalds }
1691c9c2877dSHelge Deller 
1692c9c2877dSHelge Deller /**
169342758522SHelge Deller  * pdc_pat_mem_pdt_info - Retrieve information about page deallocation table
1694c9c2877dSHelge Deller  * @rinfo: memory pdt information
1695c9c2877dSHelge Deller  *
1696c9c2877dSHelge Deller  */
pdc_pat_mem_pdt_info(struct pdc_pat_mem_retinfo * rinfo)1697c9c2877dSHelge Deller int pdc_pat_mem_pdt_info(struct pdc_pat_mem_retinfo *rinfo)
1698c9c2877dSHelge Deller {
1699c9c2877dSHelge Deller 	int retval;
1700c9c2877dSHelge Deller 	unsigned long flags;
1701c9c2877dSHelge Deller 
1702c9c2877dSHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
1703c9c2877dSHelge Deller 	retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_PD_INFO,
1704c9c2877dSHelge Deller 			__pa(&pdc_result));
1705c9c2877dSHelge Deller 	if (retval == PDC_OK)
1706c9c2877dSHelge Deller 		memcpy(rinfo, &pdc_result, sizeof(*rinfo));
1707c9c2877dSHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
1708c9c2877dSHelge Deller 
1709c9c2877dSHelge Deller 	return retval;
1710c9c2877dSHelge Deller }
1711c9c2877dSHelge Deller 
1712c9c2877dSHelge Deller /**
17138a5aa00eSHelge Deller  * pdc_pat_mem_pdt_cell_info - Retrieve information about page deallocation
17148a5aa00eSHelge Deller  *				table of a cell
17158a5aa00eSHelge Deller  * @rinfo: memory pdt information
17168a5aa00eSHelge Deller  * @cell: cell number
17178a5aa00eSHelge Deller  *
17188a5aa00eSHelge Deller  */
pdc_pat_mem_pdt_cell_info(struct pdc_pat_mem_cell_pdt_retinfo * rinfo,unsigned long cell)17198a5aa00eSHelge Deller int pdc_pat_mem_pdt_cell_info(struct pdc_pat_mem_cell_pdt_retinfo *rinfo,
17208a5aa00eSHelge Deller 		unsigned long cell)
17218a5aa00eSHelge Deller {
17228a5aa00eSHelge Deller 	int retval;
17238a5aa00eSHelge Deller 	unsigned long flags;
17248a5aa00eSHelge Deller 
17258a5aa00eSHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
17268a5aa00eSHelge Deller 	retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_CELL_INFO,
17278a5aa00eSHelge Deller 			__pa(&pdc_result), cell);
17288a5aa00eSHelge Deller 	if (retval == PDC_OK)
17298a5aa00eSHelge Deller 		memcpy(rinfo, &pdc_result, sizeof(*rinfo));
17308a5aa00eSHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
17318a5aa00eSHelge Deller 
17328a5aa00eSHelge Deller 	return retval;
17338a5aa00eSHelge Deller }
17348a5aa00eSHelge Deller 
17358a5aa00eSHelge Deller /**
1736c9c2877dSHelge Deller  * pdc_pat_mem_read_cell_pdt - Read PDT entries from (old) PAT firmware
1737c9c2877dSHelge Deller  * @pret: array of PDT entries
1738c9c2877dSHelge Deller  * @pdt_entries_ptr: ptr to hold number of PDT entries
1739c9c2877dSHelge Deller  * @max_entries: maximum number of entries to be read
1740c9c2877dSHelge Deller  *
1741c9c2877dSHelge Deller  */
pdc_pat_mem_read_cell_pdt(struct pdc_pat_mem_read_pd_retinfo * pret,unsigned long * pdt_entries_ptr,unsigned long max_entries)1742c9c2877dSHelge Deller int pdc_pat_mem_read_cell_pdt(struct pdc_pat_mem_read_pd_retinfo *pret,
1743c9c2877dSHelge Deller 		unsigned long *pdt_entries_ptr, unsigned long max_entries)
1744c9c2877dSHelge Deller {
1745c9c2877dSHelge Deller 	int retval;
1746c9c2877dSHelge Deller 	unsigned long flags, entries;
1747c9c2877dSHelge Deller 
1748c9c2877dSHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
1749c9c2877dSHelge Deller 	/* PDC_PAT_MEM_CELL_READ is available on early PAT machines only */
1750c9c2877dSHelge Deller 	retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_CELL_READ,
17518a5aa00eSHelge Deller 			__pa(&pdc_result), parisc_cell_num,
17528a5aa00eSHelge Deller 			__pa(pdt_entries_ptr));
1753c9c2877dSHelge Deller 
1754c9c2877dSHelge Deller 	if (retval == PDC_OK) {
1755c9c2877dSHelge Deller 		/* build up return value as for PDC_PAT_MEM_PD_READ */
1756c9c2877dSHelge Deller 		entries = min(pdc_result[0], max_entries);
1757c9c2877dSHelge Deller 		pret->pdt_entries = entries;
1758c9c2877dSHelge Deller 		pret->actual_count_bytes = entries * sizeof(unsigned long);
1759c9c2877dSHelge Deller 	}
1760c9c2877dSHelge Deller 
1761c9c2877dSHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
1762c9c2877dSHelge Deller 	WARN_ON(retval == PDC_OK && pdc_result[0] > max_entries);
1763c9c2877dSHelge Deller 
1764c9c2877dSHelge Deller 	return retval;
1765c9c2877dSHelge Deller }
1766c9c2877dSHelge Deller /**
1767c9c2877dSHelge Deller  * pdc_pat_mem_read_pd_pdt - Read PDT entries from (newer) PAT firmware
1768c9c2877dSHelge Deller  * @pret: array of PDT entries
1769c9c2877dSHelge Deller  * @pdt_entries_ptr: ptr to hold number of PDT entries
17708a5aa00eSHelge Deller  * @count: number of bytes to read
17718a5aa00eSHelge Deller  * @offset: offset to start (in bytes)
1772c9c2877dSHelge Deller  *
1773c9c2877dSHelge Deller  */
pdc_pat_mem_read_pd_pdt(struct pdc_pat_mem_read_pd_retinfo * pret,unsigned long * pdt_entries_ptr,unsigned long count,unsigned long offset)1774c9c2877dSHelge Deller int pdc_pat_mem_read_pd_pdt(struct pdc_pat_mem_read_pd_retinfo *pret,
1775c9c2877dSHelge Deller 		unsigned long *pdt_entries_ptr, unsigned long count,
1776c9c2877dSHelge Deller 		unsigned long offset)
1777c9c2877dSHelge Deller {
1778c9c2877dSHelge Deller 	int retval;
1779f520e552SHelge Deller 	unsigned long flags, entries;
1780c9c2877dSHelge Deller 
1781c9c2877dSHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
1782c9c2877dSHelge Deller 	retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_PD_READ,
1783f520e552SHelge Deller 		__pa(&pdc_result), __pa(pdt_entries_ptr),
1784c9c2877dSHelge Deller 		count, offset);
1785f520e552SHelge Deller 
1786f520e552SHelge Deller 	if (retval == PDC_OK) {
1787f520e552SHelge Deller 		entries = min(pdc_result[0], count);
1788f520e552SHelge Deller 		pret->actual_count_bytes = entries;
1789f520e552SHelge Deller 		pret->pdt_entries = entries / sizeof(unsigned long);
1790f520e552SHelge Deller 	}
1791f520e552SHelge Deller 
1792c9c2877dSHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
1793c9c2877dSHelge Deller 
1794c9c2877dSHelge Deller 	return retval;
1795c9c2877dSHelge Deller }
179625a9b765SHelge Deller 
179725a9b765SHelge Deller /**
179825a9b765SHelge Deller  * pdc_pat_mem_get_dimm_phys_location - Get physical DIMM slot via PAT firmware
179925a9b765SHelge Deller  * @pret: ptr to hold returned information
180025a9b765SHelge Deller  * @phys_addr: physical address to examine
180125a9b765SHelge Deller  *
180225a9b765SHelge Deller  */
pdc_pat_mem_get_dimm_phys_location(struct pdc_pat_mem_phys_mem_location * pret,unsigned long phys_addr)180325a9b765SHelge Deller int pdc_pat_mem_get_dimm_phys_location(
180425a9b765SHelge Deller 		struct pdc_pat_mem_phys_mem_location *pret,
180525a9b765SHelge Deller 		unsigned long phys_addr)
180625a9b765SHelge Deller {
180725a9b765SHelge Deller 	int retval;
180825a9b765SHelge Deller 	unsigned long flags;
180925a9b765SHelge Deller 
181025a9b765SHelge Deller 	spin_lock_irqsave(&pdc_lock, flags);
181125a9b765SHelge Deller 	retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_ADDRESS,
181225a9b765SHelge Deller 		__pa(&pdc_result), phys_addr);
181325a9b765SHelge Deller 
181425a9b765SHelge Deller 	if (retval == PDC_OK)
181525a9b765SHelge Deller 		memcpy(pret, &pdc_result, sizeof(*pret));
181625a9b765SHelge Deller 
181725a9b765SHelge Deller 	spin_unlock_irqrestore(&pdc_lock, flags);
181825a9b765SHelge Deller 
181925a9b765SHelge Deller 	return retval;
182025a9b765SHelge Deller }
1821a8f44e38SHelge Deller #endif /* CONFIG_64BIT */
1822f5213b2cSHelge Deller #endif /* defined(BOOTLOADER) */
18231da177e4SLinus Torvalds 
18241da177e4SLinus Torvalds 
18251da177e4SLinus Torvalds /***************** 32-bit real-mode calls ***********/
18261da177e4SLinus Torvalds /* The struct below is used
18271da177e4SLinus Torvalds  * to overlay real_stack (real2.S), preparing a 32-bit call frame.
18281da177e4SLinus Torvalds  * real32_call_asm() then uses this stack in narrow real mode
18291da177e4SLinus Torvalds  */
18301da177e4SLinus Torvalds 
18311da177e4SLinus Torvalds struct narrow_stack {
18321da177e4SLinus Torvalds 	/* use int, not long which is 64 bits */
18331da177e4SLinus Torvalds 	unsigned int arg13;
18341da177e4SLinus Torvalds 	unsigned int arg12;
18351da177e4SLinus Torvalds 	unsigned int arg11;
18361da177e4SLinus Torvalds 	unsigned int arg10;
18371da177e4SLinus Torvalds 	unsigned int arg9;
18381da177e4SLinus Torvalds 	unsigned int arg8;
18391da177e4SLinus Torvalds 	unsigned int arg7;
18401da177e4SLinus Torvalds 	unsigned int arg6;
18411da177e4SLinus Torvalds 	unsigned int arg5;
18421da177e4SLinus Torvalds 	unsigned int arg4;
18431da177e4SLinus Torvalds 	unsigned int arg3;
18441da177e4SLinus Torvalds 	unsigned int arg2;
18451da177e4SLinus Torvalds 	unsigned int arg1;
18461da177e4SLinus Torvalds 	unsigned int arg0;
18471da177e4SLinus Torvalds 	unsigned int frame_marker[8];
18481da177e4SLinus Torvalds 	unsigned int sp;
18491da177e4SLinus Torvalds 	/* in reality, there's nearly 8k of stack after this */
18501da177e4SLinus Torvalds };
18511da177e4SLinus Torvalds 
real32_call(unsigned long fn,...)18521da177e4SLinus Torvalds long real32_call(unsigned long fn, ...)
18531da177e4SLinus Torvalds {
18541da177e4SLinus Torvalds 	va_list args;
18551da177e4SLinus Torvalds 	extern struct narrow_stack real_stack;
18561da177e4SLinus Torvalds 	extern unsigned long real32_call_asm(unsigned int *,
18571da177e4SLinus Torvalds 					     unsigned int *,
18581da177e4SLinus Torvalds 					     unsigned int);
18591da177e4SLinus Torvalds 
18601da177e4SLinus Torvalds 	va_start(args, fn);
18611da177e4SLinus Torvalds 	real_stack.arg0 = va_arg(args, unsigned int);
18621da177e4SLinus Torvalds 	real_stack.arg1 = va_arg(args, unsigned int);
18631da177e4SLinus Torvalds 	real_stack.arg2 = va_arg(args, unsigned int);
18641da177e4SLinus Torvalds 	real_stack.arg3 = va_arg(args, unsigned int);
18651da177e4SLinus Torvalds 	real_stack.arg4 = va_arg(args, unsigned int);
18661da177e4SLinus Torvalds 	real_stack.arg5 = va_arg(args, unsigned int);
18671da177e4SLinus Torvalds 	real_stack.arg6 = va_arg(args, unsigned int);
18681da177e4SLinus Torvalds 	real_stack.arg7 = va_arg(args, unsigned int);
18691da177e4SLinus Torvalds 	real_stack.arg8 = va_arg(args, unsigned int);
18701da177e4SLinus Torvalds 	real_stack.arg9 = va_arg(args, unsigned int);
18711da177e4SLinus Torvalds 	real_stack.arg10 = va_arg(args, unsigned int);
18721da177e4SLinus Torvalds 	real_stack.arg11 = va_arg(args, unsigned int);
18731da177e4SLinus Torvalds 	real_stack.arg12 = va_arg(args, unsigned int);
18741da177e4SLinus Torvalds 	real_stack.arg13 = va_arg(args, unsigned int);
18751da177e4SLinus Torvalds 	va_end(args);
18761da177e4SLinus Torvalds 
18771da177e4SLinus Torvalds 	return real32_call_asm(&real_stack.sp, &real_stack.arg0, fn);
18781da177e4SLinus Torvalds }
18791da177e4SLinus Torvalds 
1880a8f44e38SHelge Deller #ifdef CONFIG_64BIT
18811da177e4SLinus Torvalds /***************** 64-bit real-mode calls ***********/
18821da177e4SLinus Torvalds 
18831da177e4SLinus Torvalds struct wide_stack {
18841da177e4SLinus Torvalds 	unsigned long arg0;
18851da177e4SLinus Torvalds 	unsigned long arg1;
18861da177e4SLinus Torvalds 	unsigned long arg2;
18871da177e4SLinus Torvalds 	unsigned long arg3;
18881da177e4SLinus Torvalds 	unsigned long arg4;
18891da177e4SLinus Torvalds 	unsigned long arg5;
18901da177e4SLinus Torvalds 	unsigned long arg6;
18911da177e4SLinus Torvalds 	unsigned long arg7;
18921da177e4SLinus Torvalds 	unsigned long arg8;
18931da177e4SLinus Torvalds 	unsigned long arg9;
18941da177e4SLinus Torvalds 	unsigned long arg10;
18951da177e4SLinus Torvalds 	unsigned long arg11;
18961da177e4SLinus Torvalds 	unsigned long arg12;
18971da177e4SLinus Torvalds 	unsigned long arg13;
18981da177e4SLinus Torvalds 	unsigned long frame_marker[2];	/* rp, previous sp */
18991da177e4SLinus Torvalds 	unsigned long sp;
19001da177e4SLinus Torvalds 	/* in reality, there's nearly 8k of stack after this */
19011da177e4SLinus Torvalds };
19021da177e4SLinus Torvalds 
real64_call(unsigned long fn,...)19031da177e4SLinus Torvalds long real64_call(unsigned long fn, ...)
19041da177e4SLinus Torvalds {
19051da177e4SLinus Torvalds 	va_list args;
19061da177e4SLinus Torvalds 	extern struct wide_stack real64_stack;
19071da177e4SLinus Torvalds 	extern unsigned long real64_call_asm(unsigned long *,
19081da177e4SLinus Torvalds 					     unsigned long *,
19091da177e4SLinus Torvalds 					     unsigned long);
19101da177e4SLinus Torvalds 
19111da177e4SLinus Torvalds 	va_start(args, fn);
19121da177e4SLinus Torvalds 	real64_stack.arg0 = va_arg(args, unsigned long);
19131da177e4SLinus Torvalds 	real64_stack.arg1 = va_arg(args, unsigned long);
19141da177e4SLinus Torvalds 	real64_stack.arg2 = va_arg(args, unsigned long);
19151da177e4SLinus Torvalds 	real64_stack.arg3 = va_arg(args, unsigned long);
19161da177e4SLinus Torvalds 	real64_stack.arg4 = va_arg(args, unsigned long);
19171da177e4SLinus Torvalds 	real64_stack.arg5 = va_arg(args, unsigned long);
19181da177e4SLinus Torvalds 	real64_stack.arg6 = va_arg(args, unsigned long);
19191da177e4SLinus Torvalds 	real64_stack.arg7 = va_arg(args, unsigned long);
19201da177e4SLinus Torvalds 	real64_stack.arg8 = va_arg(args, unsigned long);
19211da177e4SLinus Torvalds 	real64_stack.arg9 = va_arg(args, unsigned long);
19221da177e4SLinus Torvalds 	real64_stack.arg10 = va_arg(args, unsigned long);
19231da177e4SLinus Torvalds 	real64_stack.arg11 = va_arg(args, unsigned long);
19241da177e4SLinus Torvalds 	real64_stack.arg12 = va_arg(args, unsigned long);
19251da177e4SLinus Torvalds 	real64_stack.arg13 = va_arg(args, unsigned long);
19261da177e4SLinus Torvalds 	va_end(args);
19271da177e4SLinus Torvalds 
19281da177e4SLinus Torvalds 	return real64_call_asm(&real64_stack.sp, &real64_stack.arg0, fn);
19291da177e4SLinus Torvalds }
19301da177e4SLinus Torvalds 
1931a8f44e38SHelge Deller #endif /* CONFIG_64BIT */
1932