firmware.c 42 KB

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