firmware.c 40 KB

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