firmware.c 43 KB

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