firmware.c 42 KB

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