firmware.c 53 KB

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