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
|
/*
* 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/types.h>
#include <sys/cmn_err.h>
#include <sys/conf.h>
#include <sys/ddi_impldefs.h>
#include <sys/autoconf.h>
#include <sys/systm.h>
#include <sys/modctl.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/sunndi.h>
#include <sys/ndi_impldefs.h>
#include <sys/promif.h>
#include <sys/stat.h>
#include <sys/kmem.h>
#include <sys/promif.h>
#include <sys/conf.h>
#include <sys/obpdefs.h>
#include <sys/cpuvar.h>
#include <vm/seg_kmem.h>
#include <sys/prom_plat.h>
#include <sys/machsystm.h>
#include <sys/note.h>
#include <sys/memlist.h>
#include <sys/ssm.h>
#include <sys/sbd_ioctl.h>
#include <sys/sbd.h>
#include <sys/sbdp_priv.h>
#include <sys/sbdp_mem.h>
#include <sys/sbdp_error.h>
#include <sys/serengeti.h>
#include <sys/sgsbbc.h> /* To get fn_t type definition */
/*
* Config information
*/
#ifdef DEBUG
uint_t sbdp_debug = 0x0;
#endif /* DEBUG */
/*
* Enable or disable dr
*/
int sbdp_dr_available = 1;
/* name properties for some Serengeti device nodes */
#define CMP_DEVNAME "cmp"
#define MEM_DEVNAME "memory"
#define CPU_DEVNAME "cpu"
#define IO_PCI_DEVNAME "pci"
#define IO_SGHSC_DEVNAME "sghsc"
#define IO_WCI_DEVNAME "wci"
static sbd_devattr_t sbdp_devattr[] = {
{ CMP_DEVNAME, "cmp", SBD_COMP_CMP },
{ MEM_DEVNAME, "memory-controller", SBD_COMP_MEM },
{ CPU_DEVNAME, "cpu", SBD_COMP_CPU },
{ IO_PCI_DEVNAME, "pci", SBD_COMP_IO },
{ IO_SGHSC_DEVNAME, "sghsc", SBD_COMP_IO },
{ IO_WCI_DEVNAME, "wci", SBD_COMP_IO },
/* last item must be blank */
{ NULL, NULL, SBD_COMP_UNKNOWN }
};
/*
* In the case of a busy mbox, if a status cmd comes in we return a cached
* copy. This cache is a link list of wnodes that contains bd structs with
* the appropriate info. When a new wnode is created a whole entry is added
* to the list.
*/
sbdp_wnode_t *first_node = NULL; /* first wnode. Entry to the link list */
int cur_num_wnodes = 0; /* how many nodes are currently running */
/* Macros to access fields in the previous array */
#define SBDP_CT(i) sbdp_devattr[i].s_dnodetype
#define SBDP_DEVNAME(i) sbdp_devattr[(i)].s_devname
#define SBDP_OTYPE(i) sbdp_devattr[(i)].s_obp_type
/*
* Prototypes
*/
sbdp_wnode_t *sbdp_get_wnodep(int);
/*
* Module linkage information for the kernel.
*/
static struct modlmisc modlmisc = {
&mod_miscops,
"Serengeti sbdp",
};
static struct modlinkage modlinkage = {
MODREV_1,
(void *)&modlmisc,
NULL
};
/*
* VA area used during CPU shutdown.
*/
caddr_t sbdp_shutdown_va;
/*
* Mutex to protect our inventory
*/
kmutex_t sbdp_wnode_mutex;
int
_init(void)
{
int e;
e = mod_install(&modlinkage);
if (e != 0)
return (e);
sbdp_shutdown_va = vmem_alloc(heap_arena, PAGESIZE, VM_SLEEP);
ASSERT(sbdp_shutdown_va != NULL);
sbdp_valp = (uint64_t *)vmem_alloc(static_alloc_arena,
sizeof (uint64_t), VM_SLEEP);
mutex_init(&sbdp_wnode_mutex, NULL, MUTEX_DRIVER, NULL);
return (e);
}
int
_fini(void)
{
int e;
/*
* Remove the module.
*/
e = mod_remove(&modlinkage);
if (e != 0)
return (e);
vmem_free(heap_arena, sbdp_shutdown_va, PAGESIZE);
sbdp_shutdown_va = NULL;
vmem_free(static_alloc_arena, (void *)sbdp_valp, sizeof (uint64_t));
sbdp_valp = NULL;
mutex_destroy(&sbdp_wnode_mutex);
return (e);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
int
sbdp_get_bd_and_wnode_num(pnode_t nodeid, int *bd, int *wnode)
{
int portid;
static fn_t f = "sbdp_get_bd_and_wnode_num";
extern int get_portid(pnode_t node, pnode_t *cmpp);
SBDP_DBG_FUNC("%s\n", f);
if (sbdp_is_node_bad(nodeid))
return (-1);
if ((portid = get_portid(nodeid, NULL)) == -1)
return (-1);
/*
* decode the board number
*/
*bd = SG_PORTID_TO_BOARD_NUM(portid);
*wnode = SG_PORTID_TO_NODEID(portid);
return (0);
}
int
sbdp_get_board_num(sbdp_handle_t *hp, dev_info_t *dip)
{
_NOTE(ARGUNUSED(hp))
pnode_t nodeid;
int bd, wnode;
static fn_t f = "sbdp_get_board_num";
SBDP_DBG_FUNC("%s\n", f);
if (dip == NULL)
return (-1);
nodeid = ddi_get_nodeid(dip);
/*
* Portid has encoded the nodeid and the agent id. The top
* 4 bits are correspond to the wcnodeid and the lower 5 are the
* agent id.
* Each agent id represents a physical location hence we can
* obtain the board number
*/
if (sbdp_get_bd_and_wnode_num(nodeid, &bd, &wnode) < 0)
return (-1);
return (bd);
}
sbd_devattr_t *
sbdp_get_devattr(void)
{
return (&sbdp_devattr[0]);
}
int
sbdp_portid_to_cpu_unit(int cmp, int core)
{
return (SG_PORTID_TO_CPU_UNIT(cmp, core));
}
int
sbdp_get_unit_num(sbdp_handle_t *hp, dev_info_t *dip)
{
int unit = -1;
int portid;
processorid_t cpuid;
sbd_comp_type_t type;
char dev_type[OBP_MAXPROPNAME];
int i;
pnode_t nodeid;
static fn_t f = "sbdp_get_unit_num";
SBDP_DBG_FUNC("%s\n", f);
if (dip == NULL)
return (-1);
nodeid = ddi_get_nodeid(dip);
if (sbdp_is_node_bad(nodeid))
return (-1);
if (prom_getprop(nodeid, "device_type", (caddr_t)dev_type) < 0) {
SBDP_DBG_MISC("%s: couldn't get device_type\n", f);
return (-1);
}
for (i = 0; SBDP_CT(i) != SBD_COMP_UNKNOWN; i++) {
if (strcmp(dev_type, SBDP_OTYPE(i)) != 0)
continue;
type = SBDP_CT(i);
}
switch (type) {
case SBD_COMP_CPU:
if ((cpuid = sbdp_get_cpuid(hp, dip)) != -1) {
unit = SG_CPUID_TO_CPU_UNIT(cpuid);
}
break;
case SBD_COMP_MEM:
unit = 0;
break;
case SBD_COMP_IO: {
regspace_t regs[3];
int len = 0;
/*
* Check to see if this is a cpci node
* cpci nodes are assign unit nums of 5 for now
* So they don't conflict with the pci unit nums
*/
if (strcmp(dev_type, "sghsc") == 0) {
SBDP_DBG_MISC("it is a sghsc\n");
return (4);
}
if (prom_getprop(nodeid, "portid", (caddr_t)&portid) <= 0) {
SBDP_DBG_MISC("%s: couldn't get portid\n", f);
return (-1);
}
len = prom_getproplen(nodeid, "reg");
if (len <= 0) {
SBDP_DBG_MISC("%s: couldn't get length\n", f);
return (-1);
}
if (prom_getprop(nodeid, "reg", (caddr_t)regs) < 0) {
SBDP_DBG_MISC("%s: couldn't get registers\n", f);
return (-1);
}
if ((portid % 2) != 0)
if ((regs[0].regspec_addr_lo & 0x700000) ==
0x700000)
unit = 0;
else
unit = 1;
else
if ((regs[0].regspec_addr_lo & 0x700000) ==
0x700000)
unit = 2;
else
unit = 3;
SBDP_DBG_MISC("unit is %d\n", unit);
break;
}
default:
break;
}
return (unit);
}
struct sbdp_mem_dip {
sbdp_bd_t *bdp;
dev_info_t *dip;
};
static int
sbdp_get_mem_dip(pnode_t node, void *arg, uint_t flags)
{
_NOTE(ARGUNUSED(flags))
struct sbdp_mem_dip *smdp = (struct sbdp_mem_dip *)arg;
mem_op_t mem = {0};
if (node == OBP_NONODE || node == OBP_BADNODE)
return (DDI_FAILURE);
mem.nodes = smdp->bdp->nodes;
mem.board = smdp->bdp->bd;
mem.nmem = smdp->bdp->nnum;
(void) sbdp_is_mem(node, &mem);
/*
* We need to find the dip only for the first nodeid
*/
if (smdp->bdp->nnum == 0 && mem.nmem == 1) {
ASSERT(smdp->dip == NULL);
smdp->dip = e_ddi_nodeid_to_dip(node);
}
smdp->bdp->nnum = mem.nmem;
return (DDI_SUCCESS);
}
/*
* Update the board info. Required after a copy rename
*/
void
sbdp_update_bd_info(sbdp_bd_t *bdp)
{
attach_pkt_t apkt, *apktp = &apkt;
struct sbdp_mem_dip smd = {0};
static fn_t f = "sbdp_update_bd_info";
SBDP_DBG_FUNC("%s\n", f);
if (bdp == NULL) {
return;
}
/*
* Grab the lock
*/
mutex_enter(&bdp->bd_mutex);
/*
* we get the top nodes here. This will have a side effect of
* updating the present bit for cpus
*/
apktp->node = bdp->wnode;
apktp->board = bdp->bd;
apktp->num_of_nodes = 0;
apktp->flags = 0;
sbdp_walk_prom_tree(prom_rootnode(), sbdp_select_top_nodes,
(void *) apktp);
/*
* We need to clear nnum since we are looking again for the
* nodes
*/
bdp->nnum = 0;
smd.bdp = bdp;
/*
* If a dip is found by sbdp_get_mem_dip(), it will be
* returned held
*/
sbdp_walk_prom_tree(prom_rootnode(), sbdp_get_mem_dip, &smd);
if (smd.dip != NULL) {
sbdp_handle_t *hp;
hp = kmem_zalloc(sizeof (sbdp_handle_t), KM_SLEEP);
hp->h_board = bdp->bd;
hp->h_wnode = bdp->wnode;
hp->h_err = kmem_zalloc(sizeof (*hp->h_err), KM_SLEEP);
if (bdp->ml != NULL) {
(void) sbdp_del_memlist(hp, bdp->ml);
}
bdp->ml = sbdp_get_memlist(hp, (dev_info_t *)NULL);
/*
* if the board doesn't have banks initialize them,
* otherwise we assume they have been updated if
* necessary
*/
if (bdp->banks == NULL) {
sbdp_init_bd_banks(bdp);
}
#ifdef DEBUG
sbdp_print_bd_banks(bdp);
#endif
if (sbdphw_get_base_physaddr(hp, smd.dip, &bdp->bpa))
bdp->bpa = -1;
ddi_release_devi(smd.dip);
kmem_free(hp->h_err, sizeof (*hp->h_err));
kmem_free(hp, sizeof (sbdp_handle_t));
}
mutex_exit(&bdp->bd_mutex);
}
/*
* Initialize the board struct. This remains cached. We update it
* every time we have a successful show_board and after a copy-rename
*/
void
sbdp_bd_init(sbdp_bd_t *bdp, int bd, int wnode)
{
static fn_t f = "sbdp_bd_init";
SBDP_DBG_FUNC("%s\n", f);
bdp->bd = bd;
bdp->wnode = wnode;
SBDP_UNSET_ALL_CPUS_IN_RESET(bdp);
bdp->cpus_present = 0;
sbdp_update_bd_info(bdp);
mutex_init(&bdp->bd_mutex, NULL, MUTEX_DRIVER, NULL);
bdp->bd_sc = (show_board_t *)kmem_zalloc(sizeof (show_board_t),
KM_SLEEP);
bdp->valid_cp = -1;
}
/*
* This entry is going away. Clean up
*/
void
sbdp_bd_fini(sbdp_bd_t *bdp)
{
static fn_t f = "sbdp_bd_fini";
SBDP_DBG_FUNC("%s\n", f);
sbdp_cleanup_bd(bdp->wnode, bdp->bd);
kmem_free(bdp->bd_sc, sizeof (show_board_t));
bdp->bd_sc = NULL;
mutex_destroy(&bdp->bd_mutex);
#ifdef DEBUG
sbdp_print_all_segs();
#endif
}
/*
* A new wnode has arrived. Initialize the struct and create
* the board structures.
*/
void
sbdp_wnode_init(sbdp_wnode_t *wnodep, int wnode, int boards)
{
int i;
static fn_t f = "sbdp_wnode_init";
SBDP_DBG_FUNC("%s\n", f);
wnodep->wnode = wnode;
wnodep->nbds = boards;
wnodep->bds = kmem_zalloc(sizeof (sbdp_bd_t) * boards, KM_SLEEP);
wnodep->next = wnodep->prev = NULL;
for (i = 0; i < boards; i++)
sbdp_bd_init(&wnodep->bds[i], i, wnode);
}
/*
* Wnode got DRed out. Clean up all the node stuff including the boards
*/
void
sbdp_wnode_fini(sbdp_wnode_t *wnodep)
{
int boards;
int i;
static fn_t f = "sbdp_wnode_fini";
SBDP_DBG_FUNC("%s\n", f);
boards = wnodep->nbds;
for (i = 0; i < boards; i++)
sbdp_bd_fini(&wnodep->bds[i]);
kmem_free(wnodep->bds, sizeof (sbdp_bd_t) * boards);
wnodep->next = wnodep->prev = NULL;
kmem_free(wnodep, sizeof (sbdp_wnode_t));
}
/*
* Add all the necessary fields to this board's struct
*/
void
sbdp_add_new_bd_info(int wnode, int board)
{
sbdp_wnode_t *cur;
static fn_t f = "sbdp_add_new_bd_info";
SBDP_DBG_FUNC("%s\n", f);
cur = sbdp_get_wnodep(wnode);
SBDP_DBG_MISC("adding new board info %d\n", board);
sbdp_update_bd_info(&cur->bds[board]);
}
/*
* This board has gone away. Clean the necessary fields
*/
void
sbdp_cleanup_bd(int wnode, int board)
{
sbdp_wnode_t *cur;
sbdp_handle_t handle, *hp;
sbdp_bd_t *bdp;
int i;
static fn_t f = "sbdp_cleanup_bd";
SBDP_DBG_FUNC("%s\n", f);
cur = sbdp_get_wnodep(wnode);
SBDP_DBG_MISC("cleaning up bd info for bd %d\n", board);
if (cur == NULL) {
SBDP_DBG_MISC("cur is null\n");
return;
}
bdp = &cur->bds[board];
/*
* Grab the lock
*/
mutex_enter(&bdp->bd_mutex);
for (i = 0; i < bdp->nnum; i++)
bdp->nodes[i] = (pnode_t)0;
bdp->nnum = 0;
sbdp_fini_bd_banks(bdp);
hp = &handle;
hp->h_board = bdp->bd;
hp->h_wnode = bdp->wnode;
if (bdp->ml) {
(void) sbdp_del_memlist(hp, bdp->ml);
}
bdp->ml = NULL;
bdp->bpa = -1;
sbdp_cpu_in_reset(wnode, bdp->bd, SBDP_ALL_CPUS, 0);
bdp->cpus_present = 0;
mutex_exit(&bdp->bd_mutex);
}
/*
* Traverse the list looking for wnode. Return it when found
*/
sbdp_wnode_t *
sbdp_get_wnodep(int wnode)
{
sbdp_wnode_t *cur;
int i;
static fn_t f = "sbdp_get_wnodep";
SBDP_DBG_FUNC("%s\n", f);
mutex_enter(&sbdp_wnode_mutex);
for (i = 0, cur = first_node; i < cur_num_wnodes; i++,
cur = cur->next) {
if (cur->wnode == wnode) {
mutex_exit(&sbdp_wnode_mutex);
return (cur);
}
}
mutex_exit(&sbdp_wnode_mutex);
return (NULL);
}
/*
* Insert this brand new node into our master list. It leaves it all
* initialized
*/
void
sbdp_insert_wnode(int wnode, int max_boards)
{
sbdp_wnode_t *wnodep;
sbdp_wnode_t *cur;
static fn_t f = "sbdp_insert_wnode";
SBDP_DBG_FUNC("%s\n", f);
wnodep = kmem_zalloc(sizeof (sbdp_wnode_t), KM_SLEEP);
mutex_enter(&sbdp_wnode_mutex);
if (first_node == NULL) {
first_node = wnodep;
cur_num_wnodes++;
} else {
cur = first_node + cur_num_wnodes++;
cur->next = wnodep;
wnodep->prev = cur;
}
mutex_exit(&sbdp_wnode_mutex);
sbdp_wnode_init(wnodep, wnode, max_boards);
}
/*
* This node is gone. Remove it from the list and also clean up
*/
void
sbdp_remove_wnode(sbdp_wnode_t *wnodep)
{
sbdp_wnode_t *cur;
static fn_t f = "sbdp_remove_wnode";
SBDP_DBG_FUNC("%s\n", f);
if (wnodep != NULL) {
sbdp_wnode_fini(wnodep);
mutex_enter(&sbdp_wnode_mutex);
if (first_node == wnodep)
first_node = NULL;
else {
cur = wnodep->prev;
if (cur != NULL)
cur->next = wnodep->next;
if (wnodep->next != NULL)
wnodep->next->prev = cur;
}
cur_num_wnodes--;
mutex_exit(&sbdp_wnode_mutex);
}
}
/*
* Entry point from sbd. This is called when a new node is added. We
* create an entry in our inventory and initialize all the stuff that will be
* needed
*/
int
sbdp_setup_instance(caddr_t arg)
{
ssm_sbdp_info_t *sbdp_info;
int instance;
int wnode;
int max_boards;
static fn_t f = "sbdp_setup_instance";
SBDP_DBG_FUNC("%s\n", f);
/*
* We get this directly from ssm
*/
sbdp_info = (ssm_sbdp_info_t *)arg;
instance = sbdp_info->instance;
wnode = sbdp_info->wnode;
max_boards = plat_max_boards();
SBDP_DBG_MISC("sbdp_setup_instance: instance %d wnode %d\n", instance,
sbdp_info->wnode);
if (sbdp_get_wnodep(wnode) == NULL) {
/*
* This node has not been instanstiated
* create one
*/
sbdp_insert_wnode(wnode, max_boards);
}
return (DDI_SUCCESS);
}
/*
* Entry point from sbd. This is called when a node has been removed (or is
* going away. We do all the necessary cleanup
*/
int
sbdp_teardown_instance(caddr_t arg)
{
ssm_sbdp_info_t *sbdp_info;
int instance;
int wnode;
sbdp_wnode_t *wnodep;
static fn_t f = "sbdp_teardown_instance";
SBDP_DBG_FUNC("%s\n", f);
/*
* ssm should have set this up
*/
sbdp_info = (ssm_sbdp_info_t *)arg;
instance = sbdp_info->instance;
wnode = sbdp_info->wnode;
SBDP_DBG_MISC("sbdp_teardown_instance: instance %d wnode %d\n",
instance, wnode);
/*
* Find this node and then remove it
*/
if ((wnodep = sbdp_get_wnodep(wnode)) != NULL) {
sbdp_remove_wnode(wnodep);
}
return (DDI_SUCCESS);
}
int
sbdp_disabled_component(sbdp_handle_t *hp)
{
#ifdef lint
hp = hp;
#endif
return (0);
}
/* ARGSUSED */
int
sbdp_release_component(sbdp_handle_t *hp, dev_info_t *dip)
{
return (0);
}
void
sbdp_set_err(sbd_error_t *ep, int ecode, char *rsc)
{
static fn_t f = "sbdp_set_err";
SBDP_DBG_FUNC("%s\n", f);
ASSERT(ep != NULL);
ep->e_code = ecode;
if (rsc != NULL) {
(void) strcpy((caddr_t)(ep->e_rsc), (caddr_t)rsc);
}
}
/*
* Serengeti DR passthrus are for debugging purposes only.
*/
static struct {
const char *name;
int (*handler)(sbdp_handle_t *, void *);
} sbdp_passthrus[] = {
#ifdef DEBUG
{ "readmem", sbdp_passthru_readmem },
{ "prep-script", sbdp_passthru_prep_script },
{ "test-quiesce", sbdp_passthru_test_quiesce },
{ "inject-error", sbdp_passthru_inject_error },
{ "reset-error", sbdp_passthru_reset_error },
#endif
/* the following line must always be last */
{ NULL, NULL }
};
/*ARGSUSED*/
int
sbdp_ioctl(sbdp_handle_t *hp, sbdp_ioctl_arg_t *sbdpi)
{
#ifdef DEBUG
char buf[512];
int rv;
sbd_ioctl_arg_t *sbdi = (sbd_ioctl_arg_t *)sbdpi->h_iap;
int i;
static fn_t f = "sbdp_ioctl";
SBDP_DBG_FUNC("%s\n", f);
if (sbdi->i_len >= sizeof (buf) ||
ddi_copyin(sbdi->i_opts, buf, sbdi->i_len, sbdpi->h_mode)) {
sbdp_set_err(hp->h_err, ESBD_FAULT, NULL);
return (-1);
}
i = 0;
while (sbdp_passthrus[i].name != NULL) {
int len;
len = strlen(sbdp_passthrus[i].name);
if (strncmp(sbdp_passthrus[i].name, buf, len) == 0)
break;
i++;
}
if (sbdp_passthrus[i].name == NULL) {
sbdp_set_err(hp->h_err, ESBD_INVAL, NULL);
rv = EIO;
} else {
rv = (*sbdp_passthrus[i].handler)(hp, buf);
if (rv != ESBD_NOERROR) {
sbdp_set_err(hp->h_err, rv, NULL);
rv = EIO;
}
}
return (rv);
#else
return (0);
#endif
}
/*
* Check the dnode we obtained. Need to find a better way to determine
* if the node has the correct starting address
*/
int
sbdp_is_node_bad(pnode_t node)
{
static fn_t f = "sbdp_is_node_bad";
SBDP_DBG_FUNC("%s\n", f);
return ((node == OBP_NONODE) || (node == OBP_BADNODE) ||
((node & 0x80000000u) != 0x80000000u));
}
/*
* Retrieve the information we have on this board from
* the inventory
*/
sbdp_bd_t *
sbdp_get_bd_info(int wnode, int board)
{
sbdp_wnode_t *wnodep;
sbdp_bd_t *bdp;
int max_bds;
static fn_t f = "sbdp_get_bd_info";
SBDP_DBG_FUNC("%s\n", f);
wnodep = sbdp_get_wnodep(wnode);
max_bds = plat_max_boards();
if ((wnodep == NULL) || ((board < 0) && (board > max_bds))) {
return (NULL);
}
bdp = &wnodep->bds[board];
/*
* We might not have the complete bd info. With cheetah we
* cannot access the memory decode registers when then cpu is
* in reset. If the mem info is incomplete, then we try to gather it
* here
*/
sbdp_update_bd_info(bdp);
return (bdp);
}
/*
* There are certain cases where obp marks components as failed
* If the status is ok the node won't have any status property. It
* is only there if the status is other than ok.
*/
sbd_cond_t
sbdp_get_comp_status(pnode_t nodeid)
{
char status_buf[OBP_MAXPROPNAME];
static const char *status = "status";
static const char *failed = "fail";
static const char *disabled = "disabled";
static fn_t f = "sbdp_get_comp_status";
SBDP_DBG_FUNC("%s\n", f);
if (sbdp_is_node_bad(nodeid)) {
SBDP_DBG_STATE("node is not ok\n");
return (SBD_COND_UNKNOWN);
}
if (prom_getproplen(nodeid, (char *)status) <= 0) {
SBDP_DBG_STATE("status is ok\n");
return (SBD_COND_OK);
}
if (prom_getprop(nodeid, (char *)status, status_buf) < 0) {
SBDP_DBG_STATE("status is unknown\n");
return (SBD_COND_UNKNOWN);
}
if (strncmp(status_buf, failed, strlen(failed)) == 0) {
SBDP_DBG_STATE("status of failed\n");
return (SBD_COND_FAILED);
}
if (strcmp(status_buf, disabled) == 0) {
SBDP_DBG_STATE("status of unusable\n");
return (SBD_COND_UNUSABLE);
}
return (SBD_COND_OK);
}
void
sbdp_cpu_in_reset(int node, int bd, int unit, int reset)
{
sbdp_wnode_t *cur;
sbdp_bd_t *bdp;
static fn_t f = "sbdp_cpu_in_reset";
SBDP_DBG_FUNC("%s\n", f);
if ((unit < -1) || (bd < 0) || (node < 0)) {
return;
}
cur = sbdp_get_wnodep(node);
SBDP_DBG_MISC("marking cpu %d %s for board %d\n", unit,
(reset) ? "in reset" : "out of reset", bd);
if (cur == NULL) {
return;
}
bdp = &cur->bds[bd];
if (unit == SBDP_ALL_CPUS)
if (reset == 1)
SBDP_SET_ALL_CPUS_IN_RESET(bdp);
else
SBDP_UNSET_ALL_CPUS_IN_RESET(bdp);
else
if (reset == 1)
SBDP_SET_CPU_IN_RESET(bdp, unit);
else
SBDP_UNSET_CPU_IN_RESET(bdp, unit);
}
int
sbdp_set_cpu_present(int node, int bd, int unit)
{
sbdp_wnode_t *cur;
sbdp_bd_t *bdp;
static fn_t f = "sbdp_set_cpu_present";
SBDP_DBG_FUNC("%s\n", f);
if ((unit < 0) || (bd < 0) || (node < 0)) {
return (-1);
}
cur = sbdp_get_wnodep(node);
if (cur == NULL) {
return (-1);
}
bdp = &cur->bds[bd];
SBDP_SET_CPU_PRESENT(bdp, unit);
return (0);
}
int
sbdp_is_cpu_present(int node, int bd, int unit)
{
sbdp_wnode_t *cur;
sbdp_bd_t *bdp;
static fn_t f = "sbdp_is_cpu_present";
SBDP_DBG_FUNC("%s\n", f);
if ((unit < 0) || (bd < 0) || (node < 0)) {
return (-1);
}
cur = sbdp_get_wnodep(node);
if (cur == NULL) {
return (-1);
}
bdp = &cur->bds[bd];
return (SBDP_IS_CPU_PRESENT(bdp, unit));
}
int
sbdp_is_cpu_in_reset(int node, int bd, int unit)
{
sbdp_wnode_t *cur;
sbdp_bd_t *bdp;
static fn_t f = "sbdp_is_cpu_in_reset";
SBDP_DBG_FUNC("%s\n", f);
if ((unit < 0) || (bd < 0) || (node < 0)) {
return (-1);
}
cur = sbdp_get_wnodep(node);
if (cur == NULL) {
return (-1);
}
bdp = &cur->bds[bd];
return (SBDP_IS_CPU_IN_RESET(bdp, unit));
}
int
sbdp_dr_avail(void)
{
static fn_t f = "sbdp_dr_avail";
SBDP_DBG_FUNC("%s\n", f);
if (sbdp_dr_available)
if (sg_prom_sb_dr_check() == 0)
return (1);
return (0);
}
|