firmware.c 42 KB

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