~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/parisc/kernel/firmware.c

Version: ~ [ linux-5.1-rc2 ] ~ [ linux-5.0.4 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.31 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.108 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.165 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.177 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.137 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.63 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp