firmware.c 42 KB

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