firmware.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * arch/parisc/kernel/firmware.c - safe PDC access routines
  4. *
  5. * PDC == Processor Dependent Code
  6. *
  7. * See PDC documentation at
  8. * https://parisc.wiki.kernel.org/index.php/Technical_Documentation
  9. * for documentation describing the entry points and calling
  10. * conventions defined below.
  11. *
  12. * Copyright 1999 SuSE GmbH Nuernberg (Philipp Rumpf, [email protected])
  13. * Copyright 1999 The Puffin Group, (Alex deVries, David Kennedy)
  14. * Copyright 2003 Grant Grundler <grundler parisc-linux org>
  15. * Copyright 2003,2004 Ryan Bradetich <[email protected]>
  16. * Copyright 2004,2006 Thibaut VARENE <[email protected]>
  17. */
  18. /* I think it would be in everyone's best interest to follow this
  19. * guidelines when writing PDC wrappers:
  20. *
  21. * - the name of the pdc wrapper should match one of the macros
  22. * used for the first two arguments
  23. * - don't use caps for random parts of the name
  24. * - use the static PDC result buffers and "copyout" to structs
  25. * supplied by the caller to encapsulate alignment restrictions
  26. * - hold pdc_lock while in PDC or using static result buffers
  27. * - use __pa() to convert virtual (kernel) pointers to physical
  28. * ones.
  29. * - the name of the struct used for pdc return values should equal
  30. * one of the macros used for the first two arguments to the
  31. * corresponding PDC call
  32. * - keep the order of arguments
  33. * - don't be smart (setting trailing NUL bytes for strings, return
  34. * something useful even if the call failed) unless you are sure
  35. * it's not going to affect functionality or performance
  36. *
  37. * Example:
  38. * int pdc_cache_info(struct pdc_cache_info *cache_info )
  39. * {
  40. * int retval;
  41. *
  42. * spin_lock_irq(&pdc_lock);
  43. * retval = mem_pdc_call(PDC_CACHE,PDC_CACHE_INFO,__pa(cache_info),0);
  44. * convert_to_wide(pdc_result);
  45. * memcpy(cache_info, pdc_result, sizeof(*cache_info));
  46. * spin_unlock_irq(&pdc_lock);
  47. *
  48. * return retval;
  49. * }
  50. * prumpf 991016
  51. */
  52. #include <linux/stdarg.h>
  53. #include <linux/delay.h>
  54. #include <linux/init.h>
  55. #include <linux/kernel.h>
  56. #include <linux/module.h>
  57. #include <linux/string.h>
  58. #include <linux/spinlock.h>
  59. #include <asm/page.h>
  60. #include <asm/pdc.h>
  61. #include <asm/pdcpat.h>
  62. #include <asm/processor.h> /* for boot_cpu_data */
  63. #if defined(BOOTLOADER)
  64. # undef spin_lock_irqsave
  65. # define spin_lock_irqsave(a, b) { b = 1; }
  66. # undef spin_unlock_irqrestore
  67. # define spin_unlock_irqrestore(a, b)
  68. #else
  69. static DEFINE_SPINLOCK(pdc_lock);
  70. #endif
  71. extern unsigned long pdc_result[NUM_PDC_RESULT];
  72. extern unsigned long pdc_result2[NUM_PDC_RESULT];
  73. #ifdef CONFIG_64BIT
  74. #define WIDE_FIRMWARE 0x1
  75. #define NARROW_FIRMWARE 0x2
  76. /* Firmware needs to be initially set to narrow to determine the
  77. * actual firmware width. */
  78. int parisc_narrow_firmware __ro_after_init = 2;
  79. #endif
  80. /* On most currently-supported platforms, IODC I/O calls are 32-bit calls
  81. * and MEM_PDC calls are always the same width as the OS.
  82. * Some PAT boxes may have 64-bit IODC I/O.
  83. *
  84. * Ryan Bradetich added the now obsolete CONFIG_PDC_NARROW to allow
  85. * 64-bit kernels to run on systems with 32-bit MEM_PDC calls.
  86. * This allowed wide kernels to run on Cxxx boxes.
  87. * We now detect 32-bit-only PDC and dynamically switch to 32-bit mode
  88. * when running a 64-bit kernel on such boxes (e.g. C200 or C360).
  89. */
  90. #ifdef CONFIG_64BIT
  91. long real64_call(unsigned long function, ...);
  92. #endif
  93. long real32_call(unsigned long function, ...);
  94. #ifdef CONFIG_64BIT
  95. # define MEM_PDC (unsigned long)(PAGE0->mem_pdc_hi) << 32 | PAGE0->mem_pdc
  96. # define mem_pdc_call(args...) unlikely(parisc_narrow_firmware) ? real32_call(MEM_PDC, args) : real64_call(MEM_PDC, args)
  97. #else
  98. # define MEM_PDC (unsigned long)PAGE0->mem_pdc
  99. # define mem_pdc_call(args...) real32_call(MEM_PDC, args)
  100. #endif
  101. /**
  102. * f_extend - Convert PDC addresses to kernel addresses.
  103. * @address: Address returned from PDC.
  104. *
  105. * This function is used to convert PDC addresses into kernel addresses
  106. * when the PDC address size and kernel address size are different.
  107. */
  108. static unsigned long f_extend(unsigned long address)
  109. {
  110. #ifdef CONFIG_64BIT
  111. if(unlikely(parisc_narrow_firmware)) {
  112. if((address & 0xff000000) == 0xf0000000)
  113. return 0xf0f0f0f000000000UL | (u32)address;
  114. if((address & 0xf0000000) == 0xf0000000)
  115. return 0xffffffff00000000UL | (u32)address;
  116. }
  117. #endif
  118. return address;
  119. }
  120. /**
  121. * convert_to_wide - Convert the return buffer addresses into kernel addresses.
  122. * @address: The return buffer from PDC.
  123. *
  124. * This function is used to convert the return buffer addresses retrieved from PDC
  125. * into kernel addresses when the PDC address size and kernel address size are
  126. * different.
  127. */
  128. static void convert_to_wide(unsigned long *addr)
  129. {
  130. #ifdef CONFIG_64BIT
  131. int i;
  132. unsigned int *p = (unsigned int *)addr;
  133. if (unlikely(parisc_narrow_firmware)) {
  134. for (i = (NUM_PDC_RESULT-1); i >= 0; --i)
  135. addr[i] = p[i];
  136. }
  137. #endif
  138. }
  139. #ifdef CONFIG_64BIT
  140. void set_firmware_width_unlocked(void)
  141. {
  142. int ret;
  143. ret = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES,
  144. __pa(pdc_result), 0);
  145. convert_to_wide(pdc_result);
  146. if (pdc_result[0] != NARROW_FIRMWARE)
  147. parisc_narrow_firmware = 0;
  148. }
  149. /**
  150. * set_firmware_width - Determine if the firmware is wide or narrow.
  151. *
  152. * This function must be called before any pdc_* function that uses the
  153. * convert_to_wide function.
  154. */
  155. void set_firmware_width(void)
  156. {
  157. unsigned long flags;
  158. /* already initialized? */
  159. if (parisc_narrow_firmware != 2)
  160. return;
  161. spin_lock_irqsave(&pdc_lock, flags);
  162. set_firmware_width_unlocked();
  163. spin_unlock_irqrestore(&pdc_lock, flags);
  164. }
  165. #else
  166. void set_firmware_width_unlocked(void)
  167. {
  168. return;
  169. }
  170. void set_firmware_width(void)
  171. {
  172. return;
  173. }
  174. #endif /*CONFIG_64BIT*/
  175. #if !defined(BOOTLOADER)
  176. /**
  177. * pdc_emergency_unlock - Unlock the linux pdc lock
  178. *
  179. * This call unlocks the linux pdc lock in case we need some PDC functions
  180. * (like pdc_add_valid) during kernel stack dump.
  181. */
  182. void pdc_emergency_unlock(void)
  183. {
  184. /* Spinlock DEBUG code freaks out if we unconditionally unlock */
  185. if (spin_is_locked(&pdc_lock))
  186. spin_unlock(&pdc_lock);
  187. }
  188. /**
  189. * pdc_add_valid - Verify address can be accessed without causing a HPMC.
  190. * @address: Address to be verified.
  191. *
  192. * This PDC call attempts to read from the specified address and verifies
  193. * if the address is valid.
  194. *
  195. * The return value is PDC_OK (0) in case accessing this address is valid.
  196. */
  197. int pdc_add_valid(unsigned long address)
  198. {
  199. int retval;
  200. unsigned long flags;
  201. spin_lock_irqsave(&pdc_lock, flags);
  202. retval = mem_pdc_call(PDC_ADD_VALID, PDC_ADD_VALID_VERIFY, address);
  203. spin_unlock_irqrestore(&pdc_lock, flags);
  204. return retval;
  205. }
  206. EXPORT_SYMBOL(pdc_add_valid);
  207. /**
  208. * pdc_instr - Get instruction that invokes PDCE_CHECK in HPMC handler.
  209. * @instr: Pointer to variable which will get instruction opcode.
  210. *
  211. * The return value is PDC_OK (0) in case call succeeded.
  212. */
  213. int __init pdc_instr(unsigned int *instr)
  214. {
  215. int retval;
  216. unsigned long flags;
  217. spin_lock_irqsave(&pdc_lock, flags);
  218. retval = mem_pdc_call(PDC_INSTR, 0UL, __pa(pdc_result));
  219. convert_to_wide(pdc_result);
  220. *instr = pdc_result[0];
  221. spin_unlock_irqrestore(&pdc_lock, flags);
  222. return retval;
  223. }
  224. /**
  225. * pdc_chassis_info - Return chassis information.
  226. * @result: The return buffer.
  227. * @chassis_info: The memory buffer address.
  228. * @len: The size of the memory buffer address.
  229. *
  230. * An HVERSION dependent call for returning the chassis information.
  231. */
  232. int __init pdc_chassis_info(struct pdc_chassis_info *chassis_info, void *led_info, unsigned long len)
  233. {
  234. int retval;
  235. unsigned long flags;
  236. spin_lock_irqsave(&pdc_lock, flags);
  237. memcpy(&pdc_result, chassis_info, sizeof(*chassis_info));
  238. memcpy(&pdc_result2, led_info, len);
  239. retval = mem_pdc_call(PDC_CHASSIS, PDC_RETURN_CHASSIS_INFO,
  240. __pa(pdc_result), __pa(pdc_result2), len);
  241. memcpy(chassis_info, pdc_result, sizeof(*chassis_info));
  242. memcpy(led_info, pdc_result2, len);
  243. spin_unlock_irqrestore(&pdc_lock, flags);
  244. return retval;
  245. }
  246. /**
  247. * pdc_pat_chassis_send_log - Sends a PDC PAT CHASSIS log message.
  248. * @retval: -1 on error, 0 on success. Other value are PDC errors
  249. *
  250. * Must be correctly formatted or expect system crash
  251. */
  252. #ifdef CONFIG_64BIT
  253. int pdc_pat_chassis_send_log(unsigned long state, unsigned long data)
  254. {
  255. int retval = 0;
  256. unsigned long flags;
  257. if (!is_pdc_pat())
  258. return -1;
  259. spin_lock_irqsave(&pdc_lock, flags);
  260. retval = mem_pdc_call(PDC_PAT_CHASSIS_LOG, PDC_PAT_CHASSIS_WRITE_LOG, __pa(&state), __pa(&data));
  261. spin_unlock_irqrestore(&pdc_lock, flags);
  262. return retval;
  263. }
  264. #endif
  265. /**
  266. * pdc_chassis_disp - Updates chassis code
  267. * @retval: -1 on error, 0 on success
  268. */
  269. int pdc_chassis_disp(unsigned long disp)
  270. {
  271. int retval = 0;
  272. unsigned long flags;
  273. spin_lock_irqsave(&pdc_lock, flags);
  274. retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_DISP, disp);
  275. spin_unlock_irqrestore(&pdc_lock, flags);
  276. return retval;
  277. }
  278. /**
  279. * pdc_cpu_rendenzvous - Stop currently executing CPU
  280. * @retval: -1 on error, 0 on success
  281. */
  282. int __pdc_cpu_rendezvous(void)
  283. {
  284. if (is_pdc_pat())
  285. return mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_RENDEZVOUS);
  286. else
  287. return mem_pdc_call(PDC_PROC, 1, 0);
  288. }
  289. /**
  290. * pdc_cpu_rendezvous_lock - Lock PDC while transitioning to rendezvous state
  291. */
  292. void pdc_cpu_rendezvous_lock(void)
  293. {
  294. spin_lock(&pdc_lock);
  295. }
  296. /**
  297. * pdc_cpu_rendezvous_unlock - Unlock PDC after reaching rendezvous state
  298. */
  299. void pdc_cpu_rendezvous_unlock(void)
  300. {
  301. spin_unlock(&pdc_lock);
  302. }
  303. /**
  304. * pdc_pat_get_PDC_entrypoint - Get PDC entry point for current CPU
  305. * @retval: -1 on error, 0 on success
  306. */
  307. int pdc_pat_get_PDC_entrypoint(unsigned long *pdc_entry)
  308. {
  309. int retval = 0;
  310. unsigned long flags;
  311. if (!IS_ENABLED(CONFIG_SMP) || !is_pdc_pat()) {
  312. *pdc_entry = MEM_PDC;
  313. return 0;
  314. }
  315. spin_lock_irqsave(&pdc_lock, flags);
  316. retval = mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_GET_PDC_ENTRYPOINT,
  317. __pa(pdc_result));
  318. *pdc_entry = pdc_result[0];
  319. spin_unlock_irqrestore(&pdc_lock, flags);
  320. return retval;
  321. }
  322. /**
  323. * pdc_chassis_warn - Fetches chassis warnings
  324. * @retval: -1 on error, 0 on success
  325. */
  326. int pdc_chassis_warn(unsigned long *warn)
  327. {
  328. int retval = 0;
  329. unsigned long flags;
  330. spin_lock_irqsave(&pdc_lock, flags);
  331. retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_WARN, __pa(pdc_result));
  332. *warn = pdc_result[0];
  333. spin_unlock_irqrestore(&pdc_lock, flags);
  334. return retval;
  335. }
  336. int pdc_coproc_cfg_unlocked(struct pdc_coproc_cfg *pdc_coproc_info)
  337. {
  338. int ret;
  339. ret = mem_pdc_call(PDC_COPROC, PDC_COPROC_CFG, __pa(pdc_result));
  340. convert_to_wide(pdc_result);
  341. pdc_coproc_info->ccr_functional = pdc_result[0];
  342. pdc_coproc_info->ccr_present = pdc_result[1];
  343. pdc_coproc_info->revision = pdc_result[17];
  344. pdc_coproc_info->model = pdc_result[18];
  345. return ret;
  346. }
  347. /**
  348. * pdc_coproc_cfg - To identify coprocessors attached to the processor.
  349. * @pdc_coproc_info: Return buffer address.
  350. *
  351. * This PDC call returns the presence and status of all the coprocessors
  352. * attached to the processor.
  353. */
  354. int pdc_coproc_cfg(struct pdc_coproc_cfg *pdc_coproc_info)
  355. {
  356. int ret;
  357. unsigned long flags;
  358. spin_lock_irqsave(&pdc_lock, flags);
  359. ret = pdc_coproc_cfg_unlocked(pdc_coproc_info);
  360. spin_unlock_irqrestore(&pdc_lock, flags);
  361. return ret;
  362. }
  363. /**
  364. * pdc_iodc_read - Read data from the modules IODC.
  365. * @actcnt: The actual number of bytes.
  366. * @hpa: The HPA of the module for the iodc read.
  367. * @index: The iodc entry point.
  368. * @iodc_data: A buffer memory for the iodc options.
  369. * @iodc_data_size: Size of the memory buffer.
  370. *
  371. * This PDC call reads from the IODC of the module specified by the hpa
  372. * argument.
  373. */
  374. int pdc_iodc_read(unsigned long *actcnt, unsigned long hpa, unsigned int index,
  375. void *iodc_data, unsigned int iodc_data_size)
  376. {
  377. int retval;
  378. unsigned long flags;
  379. spin_lock_irqsave(&pdc_lock, flags);
  380. retval = mem_pdc_call(PDC_IODC, PDC_IODC_READ, __pa(pdc_result), hpa,
  381. index, __pa(pdc_result2), iodc_data_size);
  382. convert_to_wide(pdc_result);
  383. *actcnt = pdc_result[0];
  384. memcpy(iodc_data, pdc_result2, iodc_data_size);
  385. spin_unlock_irqrestore(&pdc_lock, flags);
  386. return retval;
  387. }
  388. EXPORT_SYMBOL(pdc_iodc_read);
  389. /**
  390. * pdc_system_map_find_mods - Locate unarchitected modules.
  391. * @pdc_mod_info: Return buffer address.
  392. * @mod_path: pointer to dev path structure.
  393. * @mod_index: fixed address module index.
  394. *
  395. * To locate and identify modules which reside at fixed I/O addresses, which
  396. * do not self-identify via architected bus walks.
  397. */
  398. int pdc_system_map_find_mods(struct pdc_system_map_mod_info *pdc_mod_info,
  399. struct pdc_module_path *mod_path, long mod_index)
  400. {
  401. int retval;
  402. unsigned long flags;
  403. spin_lock_irqsave(&pdc_lock, flags);
  404. retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_MODULE, __pa(pdc_result),
  405. __pa(pdc_result2), mod_index);
  406. convert_to_wide(pdc_result);
  407. memcpy(pdc_mod_info, pdc_result, sizeof(*pdc_mod_info));
  408. memcpy(mod_path, pdc_result2, sizeof(*mod_path));
  409. spin_unlock_irqrestore(&pdc_lock, flags);
  410. pdc_mod_info->mod_addr = f_extend(pdc_mod_info->mod_addr);
  411. return retval;
  412. }
  413. /**
  414. * pdc_system_map_find_addrs - Retrieve additional address ranges.
  415. * @pdc_addr_info: Return buffer address.
  416. * @mod_index: Fixed address module index.
  417. * @addr_index: Address range index.
  418. *
  419. * Retrieve additional information about subsequent address ranges for modules
  420. * with multiple address ranges.
  421. */
  422. int pdc_system_map_find_addrs(struct pdc_system_map_addr_info *pdc_addr_info,
  423. long mod_index, long addr_index)
  424. {
  425. int retval;
  426. unsigned long flags;
  427. spin_lock_irqsave(&pdc_lock, flags);
  428. retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_ADDRESS, __pa(pdc_result),
  429. mod_index, addr_index);
  430. convert_to_wide(pdc_result);
  431. memcpy(pdc_addr_info, pdc_result, sizeof(*pdc_addr_info));
  432. spin_unlock_irqrestore(&pdc_lock, flags);
  433. pdc_addr_info->mod_addr = f_extend(pdc_addr_info->mod_addr);
  434. return retval;
  435. }
  436. /**
  437. * pdc_model_info - Return model information about the processor.
  438. * @model: The return buffer.
  439. *
  440. * Returns the version numbers, identifiers, and capabilities from the processor module.
  441. */
  442. int pdc_model_info(struct pdc_model *model)
  443. {
  444. int retval;
  445. unsigned long flags;
  446. spin_lock_irqsave(&pdc_lock, flags);
  447. retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_INFO, __pa(pdc_result), 0);
  448. convert_to_wide(pdc_result);
  449. memcpy(model, pdc_result, sizeof(*model));
  450. spin_unlock_irqrestore(&pdc_lock, flags);
  451. return retval;
  452. }
  453. /**
  454. * pdc_model_sysmodel - Get the system model name.
  455. * @name: A char array of at least 81 characters.
  456. *
  457. * Get system model name from PDC ROM (e.g. 9000/715 or 9000/778/B160L).
  458. * Using OS_ID_HPUX will return the equivalent of the 'modelname' command
  459. * on HP/UX.
  460. */
  461. int pdc_model_sysmodel(char *name)
  462. {
  463. int retval;
  464. unsigned long flags;
  465. spin_lock_irqsave(&pdc_lock, flags);
  466. retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_SYSMODEL, __pa(pdc_result),
  467. OS_ID_HPUX, __pa(name));
  468. convert_to_wide(pdc_result);
  469. if (retval == PDC_OK) {
  470. name[pdc_result[0]] = '\0'; /* add trailing '\0' */
  471. } else {
  472. name[0] = 0;
  473. }
  474. spin_unlock_irqrestore(&pdc_lock, flags);
  475. return retval;
  476. }
  477. /**
  478. * pdc_model_versions - Identify the version number of each processor.
  479. * @cpu_id: The return buffer.
  480. * @id: The id of the processor to check.
  481. *
  482. * Returns the version number for each processor component.
  483. *
  484. * This comment was here before, but I do not know what it means :( -RB
  485. * id: 0 = cpu revision, 1 = boot-rom-version
  486. */
  487. int pdc_model_versions(unsigned long *versions, int id)
  488. {
  489. int retval;
  490. unsigned long flags;
  491. spin_lock_irqsave(&pdc_lock, flags);
  492. retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_VERSIONS, __pa(pdc_result), id);
  493. convert_to_wide(pdc_result);
  494. *versions = pdc_result[0];
  495. spin_unlock_irqrestore(&pdc_lock, flags);
  496. return retval;
  497. }
  498. /**
  499. * pdc_model_cpuid - Returns the CPU_ID.
  500. * @cpu_id: The return buffer.
  501. *
  502. * Returns the CPU_ID value which uniquely identifies the cpu portion of
  503. * the processor module.
  504. */
  505. int pdc_model_cpuid(unsigned long *cpu_id)
  506. {
  507. int retval;
  508. unsigned long flags;
  509. spin_lock_irqsave(&pdc_lock, flags);
  510. pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
  511. retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CPU_ID, __pa(pdc_result), 0);
  512. convert_to_wide(pdc_result);
  513. *cpu_id = pdc_result[0];
  514. spin_unlock_irqrestore(&pdc_lock, flags);
  515. return retval;
  516. }
  517. /**
  518. * pdc_model_capabilities - Returns the platform capabilities.
  519. * @capabilities: The return buffer.
  520. *
  521. * Returns information about platform support for 32- and/or 64-bit
  522. * OSes, IO-PDIR coherency, and virtual aliasing.
  523. */
  524. int pdc_model_capabilities(unsigned long *capabilities)
  525. {
  526. int retval;
  527. unsigned long flags;
  528. spin_lock_irqsave(&pdc_lock, flags);
  529. pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
  530. retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES, __pa(pdc_result), 0);
  531. convert_to_wide(pdc_result);
  532. if (retval == PDC_OK) {
  533. *capabilities = pdc_result[0];
  534. } else {
  535. *capabilities = PDC_MODEL_OS32;
  536. }
  537. spin_unlock_irqrestore(&pdc_lock, flags);
  538. return retval;
  539. }
  540. /**
  541. * pdc_model_platform_info - Returns machine product and serial number.
  542. * @orig_prod_num: Return buffer for original product number.
  543. * @current_prod_num: Return buffer for current product number.
  544. * @serial_no: Return buffer for serial number.
  545. *
  546. * Returns strings containing the original and current product numbers and the
  547. * serial number of the system.
  548. */
  549. int pdc_model_platform_info(char *orig_prod_num, char *current_prod_num,
  550. char *serial_no)
  551. {
  552. int retval;
  553. unsigned long flags;
  554. spin_lock_irqsave(&pdc_lock, flags);
  555. retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_GET_PLATFORM_INFO,
  556. __pa(orig_prod_num), __pa(current_prod_num), __pa(serial_no));
  557. convert_to_wide(pdc_result);
  558. spin_unlock_irqrestore(&pdc_lock, flags);
  559. return retval;
  560. }
  561. /**
  562. * pdc_cache_info - Return cache and TLB information.
  563. * @cache_info: The return buffer.
  564. *
  565. * Returns information about the processor's cache and TLB.
  566. */
  567. int pdc_cache_info(struct pdc_cache_info *cache_info)
  568. {
  569. int retval;
  570. unsigned long flags;
  571. spin_lock_irqsave(&pdc_lock, flags);
  572. retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_INFO, __pa(pdc_result), 0);
  573. convert_to_wide(pdc_result);
  574. memcpy(cache_info, pdc_result, sizeof(*cache_info));
  575. spin_unlock_irqrestore(&pdc_lock, flags);
  576. return retval;
  577. }
  578. /**
  579. * pdc_spaceid_bits - Return whether Space ID hashing is turned on.
  580. * @space_bits: Should be 0, if not, bad mojo!
  581. *
  582. * Returns information about Space ID hashing.
  583. */
  584. int pdc_spaceid_bits(unsigned long *space_bits)
  585. {
  586. int retval;
  587. unsigned long flags;
  588. spin_lock_irqsave(&pdc_lock, flags);
  589. pdc_result[0] = 0;
  590. retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_RET_SPID, __pa(pdc_result), 0);
  591. convert_to_wide(pdc_result);
  592. *space_bits = pdc_result[0];
  593. spin_unlock_irqrestore(&pdc_lock, flags);
  594. return retval;
  595. }
  596. #ifndef CONFIG_PA20
  597. /**
  598. * pdc_btlb_info - Return block TLB information.
  599. * @btlb: The return buffer.
  600. *
  601. * Returns information about the hardware Block TLB.
  602. */
  603. int pdc_btlb_info(struct pdc_btlb_info *btlb)
  604. {
  605. int retval;
  606. unsigned long flags;
  607. spin_lock_irqsave(&pdc_lock, flags);
  608. retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_INFO, __pa(pdc_result), 0);
  609. memcpy(btlb, pdc_result, sizeof(*btlb));
  610. spin_unlock_irqrestore(&pdc_lock, flags);
  611. if(retval < 0) {
  612. btlb->max_size = 0;
  613. }
  614. return retval;
  615. }
  616. /**
  617. * pdc_mem_map_hpa - Find fixed module information.
  618. * @address: The return buffer
  619. * @mod_path: pointer to dev path structure.
  620. *
  621. * This call was developed for S700 workstations to allow the kernel to find
  622. * the I/O devices (Core I/O). In the future (Kittyhawk and beyond) this
  623. * call will be replaced (on workstations) by the architected PDC_SYSTEM_MAP
  624. * call.
  625. *
  626. * This call is supported by all existing S700 workstations (up to Gecko).
  627. */
  628. int pdc_mem_map_hpa(struct pdc_memory_map *address,
  629. struct pdc_module_path *mod_path)
  630. {
  631. int retval;
  632. unsigned long flags;
  633. spin_lock_irqsave(&pdc_lock, flags);
  634. memcpy(pdc_result2, mod_path, sizeof(*mod_path));
  635. retval = mem_pdc_call(PDC_MEM_MAP, PDC_MEM_MAP_HPA, __pa(pdc_result),
  636. __pa(pdc_result2));
  637. memcpy(address, pdc_result, sizeof(*address));
  638. spin_unlock_irqrestore(&pdc_lock, flags);
  639. return retval;
  640. }
  641. #endif /* !CONFIG_PA20 */
  642. /**
  643. * pdc_lan_station_id - Get the LAN address.
  644. * @lan_addr: The return buffer.
  645. * @hpa: The network device HPA.
  646. *
  647. * Get the LAN station address when it is not directly available from the LAN hardware.
  648. */
  649. int pdc_lan_station_id(char *lan_addr, unsigned long hpa)
  650. {
  651. int retval;
  652. unsigned long flags;
  653. spin_lock_irqsave(&pdc_lock, flags);
  654. retval = mem_pdc_call(PDC_LAN_STATION_ID, PDC_LAN_STATION_ID_READ,
  655. __pa(pdc_result), hpa);
  656. if (retval < 0) {
  657. /* FIXME: else read MAC from NVRAM */
  658. memset(lan_addr, 0, PDC_LAN_STATION_ID_SIZE);
  659. } else {
  660. memcpy(lan_addr, pdc_result, PDC_LAN_STATION_ID_SIZE);
  661. }
  662. spin_unlock_irqrestore(&pdc_lock, flags);
  663. return retval;
  664. }
  665. EXPORT_SYMBOL(pdc_lan_station_id);
  666. /**
  667. * pdc_stable_read - Read data from Stable Storage.
  668. * @staddr: Stable Storage address to access.
  669. * @memaddr: The memory address where Stable Storage data shall be copied.
  670. * @count: number of bytes to transfer. count is multiple of 4.
  671. *
  672. * This PDC call reads from the Stable Storage address supplied in staddr
  673. * and copies count bytes to the memory address memaddr.
  674. * The call will fail if staddr+count > PDC_STABLE size.
  675. */
  676. int pdc_stable_read(unsigned long staddr, void *memaddr, unsigned long count)
  677. {
  678. int retval;
  679. unsigned long flags;
  680. spin_lock_irqsave(&pdc_lock, flags);
  681. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_READ, staddr,
  682. __pa(pdc_result), count);
  683. convert_to_wide(pdc_result);
  684. memcpy(memaddr, pdc_result, count);
  685. spin_unlock_irqrestore(&pdc_lock, flags);
  686. return retval;
  687. }
  688. EXPORT_SYMBOL(pdc_stable_read);
  689. /**
  690. * pdc_stable_write - Write data to Stable Storage.
  691. * @staddr: Stable Storage address to access.
  692. * @memaddr: The memory address where Stable Storage data shall be read from.
  693. * @count: number of bytes to transfer. count is multiple of 4.
  694. *
  695. * This PDC call reads count bytes from the supplied memaddr address,
  696. * and copies count bytes to the Stable Storage address staddr.
  697. * The call will fail if staddr+count > PDC_STABLE size.
  698. */
  699. int pdc_stable_write(unsigned long staddr, void *memaddr, unsigned long count)
  700. {
  701. int retval;
  702. unsigned long flags;
  703. spin_lock_irqsave(&pdc_lock, flags);
  704. memcpy(pdc_result, memaddr, count);
  705. convert_to_wide(pdc_result);
  706. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_WRITE, staddr,
  707. __pa(pdc_result), count);
  708. spin_unlock_irqrestore(&pdc_lock, flags);
  709. return retval;
  710. }
  711. EXPORT_SYMBOL(pdc_stable_write);
  712. /**
  713. * pdc_stable_get_size - Get Stable Storage size in bytes.
  714. * @size: pointer where the size will be stored.
  715. *
  716. * This PDC call returns the number of bytes in the processor's Stable
  717. * Storage, which is the number of contiguous bytes implemented in Stable
  718. * Storage starting from staddr=0. size in an unsigned 64-bit integer
  719. * which is a multiple of four.
  720. */
  721. int pdc_stable_get_size(unsigned long *size)
  722. {
  723. int retval;
  724. unsigned long flags;
  725. spin_lock_irqsave(&pdc_lock, flags);
  726. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_RETURN_SIZE, __pa(pdc_result));
  727. *size = pdc_result[0];
  728. spin_unlock_irqrestore(&pdc_lock, flags);
  729. return retval;
  730. }
  731. EXPORT_SYMBOL(pdc_stable_get_size);
  732. /**
  733. * pdc_stable_verify_contents - Checks that Stable Storage contents are valid.
  734. *
  735. * This PDC call is meant to be used to check the integrity of the current
  736. * contents of Stable Storage.
  737. */
  738. int pdc_stable_verify_contents(void)
  739. {
  740. int retval;
  741. unsigned long flags;
  742. spin_lock_irqsave(&pdc_lock, flags);
  743. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_VERIFY_CONTENTS);
  744. spin_unlock_irqrestore(&pdc_lock, flags);
  745. return retval;
  746. }
  747. EXPORT_SYMBOL(pdc_stable_verify_contents);
  748. /**
  749. * pdc_stable_initialize - Sets Stable Storage contents to zero and initialize
  750. * the validity indicator.
  751. *
  752. * This PDC call will erase all contents of Stable Storage. Use with care!
  753. */
  754. int pdc_stable_initialize(void)
  755. {
  756. int retval;
  757. unsigned long flags;
  758. spin_lock_irqsave(&pdc_lock, flags);
  759. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_INITIALIZE);
  760. spin_unlock_irqrestore(&pdc_lock, flags);
  761. return retval;
  762. }
  763. EXPORT_SYMBOL(pdc_stable_initialize);
  764. /**
  765. * pdc_get_initiator - Get the SCSI Interface Card params (SCSI ID, SDTR, SE or LVD)
  766. * @hwpath: fully bc.mod style path to the device.
  767. * @initiator: the array to return the result into
  768. *
  769. * Get the SCSI operational parameters from PDC.
  770. * Needed since HPUX never used BIOS or symbios card NVRAM.
  771. * Most ncr/sym cards won't have an entry and just use whatever
  772. * capabilities of the card are (eg Ultra, LVD). But there are
  773. * several cases where it's useful:
  774. * o set SCSI id for Multi-initiator clusters,
  775. * o cable too long (ie SE scsi 10Mhz won't support 6m length),
  776. * o bus width exported is less than what the interface chip supports.
  777. */
  778. int pdc_get_initiator(struct hardware_path *hwpath, struct pdc_initiator *initiator)
  779. {
  780. int retval;
  781. unsigned long flags;
  782. spin_lock_irqsave(&pdc_lock, flags);
  783. /* BCJ-XXXX series boxes. E.G. "9000/785/C3000" */
  784. #define IS_SPROCKETS() (strlen(boot_cpu_data.pdc.sys_model_name) == 14 && \
  785. strncmp(boot_cpu_data.pdc.sys_model_name, "9000/785", 8) == 0)
  786. retval = mem_pdc_call(PDC_INITIATOR, PDC_GET_INITIATOR,
  787. __pa(pdc_result), __pa(hwpath));
  788. if (retval < PDC_OK)
  789. goto out;
  790. if (pdc_result[0] < 16) {
  791. initiator->host_id = pdc_result[0];
  792. } else {
  793. initiator->host_id = -1;
  794. }
  795. /*
  796. * Sprockets and Piranha return 20 or 40 (MT/s). Prelude returns
  797. * 1, 2, 5 or 10 for 5, 10, 20 or 40 MT/s, respectively
  798. */
  799. switch (pdc_result[1]) {
  800. case 1: initiator->factor = 50; break;
  801. case 2: initiator->factor = 25; break;
  802. case 5: initiator->factor = 12; break;
  803. case 25: initiator->factor = 10; break;
  804. case 20: initiator->factor = 12; break;
  805. case 40: initiator->factor = 10; break;
  806. default: initiator->factor = -1; break;
  807. }
  808. if (IS_SPROCKETS()) {
  809. initiator->width = pdc_result[4];
  810. initiator->mode = pdc_result[5];
  811. } else {
  812. initiator->width = -1;
  813. initiator->mode = -1;
  814. }
  815. out:
  816. spin_unlock_irqrestore(&pdc_lock, flags);
  817. return (retval >= PDC_OK);
  818. }
  819. EXPORT_SYMBOL(pdc_get_initiator);
  820. /**
  821. * pdc_pci_irt_size - Get the number of entries in the interrupt routing table.
  822. * @num_entries: The return value.
  823. * @hpa: The HPA for the device.
  824. *
  825. * This PDC function returns the number of entries in the specified cell's
  826. * interrupt table.
  827. * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
  828. */
  829. int pdc_pci_irt_size(unsigned long *num_entries, unsigned long hpa)
  830. {
  831. int retval;
  832. unsigned long flags;
  833. spin_lock_irqsave(&pdc_lock, flags);
  834. retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL_SIZE,
  835. __pa(pdc_result), hpa);
  836. convert_to_wide(pdc_result);
  837. *num_entries = pdc_result[0];
  838. spin_unlock_irqrestore(&pdc_lock, flags);
  839. return retval;
  840. }
  841. /**
  842. * pdc_pci_irt - Get the PCI interrupt routing table.
  843. * @num_entries: The number of entries in the table.
  844. * @hpa: The Hard Physical Address of the device.
  845. * @tbl:
  846. *
  847. * Get the PCI interrupt routing table for the device at the given HPA.
  848. * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
  849. */
  850. int pdc_pci_irt(unsigned long num_entries, unsigned long hpa, void *tbl)
  851. {
  852. int retval;
  853. unsigned long flags;
  854. BUG_ON((unsigned long)tbl & 0x7);
  855. spin_lock_irqsave(&pdc_lock, flags);
  856. pdc_result[0] = num_entries;
  857. retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL,
  858. __pa(pdc_result), hpa, __pa(tbl));
  859. spin_unlock_irqrestore(&pdc_lock, flags);
  860. return retval;
  861. }
  862. #if 0 /* UNTEST CODE - left here in case someone needs it */
  863. /**
  864. * pdc_pci_config_read - read PCI config space.
  865. * @hpa token from PDC to indicate which PCI device
  866. * @pci_addr configuration space address to read from
  867. *
  868. * Read PCI Configuration space *before* linux PCI subsystem is running.
  869. */
  870. unsigned int pdc_pci_config_read(void *hpa, unsigned long cfg_addr)
  871. {
  872. int retval;
  873. unsigned long flags;
  874. spin_lock_irqsave(&pdc_lock, flags);
  875. pdc_result[0] = 0;
  876. pdc_result[1] = 0;
  877. retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_READ_CONFIG,
  878. __pa(pdc_result), hpa, cfg_addr&~3UL, 4UL);
  879. spin_unlock_irqrestore(&pdc_lock, flags);
  880. return retval ? ~0 : (unsigned int) pdc_result[0];
  881. }
  882. /**
  883. * pdc_pci_config_write - read PCI config space.
  884. * @hpa token from PDC to indicate which PCI device
  885. * @pci_addr configuration space address to write
  886. * @val value we want in the 32-bit register
  887. *
  888. * Write PCI Configuration space *before* linux PCI subsystem is running.
  889. */
  890. void pdc_pci_config_write(void *hpa, unsigned long cfg_addr, unsigned int val)
  891. {
  892. int retval;
  893. unsigned long flags;
  894. spin_lock_irqsave(&pdc_lock, flags);
  895. pdc_result[0] = 0;
  896. retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_WRITE_CONFIG,
  897. __pa(pdc_result), hpa,
  898. cfg_addr&~3UL, 4UL, (unsigned long) val);
  899. spin_unlock_irqrestore(&pdc_lock, flags);
  900. return retval;
  901. }
  902. #endif /* UNTESTED CODE */
  903. /**
  904. * pdc_tod_read - Read the Time-Of-Day clock.
  905. * @tod: The return buffer:
  906. *
  907. * Read the Time-Of-Day clock
  908. */
  909. int pdc_tod_read(struct pdc_tod *tod)
  910. {
  911. int retval;
  912. unsigned long flags;
  913. spin_lock_irqsave(&pdc_lock, flags);
  914. retval = mem_pdc_call(PDC_TOD, PDC_TOD_READ, __pa(pdc_result), 0);
  915. convert_to_wide(pdc_result);
  916. memcpy(tod, pdc_result, sizeof(*tod));
  917. spin_unlock_irqrestore(&pdc_lock, flags);
  918. return retval;
  919. }
  920. EXPORT_SYMBOL(pdc_tod_read);
  921. int pdc_mem_pdt_info(struct pdc_mem_retinfo *rinfo)
  922. {
  923. int retval;
  924. unsigned long flags;
  925. spin_lock_irqsave(&pdc_lock, flags);
  926. retval = mem_pdc_call(PDC_MEM, PDC_MEM_MEMINFO, __pa(pdc_result), 0);
  927. convert_to_wide(pdc_result);
  928. memcpy(rinfo, pdc_result, sizeof(*rinfo));
  929. spin_unlock_irqrestore(&pdc_lock, flags);
  930. return retval;
  931. }
  932. int pdc_mem_pdt_read_entries(struct pdc_mem_read_pdt *pret,
  933. unsigned long *pdt_entries_ptr)
  934. {
  935. int retval;
  936. unsigned long flags;
  937. spin_lock_irqsave(&pdc_lock, flags);
  938. retval = mem_pdc_call(PDC_MEM, PDC_MEM_READ_PDT, __pa(pdc_result),
  939. __pa(pdt_entries_ptr));
  940. if (retval == PDC_OK) {
  941. convert_to_wide(pdc_result);
  942. memcpy(pret, pdc_result, sizeof(*pret));
  943. }
  944. spin_unlock_irqrestore(&pdc_lock, flags);
  945. #ifdef CONFIG_64BIT
  946. /*
  947. * 64-bit kernels should not call this PDT function in narrow mode.
  948. * The pdt_entries_ptr array above will now contain 32-bit values
  949. */
  950. if (WARN_ON_ONCE((retval == PDC_OK) && parisc_narrow_firmware))
  951. return PDC_ERROR;
  952. #endif
  953. return retval;
  954. }
  955. /**
  956. * pdc_pim_toc11 - Fetch TOC PIM 1.1 data from firmware.
  957. * @ret: pointer to return buffer
  958. */
  959. int pdc_pim_toc11(struct pdc_toc_pim_11 *ret)
  960. {
  961. int retval;
  962. unsigned long flags;
  963. spin_lock_irqsave(&pdc_lock, flags);
  964. retval = mem_pdc_call(PDC_PIM, PDC_PIM_TOC, __pa(pdc_result),
  965. __pa(ret), sizeof(*ret));
  966. spin_unlock_irqrestore(&pdc_lock, flags);
  967. return retval;
  968. }
  969. /**
  970. * pdc_pim_toc20 - Fetch TOC PIM 2.0 data from firmware.
  971. * @ret: pointer to return buffer
  972. */
  973. int pdc_pim_toc20(struct pdc_toc_pim_20 *ret)
  974. {
  975. int retval;
  976. unsigned long flags;
  977. spin_lock_irqsave(&pdc_lock, flags);
  978. retval = mem_pdc_call(PDC_PIM, PDC_PIM_TOC, __pa(pdc_result),
  979. __pa(ret), sizeof(*ret));
  980. spin_unlock_irqrestore(&pdc_lock, flags);
  981. return retval;
  982. }
  983. /**
  984. * pdc_tod_set - Set the Time-Of-Day clock.
  985. * @sec: The number of seconds since epoch.
  986. * @usec: The number of micro seconds.
  987. *
  988. * Set the Time-Of-Day clock.
  989. */
  990. int pdc_tod_set(unsigned long sec, unsigned long usec)
  991. {
  992. int retval;
  993. unsigned long flags;
  994. spin_lock_irqsave(&pdc_lock, flags);
  995. retval = mem_pdc_call(PDC_TOD, PDC_TOD_WRITE, sec, usec);
  996. spin_unlock_irqrestore(&pdc_lock, flags);
  997. return retval;
  998. }
  999. EXPORT_SYMBOL(pdc_tod_set);
  1000. #ifdef CONFIG_64BIT
  1001. int pdc_mem_mem_table(struct pdc_memory_table_raddr *r_addr,
  1002. struct pdc_memory_table *tbl, unsigned long entries)
  1003. {
  1004. int retval;
  1005. unsigned long flags;
  1006. spin_lock_irqsave(&pdc_lock, flags);
  1007. retval = mem_pdc_call(PDC_MEM, PDC_MEM_TABLE, __pa(pdc_result), __pa(pdc_result2), entries);
  1008. convert_to_wide(pdc_result);
  1009. memcpy(r_addr, pdc_result, sizeof(*r_addr));
  1010. memcpy(tbl, pdc_result2, entries * sizeof(*tbl));
  1011. spin_unlock_irqrestore(&pdc_lock, flags);
  1012. return retval;
  1013. }
  1014. #endif /* CONFIG_64BIT */
  1015. /* FIXME: Is this pdc used? I could not find type reference to ftc_bitmap
  1016. * so I guessed at unsigned long. Someone who knows what this does, can fix
  1017. * it later. :)
  1018. */
  1019. int pdc_do_firm_test_reset(unsigned long ftc_bitmap)
  1020. {
  1021. int retval;
  1022. unsigned long flags;
  1023. spin_lock_irqsave(&pdc_lock, flags);
  1024. retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_FIRM_TEST_RESET,
  1025. PDC_FIRM_TEST_MAGIC, ftc_bitmap);
  1026. spin_unlock_irqrestore(&pdc_lock, flags);
  1027. return retval;
  1028. }
  1029. /*
  1030. * pdc_do_reset - Reset the system.
  1031. *
  1032. * Reset the system.
  1033. */
  1034. int pdc_do_reset(void)
  1035. {
  1036. int retval;
  1037. unsigned long flags;
  1038. spin_lock_irqsave(&pdc_lock, flags);
  1039. retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_RESET);
  1040. spin_unlock_irqrestore(&pdc_lock, flags);
  1041. return retval;
  1042. }
  1043. /*
  1044. * pdc_soft_power_info - Enable soft power switch.
  1045. * @power_reg: address of soft power register
  1046. *
  1047. * Return the absolute address of the soft power switch register
  1048. */
  1049. int __init pdc_soft_power_info(unsigned long *power_reg)
  1050. {
  1051. int retval;
  1052. unsigned long flags;
  1053. *power_reg = (unsigned long) (-1);
  1054. spin_lock_irqsave(&pdc_lock, flags);
  1055. retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_INFO, __pa(pdc_result), 0);
  1056. if (retval == PDC_OK) {
  1057. convert_to_wide(pdc_result);
  1058. *power_reg = f_extend(pdc_result[0]);
  1059. }
  1060. spin_unlock_irqrestore(&pdc_lock, flags);
  1061. return retval;
  1062. }
  1063. /*
  1064. * pdc_soft_power_button{_panic} - Control the soft power button behaviour
  1065. * @sw_control: 0 for hardware control, 1 for software control
  1066. *
  1067. *
  1068. * This PDC function places the soft power button under software or
  1069. * hardware control.
  1070. * Under software control the OS may control to when to allow to shut
  1071. * down the system. Under hardware control pressing the power button
  1072. * powers off the system immediately.
  1073. *
  1074. * The _panic version relies on spin_trylock to prevent deadlock
  1075. * on panic path.
  1076. */
  1077. int pdc_soft_power_button(int sw_control)
  1078. {
  1079. int retval;
  1080. unsigned long flags;
  1081. spin_lock_irqsave(&pdc_lock, flags);
  1082. retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
  1083. spin_unlock_irqrestore(&pdc_lock, flags);
  1084. return retval;
  1085. }
  1086. int pdc_soft_power_button_panic(int sw_control)
  1087. {
  1088. int retval;
  1089. unsigned long flags;
  1090. if (!spin_trylock_irqsave(&pdc_lock, flags)) {
  1091. pr_emerg("Couldn't enable soft power button\n");
  1092. return -EBUSY; /* ignored by the panic notifier */
  1093. }
  1094. retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
  1095. spin_unlock_irqrestore(&pdc_lock, flags);
  1096. return retval;
  1097. }
  1098. /*
  1099. * pdc_io_reset - Hack to avoid overlapping range registers of Bridges devices.
  1100. * Primarily a problem on T600 (which parisc-linux doesn't support) but
  1101. * who knows what other platform firmware might do with this OS "hook".
  1102. */
  1103. void pdc_io_reset(void)
  1104. {
  1105. unsigned long flags;
  1106. spin_lock_irqsave(&pdc_lock, flags);
  1107. mem_pdc_call(PDC_IO, PDC_IO_RESET, 0);
  1108. spin_unlock_irqrestore(&pdc_lock, flags);
  1109. }
  1110. /*
  1111. * pdc_io_reset_devices - Hack to Stop USB controller
  1112. *
  1113. * If PDC used the usb controller, the usb controller
  1114. * is still running and will crash the machines during iommu
  1115. * setup, because of still running DMA. This PDC call
  1116. * stops the USB controller.
  1117. * Normally called after calling pdc_io_reset().
  1118. */
  1119. void pdc_io_reset_devices(void)
  1120. {
  1121. unsigned long flags;
  1122. spin_lock_irqsave(&pdc_lock, flags);
  1123. mem_pdc_call(PDC_IO, PDC_IO_RESET_DEVICES, 0);
  1124. spin_unlock_irqrestore(&pdc_lock, flags);
  1125. }
  1126. #endif /* defined(BOOTLOADER) */
  1127. /* locked by pdc_lock */
  1128. static char iodc_dbuf[4096] __page_aligned_bss;
  1129. /**
  1130. * pdc_iodc_print - Console print using IODC.
  1131. * @str: the string to output.
  1132. * @count: length of str
  1133. *
  1134. * Note that only these special chars are architected for console IODC io:
  1135. * BEL, BS, CR, and LF. Others are passed through.
  1136. * Since the HP console requires CR+LF to perform a 'newline', we translate
  1137. * "\n" to "\r\n".
  1138. */
  1139. int pdc_iodc_print(const unsigned char *str, unsigned count)
  1140. {
  1141. unsigned int i, found = 0;
  1142. unsigned long flags;
  1143. count = min_t(unsigned int, count, sizeof(iodc_dbuf));
  1144. spin_lock_irqsave(&pdc_lock, flags);
  1145. for (i = 0; i < count;) {
  1146. switch(str[i]) {
  1147. case '\n':
  1148. iodc_dbuf[i+0] = '\r';
  1149. iodc_dbuf[i+1] = '\n';
  1150. i += 2;
  1151. found = 1;
  1152. goto print;
  1153. default:
  1154. iodc_dbuf[i] = str[i];
  1155. i++;
  1156. break;
  1157. }
  1158. }
  1159. print:
  1160. real32_call(PAGE0->mem_cons.iodc_io,
  1161. (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
  1162. PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
  1163. __pa(pdc_result), 0, __pa(iodc_dbuf), i, 0);
  1164. spin_unlock_irqrestore(&pdc_lock, flags);
  1165. return i - found;
  1166. }
  1167. #if !defined(BOOTLOADER)
  1168. /**
  1169. * pdc_iodc_getc - Read a character (non-blocking) from the PDC console.
  1170. *
  1171. * Read a character (non-blocking) from the PDC console, returns -1 if
  1172. * key is not present.
  1173. */
  1174. int pdc_iodc_getc(void)
  1175. {
  1176. int ch;
  1177. int status;
  1178. unsigned long flags;
  1179. /* Bail if no console input device. */
  1180. if (!PAGE0->mem_kbd.iodc_io)
  1181. return 0;
  1182. /* wait for a keyboard (rs232)-input */
  1183. spin_lock_irqsave(&pdc_lock, flags);
  1184. real32_call(PAGE0->mem_kbd.iodc_io,
  1185. (unsigned long)PAGE0->mem_kbd.hpa, ENTRY_IO_CIN,
  1186. PAGE0->mem_kbd.spa, __pa(PAGE0->mem_kbd.dp.layers),
  1187. __pa(pdc_result), 0, __pa(iodc_dbuf), 1, 0);
  1188. ch = *iodc_dbuf;
  1189. /* like convert_to_wide() but for first return value only: */
  1190. status = *(int *)&pdc_result;
  1191. spin_unlock_irqrestore(&pdc_lock, flags);
  1192. if (status == 0)
  1193. return -1;
  1194. return ch;
  1195. }
  1196. int pdc_sti_call(unsigned long func, unsigned long flags,
  1197. unsigned long inptr, unsigned long outputr,
  1198. unsigned long glob_cfg)
  1199. {
  1200. int retval;
  1201. unsigned long irqflags;
  1202. spin_lock_irqsave(&pdc_lock, irqflags);
  1203. retval = real32_call(func, flags, inptr, outputr, glob_cfg);
  1204. spin_unlock_irqrestore(&pdc_lock, irqflags);
  1205. return retval;
  1206. }
  1207. EXPORT_SYMBOL(pdc_sti_call);
  1208. #ifdef CONFIG_64BIT
  1209. /**
  1210. * pdc_pat_cell_get_number - Returns the cell number.
  1211. * @cell_info: The return buffer.
  1212. *
  1213. * This PDC call returns the cell number of the cell from which the call
  1214. * is made.
  1215. */
  1216. int pdc_pat_cell_get_number(struct pdc_pat_cell_num *cell_info)
  1217. {
  1218. int retval;
  1219. unsigned long flags;
  1220. spin_lock_irqsave(&pdc_lock, flags);
  1221. retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_GET_NUMBER, __pa(pdc_result));
  1222. memcpy(cell_info, pdc_result, sizeof(*cell_info));
  1223. spin_unlock_irqrestore(&pdc_lock, flags);
  1224. return retval;
  1225. }
  1226. /**
  1227. * pdc_pat_cell_module - Retrieve the cell's module information.
  1228. * @actcnt: The number of bytes written to mem_addr.
  1229. * @ploc: The physical location.
  1230. * @mod: The module index.
  1231. * @view_type: The view of the address type.
  1232. * @mem_addr: The return buffer.
  1233. *
  1234. * This PDC call returns information about each module attached to the cell
  1235. * at the specified location.
  1236. */
  1237. int pdc_pat_cell_module(unsigned long *actcnt, unsigned long ploc, unsigned long mod,
  1238. unsigned long view_type, void *mem_addr)
  1239. {
  1240. int retval;
  1241. unsigned long flags;
  1242. static struct pdc_pat_cell_mod_maddr_block result __attribute__ ((aligned (8)));
  1243. spin_lock_irqsave(&pdc_lock, flags);
  1244. retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_MODULE, __pa(pdc_result),
  1245. ploc, mod, view_type, __pa(&result));
  1246. if(!retval) {
  1247. *actcnt = pdc_result[0];
  1248. memcpy(mem_addr, &result, *actcnt);
  1249. }
  1250. spin_unlock_irqrestore(&pdc_lock, flags);
  1251. return retval;
  1252. }
  1253. /**
  1254. * pdc_pat_cell_info - Retrieve the cell's information.
  1255. * @info: The pointer to a struct pdc_pat_cell_info_rtn_block.
  1256. * @actcnt: The number of bytes which should be written to info.
  1257. * @offset: offset of the structure.
  1258. * @cell_number: The cell number which should be asked, or -1 for current cell.
  1259. *
  1260. * This PDC call returns information about the given cell (or all cells).
  1261. */
  1262. int pdc_pat_cell_info(struct pdc_pat_cell_info_rtn_block *info,
  1263. unsigned long *actcnt, unsigned long offset,
  1264. unsigned long cell_number)
  1265. {
  1266. int retval;
  1267. unsigned long flags;
  1268. struct pdc_pat_cell_info_rtn_block result;
  1269. spin_lock_irqsave(&pdc_lock, flags);
  1270. retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_GET_INFO,
  1271. __pa(pdc_result), __pa(&result), *actcnt,
  1272. offset, cell_number);
  1273. if (!retval) {
  1274. *actcnt = pdc_result[0];
  1275. memcpy(info, &result, *actcnt);
  1276. }
  1277. spin_unlock_irqrestore(&pdc_lock, flags);
  1278. return retval;
  1279. }
  1280. /**
  1281. * pdc_pat_cpu_get_number - Retrieve the cpu number.
  1282. * @cpu_info: The return buffer.
  1283. * @hpa: The Hard Physical Address of the CPU.
  1284. *
  1285. * Retrieve the cpu number for the cpu at the specified HPA.
  1286. */
  1287. int pdc_pat_cpu_get_number(struct pdc_pat_cpu_num *cpu_info, unsigned long hpa)
  1288. {
  1289. int retval;
  1290. unsigned long flags;
  1291. spin_lock_irqsave(&pdc_lock, flags);
  1292. retval = mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_GET_NUMBER,
  1293. __pa(&pdc_result), hpa);
  1294. memcpy(cpu_info, pdc_result, sizeof(*cpu_info));
  1295. spin_unlock_irqrestore(&pdc_lock, flags);
  1296. return retval;
  1297. }
  1298. /**
  1299. * pdc_pat_get_irt_size - Retrieve the number of entries in the cell's interrupt table.
  1300. * @num_entries: The return value.
  1301. * @cell_num: The target cell.
  1302. *
  1303. * This PDC function returns the number of entries in the specified cell's
  1304. * interrupt table.
  1305. */
  1306. int pdc_pat_get_irt_size(unsigned long *num_entries, unsigned long cell_num)
  1307. {
  1308. int retval;
  1309. unsigned long flags;
  1310. spin_lock_irqsave(&pdc_lock, flags);
  1311. retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE_SIZE,
  1312. __pa(pdc_result), cell_num);
  1313. *num_entries = pdc_result[0];
  1314. spin_unlock_irqrestore(&pdc_lock, flags);
  1315. return retval;
  1316. }
  1317. /**
  1318. * pdc_pat_get_irt - Retrieve the cell's interrupt table.
  1319. * @r_addr: The return buffer.
  1320. * @cell_num: The target cell.
  1321. *
  1322. * This PDC function returns the actual interrupt table for the specified cell.
  1323. */
  1324. int pdc_pat_get_irt(void *r_addr, unsigned long cell_num)
  1325. {
  1326. int retval;
  1327. unsigned long flags;
  1328. spin_lock_irqsave(&pdc_lock, flags);
  1329. retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE,
  1330. __pa(r_addr), cell_num);
  1331. spin_unlock_irqrestore(&pdc_lock, flags);
  1332. return retval;
  1333. }
  1334. /**
  1335. * pdc_pat_pd_get_addr_map - Retrieve information about memory address ranges.
  1336. * @actlen: The return buffer.
  1337. * @mem_addr: Pointer to the memory buffer.
  1338. * @count: The number of bytes to read from the buffer.
  1339. * @offset: The offset with respect to the beginning of the buffer.
  1340. *
  1341. */
  1342. int pdc_pat_pd_get_addr_map(unsigned long *actual_len, void *mem_addr,
  1343. unsigned long count, unsigned long offset)
  1344. {
  1345. int retval;
  1346. unsigned long flags;
  1347. spin_lock_irqsave(&pdc_lock, flags);
  1348. retval = mem_pdc_call(PDC_PAT_PD, PDC_PAT_PD_GET_ADDR_MAP, __pa(pdc_result),
  1349. __pa(pdc_result2), count, offset);
  1350. *actual_len = pdc_result[0];
  1351. memcpy(mem_addr, pdc_result2, *actual_len);
  1352. spin_unlock_irqrestore(&pdc_lock, flags);
  1353. return retval;
  1354. }
  1355. /**
  1356. * pdc_pat_pd_get_PDC_interface_revisions - Retrieve PDC interface revisions.
  1357. * @legacy_rev: The legacy revision.
  1358. * @pat_rev: The PAT revision.
  1359. * @pdc_cap: The PDC capabilities.
  1360. *
  1361. */
  1362. int pdc_pat_pd_get_pdc_revisions(unsigned long *legacy_rev,
  1363. unsigned long *pat_rev, unsigned long *pdc_cap)
  1364. {
  1365. int retval;
  1366. unsigned long flags;
  1367. spin_lock_irqsave(&pdc_lock, flags);
  1368. retval = mem_pdc_call(PDC_PAT_PD, PDC_PAT_PD_GET_PDC_INTERF_REV,
  1369. __pa(pdc_result));
  1370. if (retval == PDC_OK) {
  1371. *legacy_rev = pdc_result[0];
  1372. *pat_rev = pdc_result[1];
  1373. *pdc_cap = pdc_result[2];
  1374. }
  1375. spin_unlock_irqrestore(&pdc_lock, flags);
  1376. return retval;
  1377. }
  1378. /**
  1379. * pdc_pat_io_pci_cfg_read - Read PCI configuration space.
  1380. * @pci_addr: PCI configuration space address for which the read request is being made.
  1381. * @pci_size: Size of read in bytes. Valid values are 1, 2, and 4.
  1382. * @mem_addr: Pointer to return memory buffer.
  1383. *
  1384. */
  1385. int pdc_pat_io_pci_cfg_read(unsigned long pci_addr, int pci_size, u32 *mem_addr)
  1386. {
  1387. int retval;
  1388. unsigned long flags;
  1389. spin_lock_irqsave(&pdc_lock, flags);
  1390. retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_READ,
  1391. __pa(pdc_result), pci_addr, pci_size);
  1392. switch(pci_size) {
  1393. case 1: *(u8 *) mem_addr = (u8) pdc_result[0]; break;
  1394. case 2: *(u16 *)mem_addr = (u16) pdc_result[0]; break;
  1395. case 4: *(u32 *)mem_addr = (u32) pdc_result[0]; break;
  1396. }
  1397. spin_unlock_irqrestore(&pdc_lock, flags);
  1398. return retval;
  1399. }
  1400. /**
  1401. * pdc_pat_io_pci_cfg_write - Retrieve information about memory address ranges.
  1402. * @pci_addr: PCI configuration space address for which the write request is being made.
  1403. * @pci_size: Size of write in bytes. Valid values are 1, 2, and 4.
  1404. * @value: Pointer to 1, 2, or 4 byte value in low order end of argument to be
  1405. * written to PCI Config space.
  1406. *
  1407. */
  1408. int pdc_pat_io_pci_cfg_write(unsigned long pci_addr, int pci_size, u32 val)
  1409. {
  1410. int retval;
  1411. unsigned long flags;
  1412. spin_lock_irqsave(&pdc_lock, flags);
  1413. retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_WRITE,
  1414. pci_addr, pci_size, val);
  1415. spin_unlock_irqrestore(&pdc_lock, flags);
  1416. return retval;
  1417. }
  1418. /**
  1419. * pdc_pat_mem_pdc_info - Retrieve information about page deallocation table
  1420. * @rinfo: memory pdt information
  1421. *
  1422. */
  1423. int pdc_pat_mem_pdt_info(struct pdc_pat_mem_retinfo *rinfo)
  1424. {
  1425. int retval;
  1426. unsigned long flags;
  1427. spin_lock_irqsave(&pdc_lock, flags);
  1428. retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_PD_INFO,
  1429. __pa(&pdc_result));
  1430. if (retval == PDC_OK)
  1431. memcpy(rinfo, &pdc_result, sizeof(*rinfo));
  1432. spin_unlock_irqrestore(&pdc_lock, flags);
  1433. return retval;
  1434. }
  1435. /**
  1436. * pdc_pat_mem_pdt_cell_info - Retrieve information about page deallocation
  1437. * table of a cell
  1438. * @rinfo: memory pdt information
  1439. * @cell: cell number
  1440. *
  1441. */
  1442. int pdc_pat_mem_pdt_cell_info(struct pdc_pat_mem_cell_pdt_retinfo *rinfo,
  1443. unsigned long cell)
  1444. {
  1445. int retval;
  1446. unsigned long flags;
  1447. spin_lock_irqsave(&pdc_lock, flags);
  1448. retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_CELL_INFO,
  1449. __pa(&pdc_result), cell);
  1450. if (retval == PDC_OK)
  1451. memcpy(rinfo, &pdc_result, sizeof(*rinfo));
  1452. spin_unlock_irqrestore(&pdc_lock, flags);
  1453. return retval;
  1454. }
  1455. /**
  1456. * pdc_pat_mem_read_cell_pdt - Read PDT entries from (old) PAT firmware
  1457. * @pret: array of PDT entries
  1458. * @pdt_entries_ptr: ptr to hold number of PDT entries
  1459. * @max_entries: maximum number of entries to be read
  1460. *
  1461. */
  1462. int pdc_pat_mem_read_cell_pdt(struct pdc_pat_mem_read_pd_retinfo *pret,
  1463. unsigned long *pdt_entries_ptr, unsigned long max_entries)
  1464. {
  1465. int retval;
  1466. unsigned long flags, entries;
  1467. spin_lock_irqsave(&pdc_lock, flags);
  1468. /* PDC_PAT_MEM_CELL_READ is available on early PAT machines only */
  1469. retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_CELL_READ,
  1470. __pa(&pdc_result), parisc_cell_num,
  1471. __pa(pdt_entries_ptr));
  1472. if (retval == PDC_OK) {
  1473. /* build up return value as for PDC_PAT_MEM_PD_READ */
  1474. entries = min(pdc_result[0], max_entries);
  1475. pret->pdt_entries = entries;
  1476. pret->actual_count_bytes = entries * sizeof(unsigned long);
  1477. }
  1478. spin_unlock_irqrestore(&pdc_lock, flags);
  1479. WARN_ON(retval == PDC_OK && pdc_result[0] > max_entries);
  1480. return retval;
  1481. }
  1482. /**
  1483. * pdc_pat_mem_read_pd_pdt - Read PDT entries from (newer) PAT firmware
  1484. * @pret: array of PDT entries
  1485. * @pdt_entries_ptr: ptr to hold number of PDT entries
  1486. * @count: number of bytes to read
  1487. * @offset: offset to start (in bytes)
  1488. *
  1489. */
  1490. int pdc_pat_mem_read_pd_pdt(struct pdc_pat_mem_read_pd_retinfo *pret,
  1491. unsigned long *pdt_entries_ptr, unsigned long count,
  1492. unsigned long offset)
  1493. {
  1494. int retval;
  1495. unsigned long flags, entries;
  1496. spin_lock_irqsave(&pdc_lock, flags);
  1497. retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_PD_READ,
  1498. __pa(&pdc_result), __pa(pdt_entries_ptr),
  1499. count, offset);
  1500. if (retval == PDC_OK) {
  1501. entries = min(pdc_result[0], count);
  1502. pret->actual_count_bytes = entries;
  1503. pret->pdt_entries = entries / sizeof(unsigned long);
  1504. }
  1505. spin_unlock_irqrestore(&pdc_lock, flags);
  1506. return retval;
  1507. }
  1508. /**
  1509. * pdc_pat_mem_get_dimm_phys_location - Get physical DIMM slot via PAT firmware
  1510. * @pret: ptr to hold returned information
  1511. * @phys_addr: physical address to examine
  1512. *
  1513. */
  1514. int pdc_pat_mem_get_dimm_phys_location(
  1515. struct pdc_pat_mem_phys_mem_location *pret,
  1516. unsigned long phys_addr)
  1517. {
  1518. int retval;
  1519. unsigned long flags;
  1520. spin_lock_irqsave(&pdc_lock, flags);
  1521. retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_ADDRESS,
  1522. __pa(&pdc_result), phys_addr);
  1523. if (retval == PDC_OK)
  1524. memcpy(pret, &pdc_result, sizeof(*pret));
  1525. spin_unlock_irqrestore(&pdc_lock, flags);
  1526. return retval;
  1527. }
  1528. #endif /* CONFIG_64BIT */
  1529. #endif /* defined(BOOTLOADER) */
  1530. /***************** 32-bit real-mode calls ***********/
  1531. /* The struct below is used
  1532. * to overlay real_stack (real2.S), preparing a 32-bit call frame.
  1533. * real32_call_asm() then uses this stack in narrow real mode
  1534. */
  1535. struct narrow_stack {
  1536. /* use int, not long which is 64 bits */
  1537. unsigned int arg13;
  1538. unsigned int arg12;
  1539. unsigned int arg11;
  1540. unsigned int arg10;
  1541. unsigned int arg9;
  1542. unsigned int arg8;
  1543. unsigned int arg7;
  1544. unsigned int arg6;
  1545. unsigned int arg5;
  1546. unsigned int arg4;
  1547. unsigned int arg3;
  1548. unsigned int arg2;
  1549. unsigned int arg1;
  1550. unsigned int arg0;
  1551. unsigned int frame_marker[8];
  1552. unsigned int sp;
  1553. /* in reality, there's nearly 8k of stack after this */
  1554. };
  1555. long real32_call(unsigned long fn, ...)
  1556. {
  1557. va_list args;
  1558. extern struct narrow_stack real_stack;
  1559. extern unsigned long real32_call_asm(unsigned int *,
  1560. unsigned int *,
  1561. unsigned int);
  1562. va_start(args, fn);
  1563. real_stack.arg0 = va_arg(args, unsigned int);
  1564. real_stack.arg1 = va_arg(args, unsigned int);
  1565. real_stack.arg2 = va_arg(args, unsigned int);
  1566. real_stack.arg3 = va_arg(args, unsigned int);
  1567. real_stack.arg4 = va_arg(args, unsigned int);
  1568. real_stack.arg5 = va_arg(args, unsigned int);
  1569. real_stack.arg6 = va_arg(args, unsigned int);
  1570. real_stack.arg7 = va_arg(args, unsigned int);
  1571. real_stack.arg8 = va_arg(args, unsigned int);
  1572. real_stack.arg9 = va_arg(args, unsigned int);
  1573. real_stack.arg10 = va_arg(args, unsigned int);
  1574. real_stack.arg11 = va_arg(args, unsigned int);
  1575. real_stack.arg12 = va_arg(args, unsigned int);
  1576. real_stack.arg13 = va_arg(args, unsigned int);
  1577. va_end(args);
  1578. return real32_call_asm(&real_stack.sp, &real_stack.arg0, fn);
  1579. }
  1580. #ifdef CONFIG_64BIT
  1581. /***************** 64-bit real-mode calls ***********/
  1582. struct wide_stack {
  1583. unsigned long arg0;
  1584. unsigned long arg1;
  1585. unsigned long arg2;
  1586. unsigned long arg3;
  1587. unsigned long arg4;
  1588. unsigned long arg5;
  1589. unsigned long arg6;
  1590. unsigned long arg7;
  1591. unsigned long arg8;
  1592. unsigned long arg9;
  1593. unsigned long arg10;
  1594. unsigned long arg11;
  1595. unsigned long arg12;
  1596. unsigned long arg13;
  1597. unsigned long frame_marker[2]; /* rp, previous sp */
  1598. unsigned long sp;
  1599. /* in reality, there's nearly 8k of stack after this */
  1600. };
  1601. long real64_call(unsigned long fn, ...)
  1602. {
  1603. va_list args;
  1604. extern struct wide_stack real64_stack;
  1605. extern unsigned long real64_call_asm(unsigned long *,
  1606. unsigned long *,
  1607. unsigned long);
  1608. va_start(args, fn);
  1609. real64_stack.arg0 = va_arg(args, unsigned long);
  1610. real64_stack.arg1 = va_arg(args, unsigned long);
  1611. real64_stack.arg2 = va_arg(args, unsigned long);
  1612. real64_stack.arg3 = va_arg(args, unsigned long);
  1613. real64_stack.arg4 = va_arg(args, unsigned long);
  1614. real64_stack.arg5 = va_arg(args, unsigned long);
  1615. real64_stack.arg6 = va_arg(args, unsigned long);
  1616. real64_stack.arg7 = va_arg(args, unsigned long);
  1617. real64_stack.arg8 = va_arg(args, unsigned long);
  1618. real64_stack.arg9 = va_arg(args, unsigned long);
  1619. real64_stack.arg10 = va_arg(args, unsigned long);
  1620. real64_stack.arg11 = va_arg(args, unsigned long);
  1621. real64_stack.arg12 = va_arg(args, unsigned long);
  1622. real64_stack.arg13 = va_arg(args, unsigned long);
  1623. va_end(args);
  1624. return real64_call_asm(&real64_stack.sp, &real64_stack.arg0, fn);
  1625. }
  1626. #endif /* CONFIG_64BIT */