firmware.c 47 KB

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