firmware.c 41 KB

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