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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/time.h>
#include <sys/cpuvar.h>
#include <sys/dditypes.h>
#include <sys/ddipropdefs.h>
#include <sys/ddi_impldefs.h>
#include <sys/sunddi.h>
#include <sys/esunddi.h>
#include <sys/sunndi.h>
#include <sys/platform_module.h>
#include <sys/errno.h>
#include <sys/conf.h>
#include <sys/modctl.h>
#include <sys/promif.h>
#include <sys/promimpl.h>
#include <sys/prom_plat.h>
#include <sys/cmn_err.h>
#include <sys/sysmacros.h>
#include <sys/mem_cage.h>
#include <sys/kobj.h>
#include <sys/utsname.h>
#include <sys/cpu_sgnblk_defs.h>
#include <sys/atomic.h>
#include <sys/kdi_impl.h>
#include <sys/sgsbbc.h>
#include <sys/sgsbbc_iosram.h>
#include <sys/sgsbbc_iosram_priv.h>
#include <sys/sgsbbc_mailbox.h>
#include <sys/sgsgn.h>
#include <sys/serengeti.h>
#include <sys/sgfrutypes.h>
#include <sys/machsystm.h>
#include <sys/sbd_ioctl.h>
#include <sys/sbd.h>
#include <sys/sbdp_mem.h>
#include <sys/sgcn.h>
#include <sys/memnode.h>
#include <vm/vm_dep.h>
#include <vm/page.h>
#include <sys/cheetahregs.h>
#include <sys/plat_ecc_unum.h>
#include <sys/plat_ecc_dimm.h>
#include <sys/lgrp.h>
#include <sys/clock_impl.h>
static int sg_debug = 0;
#ifdef DEBUG
#define DCMNERR if (sg_debug) cmn_err
#else
#define DCMNERR
#endif
int (*p2get_mem_unum)(int, uint64_t, char *, int, int *);
/* local functions */
static void cpu_sgn_update(ushort_t sgn, uchar_t state,
uchar_t sub_state, int cpuid);
/*
* Local data.
*
* iosram_write_ptr is a pointer to iosram_write(). Because of
* kernel dynamic linking, we can't get to the function by name,
* but we can look up its address, and store it in this variable
* instead.
*
* We include the extern for iosram_write() here not because we call
* it, but to force compilation errors if its prototype doesn't
* match the prototype of iosram_write_ptr.
*
* The same issues apply to iosram_read() and iosram_read_ptr.
*/
/*CSTYLED*/
extern int iosram_write (int, uint32_t, caddr_t, uint32_t);
static int (*iosram_write_ptr)(int, uint32_t, caddr_t, uint32_t) = NULL;
/*CSTYLED*/
extern int iosram_read (int, uint32_t, caddr_t, uint32_t);
static int (*iosram_read_ptr)(int, uint32_t, caddr_t, uint32_t) = NULL;
/*
* Variable to indicate if the date should be obtained from the SC or not.
*/
int todsg_use_sc = FALSE; /* set the false at the beginning */
/*
* Preallocation of spare tsb's for DR
*
* We don't allocate spares for Wildcat since TSBs should come
* out of memory local to the node.
*/
#define IOMMU_PER_SCHIZO 2
int serengeti_tsb_spares = (SG_MAX_IO_BDS * SG_SCHIZO_PER_IO_BD *
IOMMU_PER_SCHIZO);
/*
* sg_max_ncpus is the maximum number of CPUs supported on lw8.
* sg_max_ncpus is set to be smaller than NCPU to reduce the amount of
* memory the logs take up until we have a dynamic log memory allocation
* solution.
*/
int sg_max_ncpus = (12 * 2); /* (max # of processors * # of cores/proc) */
/*
* variables to control mailbox message timeouts.
* These can be patched via /etc/system or mdb.
*/
int sbbc_mbox_default_timeout = MBOX_DEFAULT_TIMEOUT;
int sbbc_mbox_min_timeout = MBOX_MIN_TIMEOUT;
/* cached 'chosen' node_id */
pnode_t chosen_nodeid = (pnode_t)0;
/*
* Table that maps memory slices to a specific memnode.
*/
int slice_to_memnode[SG_MAX_SLICE];
/*
* We define and use LW8_MAX_CPU_BDS here instead of SG_MAX_CPU_BDS
* since a LW8 machine will never have a CPU/Mem board #5 (SB5).
* A LW8 machine can only have a maximum of three CPU/Mem boards, but
* the board numbers assigned are 0, 2, and 4. LW8_MAX_CPU_BDS is
* defined to be 5 since the entries in the domain_dimm_sids array
* are keyed by board number. Not perfect but some wasted space
* is avoided.
*/
#define LW8_MAX_CPU_BDS 5
plat_dimm_sid_board_t domain_dimm_sids[LW8_MAX_CPU_BDS];
int
set_platform_tsb_spares()
{
return (MIN(serengeti_tsb_spares, MAX_UPA));
}
#pragma weak mmu_init_large_pages
void
set_platform_defaults(void)
{
extern int watchdog_enable;
extern uint64_t xc_tick_limit_scale;
extern void mmu_init_large_pages(size_t);
#ifdef DEBUG
char *todsg_name = "todsg";
ce_verbose_memory = 2;
ce_verbose_other = 2;
#endif /* DEBUG */
watchdog_enable = TRUE;
watchdog_available = TRUE;
cpu_sgn_func = cpu_sgn_update;
#ifdef DEBUG
/* tod_module_name should be set to "todsg" from OBP property */
if (tod_module_name && (strcmp(tod_module_name, todsg_name) == 0))
prom_printf("Using todsg driver\n");
else {
prom_printf("Force using todsg driver\n");
tod_module_name = todsg_name;
}
#endif /* DEBUG */
/* lw8 does not support forthdebug */
forthdebug_supported = 0;
/*
* Some DR operations require the system to be sync paused.
* Sync pause on Serengeti could potentially take up to 4
* seconds to complete depending on the load on the SC. To
* avoid send_mond panics during such operations, we need to
* increase xc_tick_limit to a larger value on Serengeti by
* setting xc_tick_limit_scale to 5.
*/
xc_tick_limit_scale = 5;
if ((mmu_page_sizes == max_mmu_page_sizes) &&
(mmu_ism_pagesize != DEFAULT_ISM_PAGESIZE)) {
if (&mmu_init_large_pages)
mmu_init_large_pages(mmu_ism_pagesize);
}
}
void
load_platform_modules(void)
{
if (modload("misc", "pcihp") < 0) {
cmn_err(CE_NOTE, "pcihp driver failed to load");
}
}
/*ARGSUSED*/
int
plat_cpu_poweron(struct cpu *cp)
{
int (*serengeti_cpu_poweron)(struct cpu *) = NULL;
serengeti_cpu_poweron =
(int (*)(struct cpu *))modgetsymvalue("sbdp_cpu_poweron", 0);
if (serengeti_cpu_poweron == NULL)
return (ENOTSUP);
else
return ((serengeti_cpu_poweron)(cp));
}
/*ARGSUSED*/
int
plat_cpu_poweroff(struct cpu *cp)
{
int (*serengeti_cpu_poweroff)(struct cpu *) = NULL;
serengeti_cpu_poweroff =
(int (*)(struct cpu *))modgetsymvalue("sbdp_cpu_poweroff", 0);
if (serengeti_cpu_poweroff == NULL)
return (ENOTSUP);
else
return ((serengeti_cpu_poweroff)(cp));
}
#ifdef DEBUG
pgcnt_t serengeti_cage_size_limit;
#endif
/* Preferred minimum cage size (expressed in pages)... for DR */
pgcnt_t serengeti_minimum_cage_size = 0;
void
set_platform_cage_params(void)
{
extern pgcnt_t total_pages;
extern struct memlist *phys_avail;
if (kernel_cage_enable) {
pgcnt_t preferred_cage_size;
preferred_cage_size =
MAX(serengeti_minimum_cage_size, total_pages / 256);
#ifdef DEBUG
if (serengeti_cage_size_limit)
preferred_cage_size = serengeti_cage_size_limit;
#endif
/*
* Post copies obp into the lowest slice. This requires the
* cage to grow upwards
*/
kcage_range_init(phys_avail, KCAGE_UP, preferred_cage_size);
}
kcage_startup_dir = KCAGE_UP;
/* Only note when the cage is off since it should always be on. */
if (!kcage_on)
cmn_err(CE_NOTE, "!DR Kernel Cage is DISABLED");
}
#define ALIGN(x, a) ((a) == 0 ? (uint64_t)(x) : \
(((uint64_t)(x) + (uint64_t)(a) - 1l) & ~((uint64_t)(a) - 1l)))
void
update_mem_bounds(int brd, uint64_t base, uint64_t sz)
{
uint64_t end;
int mnode;
end = base + sz - 1;
/*
* First see if this board already has a memnode associated
* with it. If not, see if this slice has a memnode. This
* covers the cases where a single slice covers multiple
* boards (cross-board interleaving) and where a single
* board has multiple slices (1+GB DIMMs).
*/
if ((mnode = plat_lgrphand_to_mem_node(brd)) == -1) {
if ((mnode = slice_to_memnode[PA_2_SLICE(base)]) == -1)
mnode = mem_node_alloc();
plat_assign_lgrphand_to_mem_node(brd, mnode);
}
/*
* Align base at 16GB boundary
*/
base = ALIGN(base, (1ul << PA_SLICE_SHIFT));
while (base < end) {
slice_to_memnode[PA_2_SLICE(base)] = mnode;
base += (1ul << PA_SLICE_SHIFT);
}
}
/*
* Dynamically detect memory slices in the system by decoding
* the cpu memory decoder registers at boot time.
*/
void
plat_fill_mc(pnode_t nodeid)
{
uint64_t mc_addr, mask;
uint64_t mc_decode[SG_MAX_BANKS_PER_MC];
uint64_t base, size;
uint32_t regs[4];
int len;
int local_mc;
int portid;
int boardid;
int i;
if ((prom_getprop(nodeid, "portid", (caddr_t)&portid) < 0) ||
(portid == -1))
return;
/*
* Decode the board number from the MC portid
*/
boardid = SG_PORTID_TO_BOARD_NUM(portid);
/*
* The "reg" property returns 4 32-bit values. The first two are
* combined to form a 64-bit address. The second two are for a
* 64-bit size, but we don't actually need to look at that value.
*/
len = prom_getproplen(nodeid, "reg");
if (len != (sizeof (uint32_t) * 4)) {
prom_printf("Warning: malformed 'reg' property\n");
return;
}
if (prom_getprop(nodeid, "reg", (caddr_t)regs) < 0)
return;
mc_addr = ((uint64_t)regs[0]) << 32;
mc_addr |= (uint64_t)regs[1];
/*
* Figure out whether the memory controller we are examining
* belongs to this CPU or a different one.
*/
if (portid == cpunodes[CPU->cpu_id].portid)
local_mc = 1;
else
local_mc = 0;
for (i = 0; i < SG_MAX_BANKS_PER_MC; i++) {
mask = SG_REG_2_OFFSET(i);
/*
* If the memory controller is local to this CPU, we use
* the special ASI to read the decode registers.
* Otherwise, we load the values from a magic address in
* I/O space.
*/
if (local_mc)
mc_decode[i] = lddmcdecode(mask & MC_OFFSET_MASK);
else
mc_decode[i] = lddphysio((mc_addr | mask));
if (mc_decode[i] >> MC_VALID_SHIFT) {
/*
* The memory decode register is a bitmask field,
* so we can decode that into both a base and
* a span.
*/
base = MC_BASE(mc_decode[i]) << PHYS2UM_SHIFT;
size = MC_UK2SPAN(mc_decode[i]);
update_mem_bounds(boardid, base, size);
}
}
}
/*
* This routine is run midway through the boot process. By the time we get
* here, we know about all the active CPU boards in the system, and we have
* extracted information about each board's memory from the memory
* controllers. We have also figured out which ranges of memory will be
* assigned to which memnodes, so we walk the slice table to build the table
* of memnodes.
*/
/* ARGSUSED */
void
plat_build_mem_nodes(prom_memlist_t *list, size_t nelems)
{
int slice;
pfn_t basepfn;
pgcnt_t npgs;
mem_node_pfn_shift = PFN_SLICE_SHIFT;
mem_node_physalign = (1ull << PA_SLICE_SHIFT);
for (slice = 0; slice < SG_MAX_SLICE; slice++) {
if (slice_to_memnode[slice] == -1)
continue;
basepfn = (uint64_t)slice << PFN_SLICE_SHIFT;
npgs = 1ull << PFN_SLICE_SHIFT;
mem_node_add_slice(basepfn, basepfn + npgs - 1);
}
}
int
plat_pfn_to_mem_node(pfn_t pfn)
{
int node;
node = slice_to_memnode[PFN_2_SLICE(pfn)];
return (node);
}
/*
* Serengeti support for lgroups.
*
* On Serengeti, an lgroup platform handle == board number.
*
* Mappings between lgroup handles and memnodes are managed
* in addition to mappings between memory slices and memnodes
* to support cross-board interleaving as well as multiple
* slices per board (e.g. >1GB DIMMs). The initial mapping
* of memnodes to lgroup handles is determined at boot time.
* A DR addition of memory adds a new mapping. A DR copy-rename
* swaps mappings.
*/
/*
* Macro for extracting the board number from the CPU id
*/
#define CPUID_TO_BOARD(id) (((id) >> 2) & 0x7)
/*
* Return the platform handle for the lgroup containing the given CPU
*
* For Serengeti, lgroup platform handle == board number
*/
lgrp_handle_t
plat_lgrp_cpu_to_hand(processorid_t id)
{
return (CPUID_TO_BOARD(id));
}
/*
* Platform specific lgroup initialization
*/
void
plat_lgrp_init(void)
{
int i;
extern uint32_t lgrp_expand_proc_thresh;
extern uint32_t lgrp_expand_proc_diff;
/*
* Initialize lookup tables to invalid values so we catch
* any illegal use of them.
*/
for (i = 0; i < SG_MAX_SLICE; i++) {
slice_to_memnode[i] = -1;
}
/*
* Set tuneables for Serengeti architecture
*
* lgrp_expand_proc_thresh is the minimum load on the lgroups
* this process is currently running on before considering
* expanding threads to another lgroup.
*
* lgrp_expand_proc_diff determines how much less the remote lgroup
* must be loaded before expanding to it.
*
* Bandwidth is maximized on Serengeti by spreading load across
* the machine. The impact to inter-thread communication isn't
* too costly since remote latencies are relatively low. These
* values equate to one CPU's load and so attempt to spread the
* load out across as many lgroups as possible one CPU at a time.
*/
lgrp_expand_proc_thresh = LGRP_LOADAVG_THREAD_MAX;
lgrp_expand_proc_diff = LGRP_LOADAVG_THREAD_MAX;
}
/*
* Platform notification of lgroup (re)configuration changes
*/
/*ARGSUSED*/
void
plat_lgrp_config(lgrp_config_flag_t evt, uintptr_t arg)
{
update_membounds_t *umb;
lgrp_config_mem_rename_t lmr;
lgrp_handle_t shand, thand;
int snode, tnode;
switch (evt) {
case LGRP_CONFIG_MEM_ADD:
umb = (update_membounds_t *)arg;
update_mem_bounds(umb->u_board, umb->u_base, umb->u_len);
break;
case LGRP_CONFIG_MEM_DEL:
/* We don't have to do anything */
break;
case LGRP_CONFIG_MEM_RENAME:
/*
* During a DR copy-rename operation, all of the memory
* on one board is moved to another board -- but the
* addresses/pfns and memnodes don't change. This means
* the memory has changed locations without changing identity.
*
* Source is where we are copying from and target is where we
* are copying to. After source memnode is copied to target
* memnode, the physical addresses of the target memnode are
* renamed to match what the source memnode had. Then target
* memnode can be removed and source memnode can take its
* place.
*
* To do this, swap the lgroup handle to memnode mappings for
* the boards, so target lgroup will have source memnode and
* source lgroup will have empty target memnode which is where
* its memory will go (if any is added to it later).
*
* Then source memnode needs to be removed from its lgroup
* and added to the target lgroup where the memory was living
* but under a different name/memnode. The memory was in the
* target memnode and now lives in the source memnode with
* different physical addresses even though it is the same
* memory.
*/
shand = arg & 0xffff;
thand = (arg & 0xffff0000) >> 16;
snode = plat_lgrphand_to_mem_node(shand);
tnode = plat_lgrphand_to_mem_node(thand);
plat_assign_lgrphand_to_mem_node(thand, snode);
plat_assign_lgrphand_to_mem_node(shand, tnode);
/*
* Remove source memnode of copy rename from its lgroup
* and add it to its new target lgroup
*/
lmr.lmem_rename_from = shand;
lmr.lmem_rename_to = thand;
lgrp_config(LGRP_CONFIG_MEM_RENAME, (uintptr_t)snode,
(uintptr_t)&lmr);
break;
default:
break;
}
}
/*
* Return latency between "from" and "to" lgroups
*
* This latency number can only be used for relative comparison
* between lgroups on the running system, cannot be used across platforms,
* and may not reflect the actual latency. It is platform and implementation
* specific, so platform gets to decide its value. It would be nice if the
* number was at least proportional to make comparisons more meaningful though.
* NOTE: The numbers below are supposed to be load latencies for uncached
* memory divided by 10.
*/
int
plat_lgrp_latency(lgrp_handle_t from, lgrp_handle_t to)
{
/*
* Return min remote latency when there are more than two lgroups
* (root and child) and getting latency between two different lgroups
* or root is involved
*/
if (lgrp_optimizations() && (from != to ||
from == LGRP_DEFAULT_HANDLE || to == LGRP_DEFAULT_HANDLE))
return (28);
else
return (23);
}
/* ARGSUSED */
void
plat_freelist_process(int mnode)
{
}
/*
* Find dip for chosen IOSRAM
*/
dev_info_t *
find_chosen_dip(void)
{
dev_info_t *dip;
char master_sbbc[MAXNAMELEN];
int nodeid;
uint_t tunnel;
/*
* find the /chosen SBBC node, prom interface will handle errors
*/
nodeid = prom_chosennode();
/*
* get the 'iosram' property from the /chosen node
*/
if (prom_getprop(nodeid, IOSRAM_CHOSEN_PROP, (caddr_t)&tunnel) <= 0) {
SBBC_ERR(CE_PANIC, "No iosram property found! \n");
}
if (prom_phandle_to_path((phandle_t)tunnel, master_sbbc,
sizeof (master_sbbc)) < 0) {
SBBC_ERR1(CE_PANIC, "prom_phandle_to_path(%d) failed\n",
tunnel);
}
chosen_nodeid = nodeid;
/*
* load and attach the sgsbbc driver.
* This will also attach all the sgsbbc driver instances
*/
if (i_ddi_attach_hw_nodes("sgsbbc") != DDI_SUCCESS) {
cmn_err(CE_WARN, "sgsbbc failed to load\n");
}
/* translate a path name to a dev_info_t */
dip = e_ddi_hold_devi_by_path(master_sbbc, 0);
if ((dip == NULL) || (ddi_get_nodeid(dip) != tunnel)) {
cmn_err(CE_PANIC,
"e_ddi_hold_devi_by_path(%x) failed for SBBC\n", tunnel);
}
/* make sure devi_ref is ZERO */
ndi_rele_devi(dip);
DCMNERR(CE_CONT, "Chosen IOSRAM is at %s \n", master_sbbc);
return (dip);
}
void
load_platform_drivers(void)
{
int ret;
/*
* Load the mc-us3 memory driver.
*/
if (i_ddi_attach_hw_nodes("mc-us3") != DDI_SUCCESS)
cmn_err(CE_WARN, "mc-us3 failed to load");
else
(void) ddi_hold_driver(ddi_name_to_major("mc-us3"));
/*
* Initialize the chosen IOSRAM before its clients
* are loaded.
*/
(void) find_chosen_dip();
/*
* Load the environmentals driver (sgenv)
*
* We need this driver to handle events from the SC when state
* changes occur in the environmental data.
*/
if (i_ddi_attach_hw_nodes("sgenv") != DDI_SUCCESS)
cmn_err(CE_WARN, "sgenv failed to load");
/*
* Ideally, we'd do this in set_platform_defaults(), but
* at that point it's too early to look up symbols.
*/
iosram_write_ptr = (int (*)(int, uint32_t, caddr_t, uint32_t))
modgetsymvalue("iosram_write", 0);
if (iosram_write_ptr == NULL) {
DCMNERR(CE_WARN, "load_platform_defaults: iosram_write()"
" not found; signatures will not be updated\n");
} else {
/*
* The iosram read ptr is only needed if we can actually
* write CPU signatures, so only bother setting it if we
* set a valid write pointer, above.
*/
iosram_read_ptr = (int (*)(int, uint32_t, caddr_t, uint32_t))
modgetsymvalue("iosram_read", 0);
if (iosram_read_ptr == NULL)
DCMNERR(CE_WARN, "load_platform_defaults: iosram_read()"
" not found\n");
}
/*
* Set todsg_use_sc to TRUE so that we will be getting date
* from the SC.
*/
todsg_use_sc = TRUE;
/*
* Now is a good time to activate hardware watchdog (if one exists).
*/
mutex_enter(&tod_lock);
if (watchdog_enable)
ret = tod_ops.tod_set_watchdog_timer(watchdog_timeout_seconds);
mutex_exit(&tod_lock);
if (ret != 0)
printf("Hardware watchdog enabled\n");
plat_ecc_init();
}
/*
* No platform drivers on this platform
*/
char *platform_module_list[] = {
(char *)0
};
/*ARGSUSED*/
void
plat_tod_fault(enum tod_fault_type tod_bad)
{
}
int
plat_max_boards()
{
return (SG_MAX_BDS);
}
int
plat_max_io_units_per_board()
{
return (SG_MAX_IO_PER_BD);
}
int
plat_max_cmp_units_per_board()
{
return (SG_MAX_CMPS_PER_BD);
}
int
plat_max_cpu_units_per_board()
{
return (SG_MAX_CPUS_PER_BD);
}
int
plat_max_mc_units_per_board()
{
return (SG_MAX_CMPS_PER_BD); /* each CPU die has a memory controller */
}
int
plat_max_mem_units_per_board()
{
return (SG_MAX_MEM_PER_BD);
}
int
plat_max_cpumem_boards(void)
{
return (LW8_MAX_CPU_BDS);
}
int
set_platform_max_ncpus(void)
{
return (sg_max_ncpus);
}
void
plat_dmv_params(uint_t *hwint, uint_t *swint)
{
*hwint = MAX_UPA;
*swint = 0;
}
static int (*sg_mbox)(sbbc_msg_t *, sbbc_msg_t *, time_t) = NULL;
/*
* Our nodename has been set, pass it along to the SC.
*/
void
plat_nodename_set(void)
{
sbbc_msg_t req; /* request */
sbbc_msg_t resp; /* response */
int rv; /* return value from call to mbox */
struct nodename_info {
int32_t namelen;
char nodename[_SYS_NMLN];
} nni;
/*
* find the symbol for the mailbox routine
*/
if (sg_mbox == NULL)
sg_mbox = (int (*)(sbbc_msg_t *, sbbc_msg_t *, time_t))
modgetsymvalue("sbbc_mbox_request_response", 0);
if (sg_mbox == NULL) {
cmn_err(CE_NOTE, "!plat_nodename_set: sg_mbox not found\n");
return;
}
/*
* construct the message telling the SC our nodename
*/
(void) strcpy(nni.nodename, utsname.nodename);
nni.namelen = (int32_t)strlen(nni.nodename);
req.msg_type.type = INFO_MBOX;
req.msg_type.sub_type = INFO_MBOX_NODENAME;
req.msg_status = 0;
req.msg_len = (int)(nni.namelen + sizeof (nni.namelen));
req.msg_bytes = 0;
req.msg_buf = (caddr_t)&nni;
req.msg_data[0] = 0;
req.msg_data[1] = 0;
/*
* initialize the response back from the SC
*/
resp.msg_type.type = INFO_MBOX;
resp.msg_type.sub_type = INFO_MBOX_NODENAME;
resp.msg_status = 0;
resp.msg_len = 0;
resp.msg_bytes = 0;
resp.msg_buf = (caddr_t)0;
resp.msg_data[0] = 0;
resp.msg_data[1] = 0;
/*
* ship it and check for success
*/
rv = (sg_mbox)(&req, &resp, sbbc_mbox_default_timeout);
if (rv != 0) {
cmn_err(CE_NOTE, "!plat_nodename_set: sg_mbox retval %d\n", rv);
} else if (resp.msg_status != 0) {
cmn_err(CE_NOTE, "!plat_nodename_set: msg_status %d\n",
resp.msg_status);
} else {
DCMNERR(CE_NOTE, "!plat_nodename_set was successful\n");
/*
* It is necessary to exchange capability the bitmap
* with SC before sending any ecc error information and
* indictment. We are calling the plat_ecc_capability_send()
* here just after sending the nodename successfully.
*/
rv = plat_ecc_capability_send();
if (rv == 0) {
DCMNERR(CE_NOTE, "!plat_ecc_capability_send was"
"successful\n");
}
}
}
/*
* flag to allow users switch between using OBP's
* prom_get_unum() and mc-us3 driver's p2get_mem_unum()
* (for main memory errors only).
*/
int sg_use_prom_get_unum = 0;
/*
* Debugging flag: set to 1 to call into obp for get_unum, or set it to 0
* to call into the unum cache system. This is the E$ equivalent of
* sg_use_prom_get_unum.
*/
int sg_use_prom_ecache_unum = 0;
/* used for logging ECC errors to the SC */
#define SG_MEMORY_ECC 1
#define SG_ECACHE_ECC 2
#define SG_UNKNOWN_ECC (-1)
/*
* plat_get_mem_unum() generates a string identifying either the
* memory or E$ DIMM(s) during error logging. Depending on whether
* the error is E$ or memory related, the appropriate support
* routine is called to assist in the string generation.
*
* - For main memory errors we can use the mc-us3 drivers p2getunum()
* (or prom_get_unum() for debugging purposes).
*
* - For E$ errors we call sg_get_ecacheunum() to generate the unum (or
* prom_serengeti_get_ecacheunum() for debugging purposes).
*/
static int
sg_prom_get_unum(int synd_code, uint64_t paddr, char *buf, int buflen,
int *lenp)
{
if ((prom_get_unum(synd_code, (unsigned long long)paddr,
buf, buflen, lenp)) != 0)
return (EIO);
else if (*lenp <= 1)
return (EINVAL);
else
return (0);
}
/*ARGSUSED*/
int
plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
int flt_in_memory, ushort_t flt_status, char *buf, int buflen, int *lenp)
{
/*
* unum_func will either point to the memory drivers p2get_mem_unum()
* or to prom_get_unum() for memory errors.
*/
int (*unum_func)(int synd_code, uint64_t paddr, char *buf,
int buflen, int *lenp) = p2get_mem_unum;
/*
* check if it's a Memory or an Ecache error.
*/
if (flt_in_memory) {
/*
* It's a main memory error.
*
* For debugging we allow the user to switch between
* using OBP's get_unum and the memory driver's get_unum
* so we create a pointer to the functions and switch
* depending on the sg_use_prom_get_unum flag.
*/
if (sg_use_prom_get_unum) {
DCMNERR(CE_NOTE, "Using prom_get_unum from OBP");
return (sg_prom_get_unum(synd_code,
P2ALIGN(flt_addr, 8), buf, buflen, lenp));
} else if (unum_func != NULL) {
return (unum_func(synd_code, P2ALIGN(flt_addr, 8),
buf, buflen, lenp));
} else {
return (ENOTSUP);
}
} else if (flt_status & ECC_ECACHE) {
/*
* It's an E$ error.
*/
if (sg_use_prom_ecache_unum) {
/*
* We call to OBP to handle this.
*/
DCMNERR(CE_NOTE,
"Using prom_serengeti_get_ecacheunum from OBP");
if (prom_serengeti_get_ecacheunum(flt_bus_id,
P2ALIGN(flt_addr, 8), buf, buflen, lenp) != 0) {
return (EIO);
}
} else {
return (sg_get_ecacheunum(flt_bus_id, flt_addr,
buf, buflen, lenp));
}
} else {
return (ENOTSUP);
}
return (0);
}
/*
* This platform hook gets called from mc_add_mem_unum_label() in the mc-us3
* driver giving each platform the opportunity to add platform
* specific label information to the unum for ECC error logging purposes.
*/
void
plat_add_mem_unum_label(char *unum, int mcid, int bank, int dimm)
{
char new_unum[UNUM_NAMLEN] = "";
int node = SG_PORTID_TO_NODEID(mcid);
int board = SG_CPU_BD_PORTID_TO_BD_NUM(mcid);
int position = SG_PORTID_TO_CPU_POSN(mcid);
/*
* The mc-us3 driver deals with logical banks but for unum
* purposes we need to use physical banks so that the correct
* dimm can be physically located. Logical banks 0 and 2
* make up physical bank 0. Logical banks 1 and 3 make up
* physical bank 1. Here we do the necessary conversion.
*/
bank = (bank % 2);
if (dimm == -1) {
SG_SET_FRU_NAME_NODE(new_unum, node);
SG_SET_FRU_NAME_CPU_BOARD(new_unum, board);
SG_SET_FRU_NAME_MODULE(new_unum, position);
SG_SET_FRU_NAME_BANK(new_unum, bank);
} else {
SG_SET_FRU_NAME_NODE(new_unum, node);
SG_SET_FRU_NAME_CPU_BOARD(new_unum, board);
SG_SET_FRU_NAME_MODULE(new_unum, position);
SG_SET_FRU_NAME_BANK(new_unum, bank);
SG_SET_FRU_NAME_DIMM(new_unum, dimm);
(void) strcat(new_unum, " ");
(void) strcat(new_unum, unum);
}
(void) strcpy(unum, new_unum);
}
int
plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
{
int node = SG_PORTID_TO_NODEID(cpuid);
int board = SG_CPU_BD_PORTID_TO_BD_NUM(cpuid);
if (snprintf(buf, buflen, "/N%d/%s%d", node,
SG_HPU_TYPE_CPU_BOARD_ID, board) >= buflen) {
return (ENOSPC);
} else {
*lenp = strlen(buf);
return (0);
}
}
static void (*sg_ecc_taskq_func)(sbbc_ecc_mbox_t *) = NULL;
static int (*sg_ecc_mbox_func)(sbbc_ecc_mbox_t *) = NULL;
/*
* We log all ECC errors to the SC so we send a mailbox
* message to the SC passing it the relevant data.
* ECC mailbox messages are sent via a taskq mechanism to
* prevent impaired system performance during ECC floods.
* Indictments have already passed through a taskq, so they
* are not queued here.
*/
int
plat_send_ecc_mailbox_msg(plat_ecc_message_type_t msg_type, void *datap)
{
sbbc_ecc_mbox_t *msgp;
uint16_t msg_subtype;
int sleep_flag, log_error;
size_t msg_size;
if (sg_ecc_taskq_func == NULL) {
sg_ecc_taskq_func = (void (*)(sbbc_ecc_mbox_t *))
modgetsymvalue("sbbc_mbox_queue_ecc_event", 0);
if (sg_ecc_taskq_func == NULL) {
cmn_err(CE_NOTE, "!plat_send_ecc_mailbox_msg: "
"sbbc_mbox_queue_ecc_event not found");
return (ENODEV);
}
}
if (sg_ecc_mbox_func == NULL) {
sg_ecc_mbox_func = (int (*)(sbbc_ecc_mbox_t *))
modgetsymvalue("sbbc_mbox_ecc_output", 0);
if (sg_ecc_mbox_func == NULL) {
cmn_err(CE_NOTE, "!plat_send_ecc_mailbox_msg: "
"sbbc_mbox_ecc_output not found");
return (ENODEV);
}
}
/*
* Initialize the request and response structures
*/
switch (msg_type) {
case PLAT_ECC_ERROR_MESSAGE:
msg_subtype = INFO_MBOX_ERROR_ECC;
msg_size = sizeof (plat_ecc_error_data_t);
sleep_flag = KM_NOSLEEP;
log_error = 1;
break;
case PLAT_ECC_ERROR2_MESSAGE:
msg_subtype = INFO_MBOX_ECC;
msg_size = sizeof (plat_ecc_error2_data_t);
sleep_flag = KM_NOSLEEP;
log_error = 1;
break;
case PLAT_ECC_INDICTMENT_MESSAGE:
msg_subtype = INFO_MBOX_ERROR_INDICT;
msg_size = sizeof (plat_ecc_indictment_data_t);
sleep_flag = KM_SLEEP;
log_error = 0;
break;
case PLAT_ECC_INDICTMENT2_MESSAGE:
msg_subtype = INFO_MBOX_ECC;
msg_size = sizeof (plat_ecc_indictment2_data_t);
sleep_flag = KM_SLEEP;
log_error = 0;
break;
case PLAT_ECC_CAPABILITY_MESSAGE:
msg_subtype = INFO_MBOX_ECC_CAP;
msg_size = sizeof (plat_capability_data_t) +
strlen(utsname.release) + strlen(utsname.version) + 2;
sleep_flag = KM_SLEEP;
log_error = 0;
break;
case PLAT_ECC_DIMM_SID_MESSAGE:
msg_subtype = INFO_MBOX_ECC;
msg_size = sizeof (plat_dimm_sid_request_data_t);
sleep_flag = KM_SLEEP;
log_error = 0;
break;
default:
return (EINVAL);
}
msgp = (sbbc_ecc_mbox_t *)kmem_zalloc(sizeof (sbbc_ecc_mbox_t),
sleep_flag);
if (msgp == NULL) {
cmn_err(CE_NOTE, "!plat_send_ecc_mailbox_msg: "
"unable to allocate sbbc_ecc_mbox");
return (ENOMEM);
}
msgp->ecc_log_error = log_error;
msgp->ecc_req.msg_type.type = INFO_MBOX;
msgp->ecc_req.msg_type.sub_type = msg_subtype;
msgp->ecc_req.msg_status = 0;
msgp->ecc_req.msg_len = (int)msg_size;
msgp->ecc_req.msg_bytes = 0;
msgp->ecc_req.msg_buf = (caddr_t)kmem_zalloc(msg_size, sleep_flag);
msgp->ecc_req.msg_data[0] = 0;
msgp->ecc_req.msg_data[1] = 0;
if (msgp->ecc_req.msg_buf == NULL) {
cmn_err(CE_NOTE, "!plat_send_ecc_mailbox_msg: "
"unable to allocate request msg_buf");
kmem_free((void *)msgp, sizeof (sbbc_ecc_mbox_t));
return (ENOMEM);
}
bcopy(datap, (void *)msgp->ecc_req.msg_buf, msg_size);
/*
* initialize the response back from the SC
*/
msgp->ecc_resp.msg_type.type = INFO_MBOX;
msgp->ecc_resp.msg_type.sub_type = msg_subtype;
msgp->ecc_resp.msg_status = 0;
msgp->ecc_resp.msg_len = 0;
msgp->ecc_resp.msg_bytes = 0;
msgp->ecc_resp.msg_buf = NULL;
msgp->ecc_resp.msg_data[0] = 0;
msgp->ecc_resp.msg_data[1] = 0;
switch (msg_type) {
case PLAT_ECC_ERROR_MESSAGE:
case PLAT_ECC_ERROR2_MESSAGE:
/*
* For Error Messages, we go through a taskq.
* Queue up message for processing
*/
(*sg_ecc_taskq_func)(msgp);
return (0);
case PLAT_ECC_CAPABILITY_MESSAGE:
/*
* For indictment and capability messages, we've already gone
* through the taskq, so we can call the mailbox routine
* directly. Find the symbol for the routine that sends
* the mailbox msg
*/
msgp->ecc_resp.msg_len = (int)msg_size;
msgp->ecc_resp.msg_buf = (caddr_t)kmem_zalloc(msg_size,
sleep_flag);
/* FALLTHRU */
case PLAT_ECC_INDICTMENT_MESSAGE:
case PLAT_ECC_INDICTMENT2_MESSAGE:
return ((*sg_ecc_mbox_func)(msgp));
case PLAT_ECC_DIMM_SID_MESSAGE:
msgp->ecc_resp.msg_len = sizeof (plat_dimm_sid_board_data_t);
msgp->ecc_resp.msg_buf = (caddr_t)kmem_zalloc(
sizeof (plat_dimm_sid_board_data_t), sleep_flag);
return ((*sg_ecc_mbox_func)(msgp));
default:
ASSERT(0);
return (EINVAL);
}
}
/*
* m is redundant on serengeti as the multiplyer is always 4
*/
/*ARGSUSED*/
int
plat_make_fru_cpuid(int sb, int m, int proc)
{
return (MAKE_CPUID(sb, proc));
}
/*
* board number for a given proc
*/
int
plat_make_fru_boardnum(int proc)
{
return (SG_PORTID_TO_BOARD_NUM(proc));
}
static
void
cpu_sgn_update(ushort_t sig, uchar_t state, uchar_t sub_state, int cpuid)
{
uint32_t signature = CPU_SIG_BLD(sig, state, sub_state);
sig_state_t current_sgn;
int i;
if (iosram_write_ptr == NULL) {
/*
* If the IOSRAM write pointer isn't set, we won't be able
* to write signatures to ANYTHING, so we may as well just
* write out an error message (if desired) and exit this
* routine now...
*/
DCMNERR(CE_WARN,
"cpu_sgn_update: iosram_write() not found;"
" cannot write signature 0x%x for CPU(s) or domain\n",
signature);
return;
}
/*
* Differentiate a panic reboot from a non-panic reboot in the
* setting of the substate of the signature.
*
* If the new substate is REBOOT and we're rebooting due to a panic,
* then set the new substate to a special value indicating a panic
* reboot, SIGSUBST_PANIC_REBOOT.
*
* A panic reboot is detected by a current (previous) domain signature
* state of SIGST_EXIT, and a new signature substate of SIGSUBST_REBOOT.
* The domain signature state SIGST_EXIT is used as the panic flow
* progresses.
*
* At the end of the panic flow, the reboot occurs but we should now
* one that was involuntary, something that may be quite useful to know
* at OBP level.
*/
if (sub_state == SIGSUBST_REBOOT) {
if (iosram_read_ptr == NULL) {
DCMNERR(CE_WARN,
"cpu_sgn_update: iosram_read() not found;"
" could not check current domain signature\n");
} else {
(void) (*iosram_read_ptr)(SBBC_SIGBLCK_KEY,
SG_SGNBLK_DOMAINSIG_OFFSET,
(char *)¤t_sgn, sizeof (current_sgn));
if (current_sgn.state_t.state == SIGST_EXIT)
signature = CPU_SIG_BLD(sig, state,
SIGSUBST_PANIC_REBOOT);
}
}
/*
* cpuid == -1 indicates that the operation applies to all cpus.
*/
if (cpuid >= 0) {
(void) (*iosram_write_ptr)(SBBC_SIGBLCK_KEY,
SG_SGNBLK_CPUSIG_OFFSET(cpuid), (char *)&signature,
sizeof (signature));
} else {
for (i = 0; i < NCPU; i++) {
if (cpu[i] == NULL || !(cpu[i]->cpu_flags &
(CPU_EXISTS|CPU_QUIESCED))) {
continue;
}
(void) (*iosram_write_ptr)(SBBC_SIGBLCK_KEY,
SG_SGNBLK_CPUSIG_OFFSET(i), (char *)&signature,
sizeof (signature));
}
}
if (state == SIGST_OFFLINE || state == SIGST_DETACHED) {
return;
}
(void) (*iosram_write_ptr)(SBBC_SIGBLCK_KEY,
SG_SGNBLK_DOMAINSIG_OFFSET, (char *)&signature,
sizeof (signature));
}
void
startup_platform(void)
{
}
/*
* A routine to convert a number (represented as a string) to
* the integer value it represents.
*/
static int
isdigit(int ch)
{
return (ch >= '0' && ch <= '9');
}
#define isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
static int
strtoi(char *p, char **pos)
{
int n;
int c, neg = 0;
if (!isdigit(c = *p)) {
while (isspace(c))
c = *++p;
switch (c) {
case '-':
neg++;
/* FALLTHROUGH */
case '+':
c = *++p;
}
if (!isdigit(c)) {
if (pos != NULL)
*pos = p;
return (0);
}
}
for (n = '0' - c; isdigit(c = *++p); ) {
n *= 10; /* two steps to avoid unnecessary overflow */
n += '0' - c; /* accum neg to avoid surprises at MAX */
}
if (pos != NULL)
*pos = p;
return (neg ? n : -n);
}
/*
* Get the three parts of the Serengeti PROM version.
* Used for feature readiness tests.
*
* Return 0 if version extracted successfully, -1 otherwise.
*/
int
sg_get_prom_version(int *sysp, int *intfp, int *bldp)
{
int plen;
char vers[512];
static pnode_t node;
static char version[] = "version";
char *verp, *ep;
node = prom_finddevice("/openprom");
if (node == OBP_BADNODE)
return (-1);
plen = prom_getproplen(node, version);
if (plen <= 0 || plen >= sizeof (vers))
return (-1);
(void) prom_getprop(node, version, vers);
vers[plen] = '\0';
/* Make sure it's an OBP flashprom */
if (vers[0] != 'O' && vers[1] != 'B' && vers[2] != 'P') {
cmn_err(CE_WARN, "sg_get_prom_version: "
"unknown <version> string in </openprom>\n");
return (-1);
}
verp = &vers[4];
*sysp = strtoi(verp, &ep);
if (ep == verp || *ep != '.')
return (-1);
verp = ep + 1;
*intfp = strtoi(verp, &ep);
if (ep == verp || *ep != '.')
return (-1);
verp = ep + 1;
*bldp = strtoi(verp, &ep);
if (ep == verp || (*ep != '\0' && !isspace(*ep)))
return (-1);
return (0);
}
/*
* Return 0 if system board Dynamic Reconfiguration
* is supported by the firmware, -1 otherwise.
*/
int
sg_prom_sb_dr_check(void)
{
static int prom_res = 1;
if (prom_res == 1) {
int sys, intf, bld;
int rv;
rv = sg_get_prom_version(&sys, &intf, &bld);
if (rv == 0 && sys == 5 &&
(intf >= 12 || (intf == 11 && bld >= 200))) {
prom_res = 0;
} else {
prom_res = -1;
}
}
return (prom_res);
}
/*
* Return 0 if cPCI Dynamic Reconfiguration
* is supported by the firmware, -1 otherwise.
*/
int
sg_prom_cpci_dr_check(void)
{
/*
* The version check is currently the same as for
* system boards. Since the two DR sub-systems are
* independent, this could change.
*/
return (sg_prom_sb_dr_check());
}
/*
* Our implementation of this KDI op updates the CPU signature in the system
* controller. Note that we set the signature to OBP_SIG, rather than DBG_SIG.
* The Forth words we execute will, among other things, transform our OBP_SIG
* into DBG_SIG. They won't function properly if we try to use DBG_SIG.
*/
static void
sg_system_claim(void)
{
lbolt_debug_entry();
prom_interpret("sigb-sig! my-sigb-sig!", OBP_SIG, OBP_SIG, 0, 0, 0);
}
static void
sg_system_release(void)
{
prom_interpret("sigb-sig! my-sigb-sig!", OS_SIG, OS_SIG, 0, 0, 0);
lbolt_debug_return();
}
static void
sg_console_claim(void)
{
(void) prom_serengeti_set_console_input(SGCN_OBP_STR);
}
static void
sg_console_release(void)
{
(void) prom_serengeti_set_console_input(SGCN_CLNT_STR);
}
void
plat_kdi_init(kdi_t *kdi)
{
kdi->pkdi_system_claim = sg_system_claim;
kdi->pkdi_system_release = sg_system_release;
kdi->pkdi_console_claim = sg_console_claim;
kdi->pkdi_console_release = sg_console_release;
}
|