firmware.c 40 KB

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