Repository navigation
Expand file tree
/
Copy pathfirmware.c
More file actions
1496 lines (1295 loc) · 41.9 KB
/
Copy pathfirmware.c
File metadata and controls
1496 lines (1295 loc) · 41.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* arch/parisc/kernel/firmware.c - safe PDC access routines
*
* PDC == Processor Dependent Code
*
* See http://www.parisc-linux.org/documentation/index.html
* for documentation describing the entry points and calling
* conventions defined below.
*
* Copyright 1999 SuSE GmbH Nuernberg (Philipp Rumpf, prumpf@tux.org)
* Copyright 1999 The Puffin Group, (Alex deVries, David Kennedy)
* Copyright 2003 Grant Grundler <grundler parisc-linux org>
* Copyright 2003,2004 Ryan Bradetich <rbrad@parisc-linux.org>
* Copyright 2004,2006 Thibaut VARENE <varenet@parisc-linux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*/
/* I think it would be in everyone's best interest to follow this
* guidelines when writing PDC wrappers:
*
* - the name of the pdc wrapper should match one of the macros
* used for the first two arguments
* - don't use caps for random parts of the name
* - use the static PDC result buffers and "copyout" to structs
* supplied by the caller to encapsulate alignment restrictions
* - hold pdc_lock while in PDC or using static result buffers
* - use __pa() to convert virtual (kernel) pointers to physical
* ones.
* - the name of the struct used for pdc return values should equal
* one of the macros used for the first two arguments to the
* corresponding PDC call
* - keep the order of arguments
* - don't be smart (setting trailing NUL bytes for strings, return
* something useful even if the call failed) unless you are sure
* it's not going to affect functionality or performance
*
* Example:
* int pdc_cache_info(struct pdc_cache_info *cache_info )
* {
* int retval;
*
* spin_lock_irq(&pdc_lock);
* retval = mem_pdc_call(PDC_CACHE,PDC_CACHE_INFO,__pa(cache_info),0);
* convert_to_wide(pdc_result);
* memcpy(cache_info, pdc_result, sizeof(*cache_info));
* spin_unlock_irq(&pdc_lock);
*
* return retval;
* }
* prumpf 991016
*/
#include <stdarg.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/spinlock.h>
#include <asm/page.h>
#include <asm/pdc.h>
#include <asm/pdcpat.h>
#include <asm/processor.h> /* for boot_cpu_data */
static DEFINE_SPINLOCK(pdc_lock);
extern unsigned long pdc_result[NUM_PDC_RESULT];
extern unsigned long pdc_result2[NUM_PDC_RESULT];
#ifdef CONFIG_64BIT
#define WIDE_FIRMWARE 0x1
#define NARROW_FIRMWARE 0x2
/* Firmware needs to be initially set to narrow to determine the
* actual firmware width. */
int parisc_narrow_firmware __read_mostly = 1;
#endif
/* On most currently-supported platforms, IODC I/O calls are 32-bit calls
* and MEM_PDC calls are always the same width as the OS.
* Some PAT boxes may have 64-bit IODC I/O.
*
* Ryan Bradetich added the now obsolete CONFIG_PDC_NARROW to allow
* 64-bit kernels to run on systems with 32-bit MEM_PDC calls.
* This allowed wide kernels to run on Cxxx boxes.
* We now detect 32-bit-only PDC and dynamically switch to 32-bit mode
* when running a 64-bit kernel on such boxes (e.g. C200 or C360).
*/
#ifdef CONFIG_64BIT
long real64_call(unsigned long function, ...);
#endif
long real32_call(unsigned long function, ...);
#ifdef CONFIG_64BIT
# define MEM_PDC (unsigned long)(PAGE0->mem_pdc_hi) << 32 | PAGE0->mem_pdc
# define mem_pdc_call(args...) unlikely(parisc_narrow_firmware) ? real32_call(MEM_PDC, args) : real64_call(MEM_PDC, args)
#else
# define MEM_PDC (unsigned long)PAGE0->mem_pdc
# define mem_pdc_call(args...) real32_call(MEM_PDC, args)
#endif
/**
* f_extend - Convert PDC addresses to kernel addresses.
* @address: Address returned from PDC.
*
* This function is used to convert PDC addresses into kernel addresses
* when the PDC address size and kernel address size are different.
*/
static unsigned long f_extend(unsigned long address)
{
#ifdef CONFIG_64BIT
if(unlikely(parisc_narrow_firmware)) {
if((address & 0xff000000) == 0xf0000000)
return 0xf0f0f0f000000000UL | (u32)address;
if((address & 0xf0000000) == 0xf0000000)
return 0xffffffff00000000UL | (u32)address;
}
#endif
return address;
}
/**
* convert_to_wide - Convert the return buffer addresses into kernel addresses.
* @address: The return buffer from PDC.
*
* This function is used to convert the return buffer addresses retrieved from PDC
* into kernel addresses when the PDC address size and kernel address size are
* different.
*/
static void convert_to_wide(unsigned long *addr)
{
#ifdef CONFIG_64BIT
int i;
unsigned int *p = (unsigned int *)addr;
if(unlikely(parisc_narrow_firmware)) {
for(i = 31; i >= 0; --i)
addr[i] = p[i];
}
#endif
}
#ifdef CONFIG_64BIT
void set_firmware_width_unlocked(void)
{
int ret;
ret = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES,
__pa(pdc_result), 0);
convert_to_wide(pdc_result);
if (pdc_result[0] != NARROW_FIRMWARE)
parisc_narrow_firmware = 0;
}
/**
* set_firmware_width - Determine if the firmware is wide or narrow.
*
* This function must be called before any pdc_* function that uses the
* convert_to_wide function.
*/
void set_firmware_width(void)
{
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
set_firmware_width_unlocked();
spin_unlock_irqrestore(&pdc_lock, flags);
}
#else
void set_firmware_width_unlocked(void)
{
return;
}
void set_firmware_width(void)
{
return;
}
#endif /*CONFIG_64BIT*/
/**
* pdc_emergency_unlock - Unlock the linux pdc lock
*
* This call unlocks the linux pdc lock in case we need some PDC functions
* (like pdc_add_valid) during kernel stack dump.
*/
void pdc_emergency_unlock(void)
{
/* Spinlock DEBUG code freaks out if we unconditionally unlock */
if (spin_is_locked(&pdc_lock))
spin_unlock(&pdc_lock);
}
/**
* pdc_add_valid - Verify address can be accessed without causing a HPMC.
* @address: Address to be verified.
*
* This PDC call attempts to read from the specified address and verifies
* if the address is valid.
*
* The return value is PDC_OK (0) in case accessing this address is valid.
*/
int pdc_add_valid(unsigned long address)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_ADD_VALID, PDC_ADD_VALID_VERIFY, address);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_add_valid);
/**
* pdc_chassis_info - Return chassis information.
* @result: The return buffer.
* @chassis_info: The memory buffer address.
* @len: The size of the memory buffer address.
*
* An HVERSION dependent call for returning the chassis information.
*/
int __init pdc_chassis_info(struct pdc_chassis_info *chassis_info, void *led_info, unsigned long len)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
memcpy(&pdc_result, chassis_info, sizeof(*chassis_info));
memcpy(&pdc_result2, led_info, len);
retval = mem_pdc_call(PDC_CHASSIS, PDC_RETURN_CHASSIS_INFO,
__pa(pdc_result), __pa(pdc_result2), len);
memcpy(chassis_info, pdc_result, sizeof(*chassis_info));
memcpy(led_info, pdc_result2, len);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
/**
* pdc_pat_chassis_send_log - Sends a PDC PAT CHASSIS log message.
* @retval: -1 on error, 0 on success. Other value are PDC errors
*
* Must be correctly formatted or expect system crash
*/
#ifdef CONFIG_64BIT
int pdc_pat_chassis_send_log(unsigned long state, unsigned long data)
{
int retval = 0;
unsigned long flags;
if (!is_pdc_pat())
return -1;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_PAT_CHASSIS_LOG, PDC_PAT_CHASSIS_WRITE_LOG, __pa(&state), __pa(&data));
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
#endif
/**
* pdc_chassis_disp - Updates chassis code
* @retval: -1 on error, 0 on success
*/
int pdc_chassis_disp(unsigned long disp)
{
int retval = 0;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_DISP, disp);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
/**
* pdc_chassis_warn - Fetches chassis warnings
* @retval: -1 on error, 0 on success
*/
int pdc_chassis_warn(unsigned long *warn)
{
int retval = 0;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_WARN, __pa(pdc_result));
*warn = pdc_result[0];
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
int pdc_coproc_cfg_unlocked(struct pdc_coproc_cfg *pdc_coproc_info)
{
int ret;
ret = mem_pdc_call(PDC_COPROC, PDC_COPROC_CFG, __pa(pdc_result));
convert_to_wide(pdc_result);
pdc_coproc_info->ccr_functional = pdc_result[0];
pdc_coproc_info->ccr_present = pdc_result[1];
pdc_coproc_info->revision = pdc_result[17];
pdc_coproc_info->model = pdc_result[18];
return ret;
}
/**
* pdc_coproc_cfg - To identify coprocessors attached to the processor.
* @pdc_coproc_info: Return buffer address.
*
* This PDC call returns the presence and status of all the coprocessors
* attached to the processor.
*/
int pdc_coproc_cfg(struct pdc_coproc_cfg *pdc_coproc_info)
{
int ret;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
ret = pdc_coproc_cfg_unlocked(pdc_coproc_info);
spin_unlock_irqrestore(&pdc_lock, flags);
return ret;
}
/**
* pdc_iodc_read - Read data from the modules IODC.
* @actcnt: The actual number of bytes.
* @hpa: The HPA of the module for the iodc read.
* @index: The iodc entry point.
* @iodc_data: A buffer memory for the iodc options.
* @iodc_data_size: Size of the memory buffer.
*
* This PDC call reads from the IODC of the module specified by the hpa
* argument.
*/
int pdc_iodc_read(unsigned long *actcnt, unsigned long hpa, unsigned int index,
void *iodc_data, unsigned int iodc_data_size)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_IODC, PDC_IODC_READ, __pa(pdc_result), hpa,
index, __pa(pdc_result2), iodc_data_size);
convert_to_wide(pdc_result);
*actcnt = pdc_result[0];
memcpy(iodc_data, pdc_result2, iodc_data_size);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_iodc_read);
/**
* pdc_system_map_find_mods - Locate unarchitected modules.
* @pdc_mod_info: Return buffer address.
* @mod_path: pointer to dev path structure.
* @mod_index: fixed address module index.
*
* To locate and identify modules which reside at fixed I/O addresses, which
* do not self-identify via architected bus walks.
*/
int pdc_system_map_find_mods(struct pdc_system_map_mod_info *pdc_mod_info,
struct pdc_module_path *mod_path, long mod_index)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_MODULE, __pa(pdc_result),
__pa(pdc_result2), mod_index);
convert_to_wide(pdc_result);
memcpy(pdc_mod_info, pdc_result, sizeof(*pdc_mod_info));
memcpy(mod_path, pdc_result2, sizeof(*mod_path));
spin_unlock_irqrestore(&pdc_lock, flags);
pdc_mod_info->mod_addr = f_extend(pdc_mod_info->mod_addr);
return retval;
}
/**
* pdc_system_map_find_addrs - Retrieve additional address ranges.
* @pdc_addr_info: Return buffer address.
* @mod_index: Fixed address module index.
* @addr_index: Address range index.
*
* Retrieve additional information about subsequent address ranges for modules
* with multiple address ranges.
*/
int pdc_system_map_find_addrs(struct pdc_system_map_addr_info *pdc_addr_info,
long mod_index, long addr_index)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_ADDRESS, __pa(pdc_result),
mod_index, addr_index);
convert_to_wide(pdc_result);
memcpy(pdc_addr_info, pdc_result, sizeof(*pdc_addr_info));
spin_unlock_irqrestore(&pdc_lock, flags);
pdc_addr_info->mod_addr = f_extend(pdc_addr_info->mod_addr);
return retval;
}
/**
* pdc_model_info - Return model information about the processor.
* @model: The return buffer.
*
* Returns the version numbers, identifiers, and capabilities from the processor module.
*/
int pdc_model_info(struct pdc_model *model)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_INFO, __pa(pdc_result), 0);
convert_to_wide(pdc_result);
memcpy(model, pdc_result, sizeof(*model));
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
/**
* pdc_model_sysmodel - Get the system model name.
* @name: A char array of at least 81 characters.
*
* Get system model name from PDC ROM (e.g. 9000/715 or 9000/778/B160L).
* Using OS_ID_HPUX will return the equivalent of the 'modelname' command
* on HP/UX.
*/
int pdc_model_sysmodel(char *name)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_SYSMODEL, __pa(pdc_result),
OS_ID_HPUX, __pa(name));
convert_to_wide(pdc_result);
if (retval == PDC_OK) {
name[pdc_result[0]] = '\0'; /* add trailing '\0' */
} else {
name[0] = 0;
}
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
/**
* pdc_model_versions - Identify the version number of each processor.
* @cpu_id: The return buffer.
* @id: The id of the processor to check.
*
* Returns the version number for each processor component.
*
* This comment was here before, but I do not know what it means :( -RB
* id: 0 = cpu revision, 1 = boot-rom-version
*/
int pdc_model_versions(unsigned long *versions, int id)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_VERSIONS, __pa(pdc_result), id);
convert_to_wide(pdc_result);
*versions = pdc_result[0];
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
/**
* pdc_model_cpuid - Returns the CPU_ID.
* @cpu_id: The return buffer.
*
* Returns the CPU_ID value which uniquely identifies the cpu portion of
* the processor module.
*/
int pdc_model_cpuid(unsigned long *cpu_id)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CPU_ID, __pa(pdc_result), 0);
convert_to_wide(pdc_result);
*cpu_id = pdc_result[0];
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
/**
* pdc_model_capabilities - Returns the platform capabilities.
* @capabilities: The return buffer.
*
* Returns information about platform support for 32- and/or 64-bit
* OSes, IO-PDIR coherency, and virtual aliasing.
*/
int pdc_model_capabilities(unsigned long *capabilities)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES, __pa(pdc_result), 0);
convert_to_wide(pdc_result);
if (retval == PDC_OK) {
*capabilities = pdc_result[0];
} else {
*capabilities = PDC_MODEL_OS32;
}
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
/**
* pdc_cache_info - Return cache and TLB information.
* @cache_info: The return buffer.
*
* Returns information about the processor's cache and TLB.
*/
int pdc_cache_info(struct pdc_cache_info *cache_info)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_INFO, __pa(pdc_result), 0);
convert_to_wide(pdc_result);
memcpy(cache_info, pdc_result, sizeof(*cache_info));
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
/**
* pdc_spaceid_bits - Return whether Space ID hashing is turned on.
* @space_bits: Should be 0, if not, bad mojo!
*
* Returns information about Space ID hashing.
*/
int pdc_spaceid_bits(unsigned long *space_bits)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
pdc_result[0] = 0;
retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_RET_SPID, __pa(pdc_result), 0);
convert_to_wide(pdc_result);
*space_bits = pdc_result[0];
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
#ifndef CONFIG_PA20
/**
* pdc_btlb_info - Return block TLB information.
* @btlb: The return buffer.
*
* Returns information about the hardware Block TLB.
*/
int pdc_btlb_info(struct pdc_btlb_info *btlb)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_INFO, __pa(pdc_result), 0);
memcpy(btlb, pdc_result, sizeof(*btlb));
spin_unlock_irqrestore(&pdc_lock, flags);
if(retval < 0) {
btlb->max_size = 0;
}
return retval;
}
/**
* pdc_mem_map_hpa - Find fixed module information.
* @address: The return buffer
* @mod_path: pointer to dev path structure.
*
* This call was developed for S700 workstations to allow the kernel to find
* the I/O devices (Core I/O). In the future (Kittyhawk and beyond) this
* call will be replaced (on workstations) by the architected PDC_SYSTEM_MAP
* call.
*
* This call is supported by all existing S700 workstations (up to Gecko).
*/
int pdc_mem_map_hpa(struct pdc_memory_map *address,
struct pdc_module_path *mod_path)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
memcpy(pdc_result2, mod_path, sizeof(*mod_path));
retval = mem_pdc_call(PDC_MEM_MAP, PDC_MEM_MAP_HPA, __pa(pdc_result),
__pa(pdc_result2));
memcpy(address, pdc_result, sizeof(*address));
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
#endif /* !CONFIG_PA20 */
/**
* pdc_lan_station_id - Get the LAN address.
* @lan_addr: The return buffer.
* @hpa: The network device HPA.
*
* Get the LAN station address when it is not directly available from the LAN hardware.
*/
int pdc_lan_station_id(char *lan_addr, unsigned long hpa)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_LAN_STATION_ID, PDC_LAN_STATION_ID_READ,
__pa(pdc_result), hpa);
if (retval < 0) {
/* FIXME: else read MAC from NVRAM */
memset(lan_addr, 0, PDC_LAN_STATION_ID_SIZE);
} else {
memcpy(lan_addr, pdc_result, PDC_LAN_STATION_ID_SIZE);
}
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_lan_station_id);
/**
* pdc_stable_read - Read data from Stable Storage.
* @staddr: Stable Storage address to access.
* @memaddr: The memory address where Stable Storage data shall be copied.
* @count: number of bytes to transfer. count is multiple of 4.
*
* This PDC call reads from the Stable Storage address supplied in staddr
* and copies count bytes to the memory address memaddr.
* The call will fail if staddr+count > PDC_STABLE size.
*/
int pdc_stable_read(unsigned long staddr, void *memaddr, unsigned long count)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_READ, staddr,
__pa(pdc_result), count);
convert_to_wide(pdc_result);
memcpy(memaddr, pdc_result, count);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_stable_read);
/**
* pdc_stable_write - Write data to Stable Storage.
* @staddr: Stable Storage address to access.
* @memaddr: The memory address where Stable Storage data shall be read from.
* @count: number of bytes to transfer. count is multiple of 4.
*
* This PDC call reads count bytes from the supplied memaddr address,
* and copies count bytes to the Stable Storage address staddr.
* The call will fail if staddr+count > PDC_STABLE size.
*/
int pdc_stable_write(unsigned long staddr, void *memaddr, unsigned long count)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
memcpy(pdc_result, memaddr, count);
convert_to_wide(pdc_result);
retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_WRITE, staddr,
__pa(pdc_result), count);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_stable_write);
/**
* pdc_stable_get_size - Get Stable Storage size in bytes.
* @size: pointer where the size will be stored.
*
* This PDC call returns the number of bytes in the processor's Stable
* Storage, which is the number of contiguous bytes implemented in Stable
* Storage starting from staddr=0. size in an unsigned 64-bit integer
* which is a multiple of four.
*/
int pdc_stable_get_size(unsigned long *size)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_RETURN_SIZE, __pa(pdc_result));
*size = pdc_result[0];
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_stable_get_size);
/**
* pdc_stable_verify_contents - Checks that Stable Storage contents are valid.
*
* This PDC call is meant to be used to check the integrity of the current
* contents of Stable Storage.
*/
int pdc_stable_verify_contents(void)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_VERIFY_CONTENTS);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_stable_verify_contents);
/**
* pdc_stable_initialize - Sets Stable Storage contents to zero and initialize
* the validity indicator.
*
* This PDC call will erase all contents of Stable Storage. Use with care!
*/
int pdc_stable_initialize(void)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_INITIALIZE);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_stable_initialize);
/**
* pdc_get_initiator - Get the SCSI Interface Card params (SCSI ID, SDTR, SE or LVD)
* @hwpath: fully bc.mod style path to the device.
* @initiator: the array to return the result into
*
* Get the SCSI operational parameters from PDC.
* Needed since HPUX never used BIOS or symbios card NVRAM.
* Most ncr/sym cards won't have an entry and just use whatever
* capabilities of the card are (eg Ultra, LVD). But there are
* several cases where it's useful:
* o set SCSI id for Multi-initiator clusters,
* o cable too long (ie SE scsi 10Mhz won't support 6m length),
* o bus width exported is less than what the interface chip supports.
*/
int pdc_get_initiator(struct hardware_path *hwpath, struct pdc_initiator *initiator)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
/* BCJ-XXXX series boxes. E.G. "9000/785/C3000" */
#define IS_SPROCKETS() (strlen(boot_cpu_data.pdc.sys_model_name) == 14 && \
strncmp(boot_cpu_data.pdc.sys_model_name, "9000/785", 8) == 0)
retval = mem_pdc_call(PDC_INITIATOR, PDC_GET_INITIATOR,
__pa(pdc_result), __pa(hwpath));
if (retval < PDC_OK)
goto out;
if (pdc_result[0] < 16) {
initiator->host_id = pdc_result[0];
} else {
initiator->host_id = -1;
}
/*
* Sprockets and Piranha return 20 or 40 (MT/s). Prelude returns
* 1, 2, 5 or 10 for 5, 10, 20 or 40 MT/s, respectively
*/
switch (pdc_result[1]) {
case 1: initiator->factor = 50; break;
case 2: initiator->factor = 25; break;
case 5: initiator->factor = 12; break;
case 25: initiator->factor = 10; break;
case 20: initiator->factor = 12; break;
case 40: initiator->factor = 10; break;
default: initiator->factor = -1; break;
}
if (IS_SPROCKETS()) {
initiator->width = pdc_result[4];
initiator->mode = pdc_result[5];
} else {
initiator->width = -1;
initiator->mode = -1;
}
out:
spin_unlock_irqrestore(&pdc_lock, flags);
return (retval >= PDC_OK);
}
EXPORT_SYMBOL(pdc_get_initiator);
/**
* pdc_pci_irt_size - Get the number of entries in the interrupt routing table.
* @num_entries: The return value.
* @hpa: The HPA for the device.
*
* This PDC function returns the number of entries in the specified cell's
* interrupt table.
* Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
*/
int pdc_pci_irt_size(unsigned long *num_entries, unsigned long hpa)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL_SIZE,
__pa(pdc_result), hpa);
convert_to_wide(pdc_result);
*num_entries = pdc_result[0];
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
/**
* pdc_pci_irt - Get the PCI interrupt routing table.
* @num_entries: The number of entries in the table.
* @hpa: The Hard Physical Address of the device.
* @tbl:
*
* Get the PCI interrupt routing table for the device at the given HPA.
* Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
*/
int pdc_pci_irt(unsigned long num_entries, unsigned long hpa, void *tbl)
{
int retval;
unsigned long flags;
BUG_ON((unsigned long)tbl & 0x7);
spin_lock_irqsave(&pdc_lock, flags);
pdc_result[0] = num_entries;
retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL,
__pa(pdc_result), hpa, __pa(tbl));
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
#if 0 /* UNTEST CODE - left here in case someone needs it */
/**
* pdc_pci_config_read - read PCI config space.
* @hpa token from PDC to indicate which PCI device
* @pci_addr configuration space address to read from
*
* Read PCI Configuration space *before* linux PCI subsystem is running.
*/
unsigned int pdc_pci_config_read(void *hpa, unsigned long cfg_addr)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
pdc_result[0] = 0;
pdc_result[1] = 0;
retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_READ_CONFIG,
__pa(pdc_result), hpa, cfg_addr&~3UL, 4UL);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval ? ~0 : (unsigned int) pdc_result[0];
}
/**
* pdc_pci_config_write - read PCI config space.
* @hpa token from PDC to indicate which PCI device
* @pci_addr configuration space address to write
* @val value we want in the 32-bit register
*
* Write PCI Configuration space *before* linux PCI subsystem is running.
*/
void pdc_pci_config_write(void *hpa, unsigned long cfg_addr, unsigned int val)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
pdc_result[0] = 0;
retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_WRITE_CONFIG,
__pa(pdc_result), hpa,
cfg_addr&~3UL, 4UL, (unsigned long) val);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
#endif /* UNTESTED CODE */
/**
* pdc_tod_read - Read the Time-Of-Day clock.
* @tod: The return buffer:
*
* Read the Time-Of-Day clock
*/
int pdc_tod_read(struct pdc_tod *tod)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_TOD, PDC_TOD_READ, __pa(pdc_result), 0);
convert_to_wide(pdc_result);
memcpy(tod, pdc_result, sizeof(*tod));
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_tod_read);
/**
* pdc_tod_set - Set the Time-Of-Day clock.
* @sec: The number of seconds since epoch.
* @usec: The number of micro seconds.
*
* Set the Time-Of-Day clock.
*/
int pdc_tod_set(unsigned long sec, unsigned long usec)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_TOD, PDC_TOD_WRITE, sec, usec);
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
EXPORT_SYMBOL(pdc_tod_set);
#ifdef CONFIG_64BIT
int pdc_mem_mem_table(struct pdc_memory_table_raddr *r_addr,
struct pdc_memory_table *tbl, unsigned long entries)
{
int retval;
unsigned long flags;
spin_lock_irqsave(&pdc_lock, flags);
retval = mem_pdc_call(PDC_MEM, PDC_MEM_TABLE, __pa(pdc_result), __pa(pdc_result2), entries);
convert_to_wide(pdc_result);
memcpy(r_addr, pdc_result, sizeof(*r_addr));
memcpy(tbl, pdc_result2, entries * sizeof(*tbl));
spin_unlock_irqrestore(&pdc_lock, flags);
return retval;
}
#endif /* CONFIG_64BIT */
/* FIXME: Is this pdc used? I could not find type reference to ftc_bitmap
* so I guessed at unsigned long. Someone who knows what this does, can fix
* it later. :)