firmware.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  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 __cpuinit 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 __cpuinit 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 __cpuinit set_firmware_width_unlocked(void) {
  162. return;
  163. }
  164. void __cpuinit 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 __cpuinit 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 __cpuinit 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. if (retval == PDC_OK) {
  464. *capabilities = pdc_result[0];
  465. } else {
  466. *capabilities = PDC_MODEL_OS32;
  467. }
  468. spin_unlock_irqrestore(&pdc_lock, flags);
  469. return retval;
  470. }
  471. /**
  472. * pdc_cache_info - Return cache and TLB information.
  473. * @cache_info: The return buffer.
  474. *
  475. * Returns information about the processor's cache and TLB.
  476. */
  477. int pdc_cache_info(struct pdc_cache_info *cache_info)
  478. {
  479. int retval;
  480. unsigned long flags;
  481. spin_lock_irqsave(&pdc_lock, flags);
  482. retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_INFO, __pa(pdc_result), 0);
  483. convert_to_wide(pdc_result);
  484. memcpy(cache_info, pdc_result, sizeof(*cache_info));
  485. spin_unlock_irqrestore(&pdc_lock, flags);
  486. return retval;
  487. }
  488. /**
  489. * pdc_spaceid_bits - Return whether Space ID hashing is turned on.
  490. * @space_bits: Should be 0, if not, bad mojo!
  491. *
  492. * Returns information about Space ID hashing.
  493. */
  494. int pdc_spaceid_bits(unsigned long *space_bits)
  495. {
  496. int retval;
  497. unsigned long flags;
  498. spin_lock_irqsave(&pdc_lock, flags);
  499. pdc_result[0] = 0;
  500. retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_RET_SPID, __pa(pdc_result), 0);
  501. convert_to_wide(pdc_result);
  502. *space_bits = pdc_result[0];
  503. spin_unlock_irqrestore(&pdc_lock, flags);
  504. return retval;
  505. }
  506. #ifndef CONFIG_PA20
  507. /**
  508. * pdc_btlb_info - Return block TLB information.
  509. * @btlb: The return buffer.
  510. *
  511. * Returns information about the hardware Block TLB.
  512. */
  513. int pdc_btlb_info(struct pdc_btlb_info *btlb)
  514. {
  515. int retval;
  516. unsigned long flags;
  517. spin_lock_irqsave(&pdc_lock, flags);
  518. retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_INFO, __pa(pdc_result), 0);
  519. memcpy(btlb, pdc_result, sizeof(*btlb));
  520. spin_unlock_irqrestore(&pdc_lock, flags);
  521. if(retval < 0) {
  522. btlb->max_size = 0;
  523. }
  524. return retval;
  525. }
  526. /**
  527. * pdc_mem_map_hpa - Find fixed module information.
  528. * @address: The return buffer
  529. * @mod_path: pointer to dev path structure.
  530. *
  531. * This call was developed for S700 workstations to allow the kernel to find
  532. * the I/O devices (Core I/O). In the future (Kittyhawk and beyond) this
  533. * call will be replaced (on workstations) by the architected PDC_SYSTEM_MAP
  534. * call.
  535. *
  536. * This call is supported by all existing S700 workstations (up to Gecko).
  537. */
  538. int pdc_mem_map_hpa(struct pdc_memory_map *address,
  539. struct pdc_module_path *mod_path)
  540. {
  541. int retval;
  542. unsigned long flags;
  543. spin_lock_irqsave(&pdc_lock, flags);
  544. memcpy(pdc_result2, mod_path, sizeof(*mod_path));
  545. retval = mem_pdc_call(PDC_MEM_MAP, PDC_MEM_MAP_HPA, __pa(pdc_result),
  546. __pa(pdc_result2));
  547. memcpy(address, pdc_result, sizeof(*address));
  548. spin_unlock_irqrestore(&pdc_lock, flags);
  549. return retval;
  550. }
  551. #endif /* !CONFIG_PA20 */
  552. /**
  553. * pdc_lan_station_id - Get the LAN address.
  554. * @lan_addr: The return buffer.
  555. * @hpa: The network device HPA.
  556. *
  557. * Get the LAN station address when it is not directly available from the LAN hardware.
  558. */
  559. int pdc_lan_station_id(char *lan_addr, unsigned long hpa)
  560. {
  561. int retval;
  562. unsigned long flags;
  563. spin_lock_irqsave(&pdc_lock, flags);
  564. retval = mem_pdc_call(PDC_LAN_STATION_ID, PDC_LAN_STATION_ID_READ,
  565. __pa(pdc_result), hpa);
  566. if (retval < 0) {
  567. /* FIXME: else read MAC from NVRAM */
  568. memset(lan_addr, 0, PDC_LAN_STATION_ID_SIZE);
  569. } else {
  570. memcpy(lan_addr, pdc_result, PDC_LAN_STATION_ID_SIZE);
  571. }
  572. spin_unlock_irqrestore(&pdc_lock, flags);
  573. return retval;
  574. }
  575. EXPORT_SYMBOL(pdc_lan_station_id);
  576. /**
  577. * pdc_stable_read - Read data from Stable Storage.
  578. * @staddr: Stable Storage address to access.
  579. * @memaddr: The memory address where Stable Storage data shall be copied.
  580. * @count: number of bytes to transfer. count is multiple of 4.
  581. *
  582. * This PDC call reads from the Stable Storage address supplied in staddr
  583. * and copies count bytes to the memory address memaddr.
  584. * The call will fail if staddr+count > PDC_STABLE size.
  585. */
  586. int pdc_stable_read(unsigned long staddr, void *memaddr, unsigned long count)
  587. {
  588. int retval;
  589. unsigned long flags;
  590. spin_lock_irqsave(&pdc_lock, flags);
  591. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_READ, staddr,
  592. __pa(pdc_result), count);
  593. convert_to_wide(pdc_result);
  594. memcpy(memaddr, pdc_result, count);
  595. spin_unlock_irqrestore(&pdc_lock, flags);
  596. return retval;
  597. }
  598. EXPORT_SYMBOL(pdc_stable_read);
  599. /**
  600. * pdc_stable_write - Write data to Stable Storage.
  601. * @staddr: Stable Storage address to access.
  602. * @memaddr: The memory address where Stable Storage data shall be read from.
  603. * @count: number of bytes to transfer. count is multiple of 4.
  604. *
  605. * This PDC call reads count bytes from the supplied memaddr address,
  606. * and copies count bytes to the Stable Storage address staddr.
  607. * The call will fail if staddr+count > PDC_STABLE size.
  608. */
  609. int pdc_stable_write(unsigned long staddr, void *memaddr, unsigned long count)
  610. {
  611. int retval;
  612. unsigned long flags;
  613. spin_lock_irqsave(&pdc_lock, flags);
  614. memcpy(pdc_result, memaddr, count);
  615. convert_to_wide(pdc_result);
  616. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_WRITE, staddr,
  617. __pa(pdc_result), count);
  618. spin_unlock_irqrestore(&pdc_lock, flags);
  619. return retval;
  620. }
  621. EXPORT_SYMBOL(pdc_stable_write);
  622. /**
  623. * pdc_stable_get_size - Get Stable Storage size in bytes.
  624. * @size: pointer where the size will be stored.
  625. *
  626. * This PDC call returns the number of bytes in the processor's Stable
  627. * Storage, which is the number of contiguous bytes implemented in Stable
  628. * Storage starting from staddr=0. size in an unsigned 64-bit integer
  629. * which is a multiple of four.
  630. */
  631. int pdc_stable_get_size(unsigned long *size)
  632. {
  633. int retval;
  634. unsigned long flags;
  635. spin_lock_irqsave(&pdc_lock, flags);
  636. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_RETURN_SIZE, __pa(pdc_result));
  637. *size = pdc_result[0];
  638. spin_unlock_irqrestore(&pdc_lock, flags);
  639. return retval;
  640. }
  641. EXPORT_SYMBOL(pdc_stable_get_size);
  642. /**
  643. * pdc_stable_verify_contents - Checks that Stable Storage contents are valid.
  644. *
  645. * This PDC call is meant to be used to check the integrity of the current
  646. * contents of Stable Storage.
  647. */
  648. int pdc_stable_verify_contents(void)
  649. {
  650. int retval;
  651. unsigned long flags;
  652. spin_lock_irqsave(&pdc_lock, flags);
  653. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_VERIFY_CONTENTS);
  654. spin_unlock_irqrestore(&pdc_lock, flags);
  655. return retval;
  656. }
  657. EXPORT_SYMBOL(pdc_stable_verify_contents);
  658. /**
  659. * pdc_stable_initialize - Sets Stable Storage contents to zero and initialize
  660. * the validity indicator.
  661. *
  662. * This PDC call will erase all contents of Stable Storage. Use with care!
  663. */
  664. int pdc_stable_initialize(void)
  665. {
  666. int retval;
  667. unsigned long flags;
  668. spin_lock_irqsave(&pdc_lock, flags);
  669. retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_INITIALIZE);
  670. spin_unlock_irqrestore(&pdc_lock, flags);
  671. return retval;
  672. }
  673. EXPORT_SYMBOL(pdc_stable_initialize);
  674. /**
  675. * pdc_get_initiator - Get the SCSI Interface Card params (SCSI ID, SDTR, SE or LVD)
  676. * @hwpath: fully bc.mod style path to the device.
  677. * @initiator: the array to return the result into
  678. *
  679. * Get the SCSI operational parameters from PDC.
  680. * Needed since HPUX never used BIOS or symbios card NVRAM.
  681. * Most ncr/sym cards won't have an entry and just use whatever
  682. * capabilities of the card are (eg Ultra, LVD). But there are
  683. * several cases where it's useful:
  684. * o set SCSI id for Multi-initiator clusters,
  685. * o cable too long (ie SE scsi 10Mhz won't support 6m length),
  686. * o bus width exported is less than what the interface chip supports.
  687. */
  688. int pdc_get_initiator(struct hardware_path *hwpath, struct pdc_initiator *initiator)
  689. {
  690. int retval;
  691. unsigned long flags;
  692. spin_lock_irqsave(&pdc_lock, flags);
  693. /* BCJ-XXXX series boxes. E.G. "9000/785/C3000" */
  694. #define IS_SPROCKETS() (strlen(boot_cpu_data.pdc.sys_model_name) == 14 && \
  695. strncmp(boot_cpu_data.pdc.sys_model_name, "9000/785", 8) == 0)
  696. retval = mem_pdc_call(PDC_INITIATOR, PDC_GET_INITIATOR,
  697. __pa(pdc_result), __pa(hwpath));
  698. if (retval < PDC_OK)
  699. goto out;
  700. if (pdc_result[0] < 16) {
  701. initiator->host_id = pdc_result[0];
  702. } else {
  703. initiator->host_id = -1;
  704. }
  705. /*
  706. * Sprockets and Piranha return 20 or 40 (MT/s). Prelude returns
  707. * 1, 2, 5 or 10 for 5, 10, 20 or 40 MT/s, respectively
  708. */
  709. switch (pdc_result[1]) {
  710. case 1: initiator->factor = 50; break;
  711. case 2: initiator->factor = 25; break;
  712. case 5: initiator->factor = 12; break;
  713. case 25: initiator->factor = 10; break;
  714. case 20: initiator->factor = 12; break;
  715. case 40: initiator->factor = 10; break;
  716. default: initiator->factor = -1; break;
  717. }
  718. if (IS_SPROCKETS()) {
  719. initiator->width = pdc_result[4];
  720. initiator->mode = pdc_result[5];
  721. } else {
  722. initiator->width = -1;
  723. initiator->mode = -1;
  724. }
  725. out:
  726. spin_unlock_irqrestore(&pdc_lock, flags);
  727. return (retval >= PDC_OK);
  728. }
  729. EXPORT_SYMBOL(pdc_get_initiator);
  730. /**
  731. * pdc_pci_irt_size - Get the number of entries in the interrupt routing table.
  732. * @num_entries: The return value.
  733. * @hpa: The HPA for the device.
  734. *
  735. * This PDC function returns the number of entries in the specified cell's
  736. * interrupt table.
  737. * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
  738. */
  739. int pdc_pci_irt_size(unsigned long *num_entries, unsigned long hpa)
  740. {
  741. int retval;
  742. unsigned long flags;
  743. spin_lock_irqsave(&pdc_lock, flags);
  744. retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL_SIZE,
  745. __pa(pdc_result), hpa);
  746. convert_to_wide(pdc_result);
  747. *num_entries = pdc_result[0];
  748. spin_unlock_irqrestore(&pdc_lock, flags);
  749. return retval;
  750. }
  751. /**
  752. * pdc_pci_irt - Get the PCI interrupt routing table.
  753. * @num_entries: The number of entries in the table.
  754. * @hpa: The Hard Physical Address of the device.
  755. * @tbl:
  756. *
  757. * Get the PCI interrupt routing table for the device at the given HPA.
  758. * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
  759. */
  760. int pdc_pci_irt(unsigned long num_entries, unsigned long hpa, void *tbl)
  761. {
  762. int retval;
  763. unsigned long flags;
  764. BUG_ON((unsigned long)tbl & 0x7);
  765. spin_lock_irqsave(&pdc_lock, flags);
  766. pdc_result[0] = num_entries;
  767. retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL,
  768. __pa(pdc_result), hpa, __pa(tbl));
  769. spin_unlock_irqrestore(&pdc_lock, flags);
  770. return retval;
  771. }
  772. #if 0 /* UNTEST CODE - left here in case someone needs it */
  773. /**
  774. * pdc_pci_config_read - read PCI config space.
  775. * @hpa token from PDC to indicate which PCI device
  776. * @pci_addr configuration space address to read from
  777. *
  778. * Read PCI Configuration space *before* linux PCI subsystem is running.
  779. */
  780. unsigned int pdc_pci_config_read(void *hpa, unsigned long cfg_addr)
  781. {
  782. int retval;
  783. unsigned long flags;
  784. spin_lock_irqsave(&pdc_lock, flags);
  785. pdc_result[0] = 0;
  786. pdc_result[1] = 0;
  787. retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_READ_CONFIG,
  788. __pa(pdc_result), hpa, cfg_addr&~3UL, 4UL);
  789. spin_unlock_irqrestore(&pdc_lock, flags);
  790. return retval ? ~0 : (unsigned int) pdc_result[0];
  791. }
  792. /**
  793. * pdc_pci_config_write - read PCI config space.
  794. * @hpa token from PDC to indicate which PCI device
  795. * @pci_addr configuration space address to write
  796. * @val value we want in the 32-bit register
  797. *
  798. * Write PCI Configuration space *before* linux PCI subsystem is running.
  799. */
  800. void pdc_pci_config_write(void *hpa, unsigned long cfg_addr, unsigned int val)
  801. {
  802. int retval;
  803. unsigned long flags;
  804. spin_lock_irqsave(&pdc_lock, flags);
  805. pdc_result[0] = 0;
  806. retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_WRITE_CONFIG,
  807. __pa(pdc_result), hpa,
  808. cfg_addr&~3UL, 4UL, (unsigned long) val);
  809. spin_unlock_irqrestore(&pdc_lock, flags);
  810. return retval;
  811. }
  812. #endif /* UNTESTED CODE */
  813. /**
  814. * pdc_tod_read - Read the Time-Of-Day clock.
  815. * @tod: The return buffer:
  816. *
  817. * Read the Time-Of-Day clock
  818. */
  819. int pdc_tod_read(struct pdc_tod *tod)
  820. {
  821. int retval;
  822. unsigned long flags;
  823. spin_lock_irqsave(&pdc_lock, flags);
  824. retval = mem_pdc_call(PDC_TOD, PDC_TOD_READ, __pa(pdc_result), 0);
  825. convert_to_wide(pdc_result);
  826. memcpy(tod, pdc_result, sizeof(*tod));
  827. spin_unlock_irqrestore(&pdc_lock, flags);
  828. return retval;
  829. }
  830. EXPORT_SYMBOL(pdc_tod_read);
  831. /**
  832. * pdc_tod_set - Set the Time-Of-Day clock.
  833. * @sec: The number of seconds since epoch.
  834. * @usec: The number of micro seconds.
  835. *
  836. * Set the Time-Of-Day clock.
  837. */
  838. int pdc_tod_set(unsigned long sec, unsigned long usec)
  839. {
  840. int retval;
  841. unsigned long flags;
  842. spin_lock_irqsave(&pdc_lock, flags);
  843. retval = mem_pdc_call(PDC_TOD, PDC_TOD_WRITE, sec, usec);
  844. spin_unlock_irqrestore(&pdc_lock, flags);
  845. return retval;
  846. }
  847. EXPORT_SYMBOL(pdc_tod_set);
  848. #ifdef CONFIG_64BIT
  849. int pdc_mem_mem_table(struct pdc_memory_table_raddr *r_addr,
  850. struct pdc_memory_table *tbl, unsigned long entries)
  851. {
  852. int retval;
  853. unsigned long flags;
  854. spin_lock_irqsave(&pdc_lock, flags);
  855. retval = mem_pdc_call(PDC_MEM, PDC_MEM_TABLE, __pa(pdc_result), __pa(pdc_result2), entries);
  856. convert_to_wide(pdc_result);
  857. memcpy(r_addr, pdc_result, sizeof(*r_addr));
  858. memcpy(tbl, pdc_result2, entries * sizeof(*tbl));
  859. spin_unlock_irqrestore(&pdc_lock, flags);
  860. return retval;
  861. }
  862. #endif /* CONFIG_64BIT */
  863. /* FIXME: Is this pdc used? I could not find type reference to ftc_bitmap
  864. * so I guessed at unsigned long. Someone who knows what this does, can fix
  865. * it later. :)
  866. */
  867. int pdc_do_firm_test_reset(unsigned long ftc_bitmap)
  868. {
  869. int retval;
  870. unsigned long flags;
  871. spin_lock_irqsave(&pdc_lock, flags);
  872. retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_FIRM_TEST_RESET,
  873. PDC_FIRM_TEST_MAGIC, ftc_bitmap);
  874. spin_unlock_irqrestore(&pdc_lock, flags);
  875. return retval;
  876. }
  877. /*
  878. * pdc_do_reset - Reset the system.
  879. *
  880. * Reset the system.
  881. */
  882. int pdc_do_reset(void)
  883. {
  884. int retval;
  885. unsigned long flags;
  886. spin_lock_irqsave(&pdc_lock, flags);
  887. retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_RESET);
  888. spin_unlock_irqrestore(&pdc_lock, flags);
  889. return retval;
  890. }
  891. /*
  892. * pdc_soft_power_info - Enable soft power switch.
  893. * @power_reg: address of soft power register
  894. *
  895. * Return the absolute address of the soft power switch register
  896. */
  897. int __init pdc_soft_power_info(unsigned long *power_reg)
  898. {
  899. int retval;
  900. unsigned long flags;
  901. *power_reg = (unsigned long) (-1);
  902. spin_lock_irqsave(&pdc_lock, flags);
  903. retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_INFO, __pa(pdc_result), 0);
  904. if (retval == PDC_OK) {
  905. convert_to_wide(pdc_result);
  906. *power_reg = f_extend(pdc_result[0]);
  907. }
  908. spin_unlock_irqrestore(&pdc_lock, flags);
  909. return retval;
  910. }
  911. /*
  912. * pdc_soft_power_button - Control the soft power button behaviour
  913. * @sw_control: 0 for hardware control, 1 for software control
  914. *
  915. *
  916. * This PDC function places the soft power button under software or
  917. * hardware control.
  918. * Under software control the OS may control to when to allow to shut
  919. * down the system. Under hardware control pressing the power button
  920. * powers off the system immediately.
  921. */
  922. int pdc_soft_power_button(int sw_control)
  923. {
  924. int retval;
  925. unsigned long flags;
  926. spin_lock_irqsave(&pdc_lock, flags);
  927. retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
  928. spin_unlock_irqrestore(&pdc_lock, flags);
  929. return retval;
  930. }
  931. /*
  932. * pdc_io_reset - Hack to avoid overlapping range registers of Bridges devices.
  933. * Primarily a problem on T600 (which parisc-linux doesn't support) but
  934. * who knows what other platform firmware might do with this OS "hook".
  935. */
  936. void pdc_io_reset(void)
  937. {
  938. unsigned long flags;
  939. spin_lock_irqsave(&pdc_lock, flags);
  940. mem_pdc_call(PDC_IO, PDC_IO_RESET, 0);
  941. spin_unlock_irqrestore(&pdc_lock, flags);
  942. }
  943. /*
  944. * pdc_io_reset_devices - Hack to Stop USB controller
  945. *
  946. * If PDC used the usb controller, the usb controller
  947. * is still running and will crash the machines during iommu
  948. * setup, because of still running DMA. This PDC call
  949. * stops the USB controller.
  950. * Normally called after calling pdc_io_reset().
  951. */
  952. void pdc_io_reset_devices(void)
  953. {
  954. unsigned long flags;
  955. spin_lock_irqsave(&pdc_lock, flags);
  956. mem_pdc_call(PDC_IO, PDC_IO_RESET_DEVICES, 0);
  957. spin_unlock_irqrestore(&pdc_lock, flags);
  958. }
  959. /* locked by pdc_console_lock */
  960. static int __attribute__((aligned(8))) iodc_retbuf[32];
  961. static char __attribute__((aligned(64))) iodc_dbuf[4096];
  962. /**
  963. * pdc_iodc_print - Console print using IODC.
  964. * @str: the string to output.
  965. * @count: length of str
  966. *
  967. * Note that only these special chars are architected for console IODC io:
  968. * BEL, BS, CR, and LF. Others are passed through.
  969. * Since the HP console requires CR+LF to perform a 'newline', we translate
  970. * "\n" to "\r\n".
  971. */
  972. int pdc_iodc_print(const unsigned char *str, unsigned count)
  973. {
  974. unsigned int i;
  975. unsigned long flags;
  976. for (i = 0; i < count && i < 79;) {
  977. switch(str[i]) {
  978. case '\n':
  979. iodc_dbuf[i+0] = '\r';
  980. iodc_dbuf[i+1] = '\n';
  981. i += 2;
  982. goto print;
  983. case '\b': /* BS */
  984. i--; /* overwrite last */
  985. default:
  986. iodc_dbuf[i] = str[i];
  987. i++;
  988. break;
  989. }
  990. }
  991. /* if we're at the end of line, and not already inserting a newline,
  992. * insert one anyway. iodc console doesn't claim to support >79 char
  993. * lines. don't account for this in the return value.
  994. */
  995. if (i == 79 && iodc_dbuf[i-1] != '\n') {
  996. iodc_dbuf[i+0] = '\r';
  997. iodc_dbuf[i+1] = '\n';
  998. }
  999. print:
  1000. spin_lock_irqsave(&pdc_lock, flags);
  1001. real32_call(PAGE0->mem_cons.iodc_io,
  1002. (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
  1003. PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
  1004. __pa(iodc_retbuf), 0, __pa(iodc_dbuf), i, 0);
  1005. spin_unlock_irqrestore(&pdc_lock, flags);
  1006. return i;
  1007. }
  1008. /**
  1009. * pdc_iodc_getc - Read a character (non-blocking) from the PDC console.
  1010. *
  1011. * Read a character (non-blocking) from the PDC console, returns -1 if
  1012. * key is not present.
  1013. */
  1014. int pdc_iodc_getc(void)
  1015. {
  1016. int ch;
  1017. int status;
  1018. unsigned long flags;
  1019. /* Bail if no console input device. */
  1020. if (!PAGE0->mem_kbd.iodc_io)
  1021. return 0;
  1022. /* wait for a keyboard (rs232)-input */
  1023. spin_lock_irqsave(&pdc_lock, flags);
  1024. real32_call(PAGE0->mem_kbd.iodc_io,
  1025. (unsigned long)PAGE0->mem_kbd.hpa, ENTRY_IO_CIN,
  1026. PAGE0->mem_kbd.spa, __pa(PAGE0->mem_kbd.dp.layers),
  1027. __pa(iodc_retbuf), 0, __pa(iodc_dbuf), 1, 0);
  1028. ch = *iodc_dbuf;
  1029. status = *iodc_retbuf;
  1030. spin_unlock_irqrestore(&pdc_lock, flags);
  1031. if (status == 0)
  1032. return -1;
  1033. return ch;
  1034. }
  1035. int pdc_sti_call(unsigned long func, unsigned long flags,
  1036. unsigned long inptr, unsigned long outputr,
  1037. unsigned long glob_cfg)
  1038. {
  1039. int retval;
  1040. unsigned long irqflags;
  1041. spin_lock_irqsave(&pdc_lock, irqflags);
  1042. retval = real32_call(func, flags, inptr, outputr, glob_cfg);
  1043. spin_unlock_irqrestore(&pdc_lock, irqflags);
  1044. return retval;
  1045. }
  1046. EXPORT_SYMBOL(pdc_sti_call);
  1047. #ifdef CONFIG_64BIT
  1048. /**
  1049. * pdc_pat_cell_get_number - Returns the cell number.
  1050. * @cell_info: The return buffer.
  1051. *
  1052. * This PDC call returns the cell number of the cell from which the call
  1053. * is made.
  1054. */
  1055. int pdc_pat_cell_get_number(struct pdc_pat_cell_num *cell_info)
  1056. {
  1057. int retval;
  1058. unsigned long flags;
  1059. spin_lock_irqsave(&pdc_lock, flags);
  1060. retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_GET_NUMBER, __pa(pdc_result));
  1061. memcpy(cell_info, pdc_result, sizeof(*cell_info));
  1062. spin_unlock_irqrestore(&pdc_lock, flags);
  1063. return retval;
  1064. }
  1065. /**
  1066. * pdc_pat_cell_module - Retrieve the cell's module information.
  1067. * @actcnt: The number of bytes written to mem_addr.
  1068. * @ploc: The physical location.
  1069. * @mod: The module index.
  1070. * @view_type: The view of the address type.
  1071. * @mem_addr: The return buffer.
  1072. *
  1073. * This PDC call returns information about each module attached to the cell
  1074. * at the specified location.
  1075. */
  1076. int pdc_pat_cell_module(unsigned long *actcnt, unsigned long ploc, unsigned long mod,
  1077. unsigned long view_type, void *mem_addr)
  1078. {
  1079. int retval;
  1080. unsigned long flags;
  1081. static struct pdc_pat_cell_mod_maddr_block result __attribute__ ((aligned (8)));
  1082. spin_lock_irqsave(&pdc_lock, flags);
  1083. retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_MODULE, __pa(pdc_result),
  1084. ploc, mod, view_type, __pa(&result));
  1085. if(!retval) {
  1086. *actcnt = pdc_result[0];
  1087. memcpy(mem_addr, &result, *actcnt);
  1088. }
  1089. spin_unlock_irqrestore(&pdc_lock, flags);
  1090. return retval;
  1091. }
  1092. /**
  1093. * pdc_pat_cpu_get_number - Retrieve the cpu number.
  1094. * @cpu_info: The return buffer.
  1095. * @hpa: The Hard Physical Address of the CPU.
  1096. *
  1097. * Retrieve the cpu number for the cpu at the specified HPA.
  1098. */
  1099. int pdc_pat_cpu_get_number(struct pdc_pat_cpu_num *cpu_info, void *hpa)
  1100. {
  1101. int retval;
  1102. unsigned long flags;
  1103. spin_lock_irqsave(&pdc_lock, flags);
  1104. retval = mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_GET_NUMBER,
  1105. __pa(&pdc_result), hpa);
  1106. memcpy(cpu_info, pdc_result, sizeof(*cpu_info));
  1107. spin_unlock_irqrestore(&pdc_lock, flags);
  1108. return retval;
  1109. }
  1110. /**
  1111. * pdc_pat_get_irt_size - Retrieve the number of entries in the cell's interrupt table.
  1112. * @num_entries: The return value.
  1113. * @cell_num: The target cell.
  1114. *
  1115. * This PDC function returns the number of entries in the specified cell's
  1116. * interrupt table.
  1117. */
  1118. int pdc_pat_get_irt_size(unsigned long *num_entries, unsigned long cell_num)
  1119. {
  1120. int retval;
  1121. unsigned long flags;
  1122. spin_lock_irqsave(&pdc_lock, flags);
  1123. retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE_SIZE,
  1124. __pa(pdc_result), cell_num);
  1125. *num_entries = pdc_result[0];
  1126. spin_unlock_irqrestore(&pdc_lock, flags);
  1127. return retval;
  1128. }
  1129. /**
  1130. * pdc_pat_get_irt - Retrieve the cell's interrupt table.
  1131. * @r_addr: The return buffer.
  1132. * @cell_num: The target cell.
  1133. *
  1134. * This PDC function returns the actual interrupt table for the specified cell.
  1135. */
  1136. int pdc_pat_get_irt(void *r_addr, unsigned long cell_num)
  1137. {
  1138. int retval;
  1139. unsigned long flags;
  1140. spin_lock_irqsave(&pdc_lock, flags);
  1141. retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE,
  1142. __pa(r_addr), cell_num);
  1143. spin_unlock_irqrestore(&pdc_lock, flags);
  1144. return retval;
  1145. }
  1146. /**
  1147. * pdc_pat_pd_get_addr_map - Retrieve information about memory address ranges.
  1148. * @actlen: The return buffer.
  1149. * @mem_addr: Pointer to the memory buffer.
  1150. * @count: The number of bytes to read from the buffer.
  1151. * @offset: The offset with respect to the beginning of the buffer.
  1152. *
  1153. */
  1154. int pdc_pat_pd_get_addr_map(unsigned long *actual_len, void *mem_addr,
  1155. unsigned long count, unsigned long offset)
  1156. {
  1157. int retval;
  1158. unsigned long flags;
  1159. spin_lock_irqsave(&pdc_lock, flags);
  1160. retval = mem_pdc_call(PDC_PAT_PD, PDC_PAT_PD_GET_ADDR_MAP, __pa(pdc_result),
  1161. __pa(pdc_result2), count, offset);
  1162. *actual_len = pdc_result[0];
  1163. memcpy(mem_addr, pdc_result2, *actual_len);
  1164. spin_unlock_irqrestore(&pdc_lock, flags);
  1165. return retval;
  1166. }
  1167. /**
  1168. * pdc_pat_io_pci_cfg_read - Read PCI configuration space.
  1169. * @pci_addr: PCI configuration space address for which the read request is being made.
  1170. * @pci_size: Size of read in bytes. Valid values are 1, 2, and 4.
  1171. * @mem_addr: Pointer to return memory buffer.
  1172. *
  1173. */
  1174. int pdc_pat_io_pci_cfg_read(unsigned long pci_addr, int pci_size, u32 *mem_addr)
  1175. {
  1176. int retval;
  1177. unsigned long flags;
  1178. spin_lock_irqsave(&pdc_lock, flags);
  1179. retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_READ,
  1180. __pa(pdc_result), pci_addr, pci_size);
  1181. switch(pci_size) {
  1182. case 1: *(u8 *) mem_addr = (u8) pdc_result[0];
  1183. case 2: *(u16 *)mem_addr = (u16) pdc_result[0];
  1184. case 4: *(u32 *)mem_addr = (u32) pdc_result[0];
  1185. }
  1186. spin_unlock_irqrestore(&pdc_lock, flags);
  1187. return retval;
  1188. }
  1189. /**
  1190. * pdc_pat_io_pci_cfg_write - Retrieve information about memory address ranges.
  1191. * @pci_addr: PCI configuration space address for which the write request is being made.
  1192. * @pci_size: Size of write in bytes. Valid values are 1, 2, and 4.
  1193. * @value: Pointer to 1, 2, or 4 byte value in low order end of argument to be
  1194. * written to PCI Config space.
  1195. *
  1196. */
  1197. int pdc_pat_io_pci_cfg_write(unsigned long pci_addr, int pci_size, u32 val)
  1198. {
  1199. int retval;
  1200. unsigned long flags;
  1201. spin_lock_irqsave(&pdc_lock, flags);
  1202. retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_WRITE,
  1203. pci_addr, pci_size, val);
  1204. spin_unlock_irqrestore(&pdc_lock, flags);
  1205. return retval;
  1206. }
  1207. #endif /* CONFIG_64BIT */
  1208. /***************** 32-bit real-mode calls ***********/
  1209. /* The struct below is used
  1210. * to overlay real_stack (real2.S), preparing a 32-bit call frame.
  1211. * real32_call_asm() then uses this stack in narrow real mode
  1212. */
  1213. struct narrow_stack {
  1214. /* use int, not long which is 64 bits */
  1215. unsigned int arg13;
  1216. unsigned int arg12;
  1217. unsigned int arg11;
  1218. unsigned int arg10;
  1219. unsigned int arg9;
  1220. unsigned int arg8;
  1221. unsigned int arg7;
  1222. unsigned int arg6;
  1223. unsigned int arg5;
  1224. unsigned int arg4;
  1225. unsigned int arg3;
  1226. unsigned int arg2;
  1227. unsigned int arg1;
  1228. unsigned int arg0;
  1229. unsigned int frame_marker[8];
  1230. unsigned int sp;
  1231. /* in reality, there's nearly 8k of stack after this */
  1232. };
  1233. long real32_call(unsigned long fn, ...)
  1234. {
  1235. va_list args;
  1236. extern struct narrow_stack real_stack;
  1237. extern unsigned long real32_call_asm(unsigned int *,
  1238. unsigned int *,
  1239. unsigned int);
  1240. va_start(args, fn);
  1241. real_stack.arg0 = va_arg(args, unsigned int);
  1242. real_stack.arg1 = va_arg(args, unsigned int);
  1243. real_stack.arg2 = va_arg(args, unsigned int);
  1244. real_stack.arg3 = va_arg(args, unsigned int);
  1245. real_stack.arg4 = va_arg(args, unsigned int);
  1246. real_stack.arg5 = va_arg(args, unsigned int);
  1247. real_stack.arg6 = va_arg(args, unsigned int);
  1248. real_stack.arg7 = va_arg(args, unsigned int);
  1249. real_stack.arg8 = va_arg(args, unsigned int);
  1250. real_stack.arg9 = va_arg(args, unsigned int);
  1251. real_stack.arg10 = va_arg(args, unsigned int);
  1252. real_stack.arg11 = va_arg(args, unsigned int);
  1253. real_stack.arg12 = va_arg(args, unsigned int);
  1254. real_stack.arg13 = va_arg(args, unsigned int);
  1255. va_end(args);
  1256. return real32_call_asm(&real_stack.sp, &real_stack.arg0, fn);
  1257. }
  1258. #ifdef CONFIG_64BIT
  1259. /***************** 64-bit real-mode calls ***********/
  1260. struct wide_stack {
  1261. unsigned long arg0;
  1262. unsigned long arg1;
  1263. unsigned long arg2;
  1264. unsigned long arg3;
  1265. unsigned long arg4;
  1266. unsigned long arg5;
  1267. unsigned long arg6;
  1268. unsigned long arg7;
  1269. unsigned long arg8;
  1270. unsigned long arg9;
  1271. unsigned long arg10;
  1272. unsigned long arg11;
  1273. unsigned long arg12;
  1274. unsigned long arg13;
  1275. unsigned long frame_marker[2]; /* rp, previous sp */
  1276. unsigned long sp;
  1277. /* in reality, there's nearly 8k of stack after this */
  1278. };
  1279. long real64_call(unsigned long fn, ...)
  1280. {
  1281. va_list args;
  1282. extern struct wide_stack real64_stack;
  1283. extern unsigned long real64_call_asm(unsigned long *,
  1284. unsigned long *,
  1285. unsigned long);
  1286. va_start(args, fn);
  1287. real64_stack.arg0 = va_arg(args, unsigned long);
  1288. real64_stack.arg1 = va_arg(args, unsigned long);
  1289. real64_stack.arg2 = va_arg(args, unsigned long);
  1290. real64_stack.arg3 = va_arg(args, unsigned long);
  1291. real64_stack.arg4 = va_arg(args, unsigned long);
  1292. real64_stack.arg5 = va_arg(args, unsigned long);
  1293. real64_stack.arg6 = va_arg(args, unsigned long);
  1294. real64_stack.arg7 = va_arg(args, unsigned long);
  1295. real64_stack.arg8 = va_arg(args, unsigned long);
  1296. real64_stack.arg9 = va_arg(args, unsigned long);
  1297. real64_stack.arg10 = va_arg(args, unsigned long);
  1298. real64_stack.arg11 = va_arg(args, unsigned long);
  1299. real64_stack.arg12 = va_arg(args, unsigned long);
  1300. real64_stack.arg13 = va_arg(args, unsigned long);
  1301. va_end(args);
  1302. return real64_call_asm(&real64_stack.sp, &real64_stack.arg0, fn);
  1303. }
  1304. #endif /* CONFIG_64BIT */