8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / uts / sun4u / serengeti / io / sbdp.c
blob3bec42897cff9ab178e73b5d2a5d9c427dc805ab
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <sys/types.h>
28 #include <sys/cmn_err.h>
29 #include <sys/conf.h>
30 #include <sys/ddi_impldefs.h>
31 #include <sys/autoconf.h>
32 #include <sys/systm.h>
33 #include <sys/modctl.h>
34 #include <sys/ddi.h>
35 #include <sys/sunddi.h>
36 #include <sys/sunndi.h>
37 #include <sys/ndi_impldefs.h>
38 #include <sys/promif.h>
39 #include <sys/stat.h>
40 #include <sys/kmem.h>
41 #include <sys/promif.h>
42 #include <sys/conf.h>
43 #include <sys/obpdefs.h>
44 #include <sys/cpuvar.h>
45 #include <vm/seg_kmem.h>
46 #include <sys/prom_plat.h>
47 #include <sys/machsystm.h>
48 #include <sys/note.h>
49 #include <sys/memlist.h>
50 #include <sys/ssm.h>
52 #include <sys/sbd_ioctl.h>
53 #include <sys/sbd.h>
54 #include <sys/sbdp_priv.h>
55 #include <sys/sbdp_mem.h>
56 #include <sys/sbdp_error.h>
57 #include <sys/serengeti.h>
59 #include <sys/sgsbbc.h> /* To get fn_t type definition */
62 * Config information
64 #ifdef DEBUG
65 uint_t sbdp_debug = 0x0;
66 #endif /* DEBUG */
69 * Enable or disable dr
71 int sbdp_dr_available = 1;
73 /* name properties for some Serengeti device nodes */
74 #define CMP_DEVNAME "cmp"
75 #define MEM_DEVNAME "memory"
76 #define CPU_DEVNAME "cpu"
77 #define IO_PCI_DEVNAME "pci"
78 #define IO_SGHSC_DEVNAME "sghsc"
79 #define IO_WCI_DEVNAME "wci"
81 static sbd_devattr_t sbdp_devattr[] = {
82 { CMP_DEVNAME, "cmp", SBD_COMP_CMP },
83 { MEM_DEVNAME, "memory-controller", SBD_COMP_MEM },
84 { CPU_DEVNAME, "cpu", SBD_COMP_CPU },
85 { IO_PCI_DEVNAME, "pci", SBD_COMP_IO },
86 { IO_SGHSC_DEVNAME, "sghsc", SBD_COMP_IO },
87 { IO_WCI_DEVNAME, "wci", SBD_COMP_IO },
88 /* last item must be blank */
89 { NULL, NULL, SBD_COMP_UNKNOWN }
93 * In the case of a busy mbox, if a status cmd comes in we return a cached
94 * copy. This cache is a link list of wnodes that contains bd structs with
95 * the appropriate info. When a new wnode is created a whole entry is added
96 * to the list.
98 sbdp_wnode_t *first_node = NULL; /* first wnode. Entry to the link list */
99 int cur_num_wnodes = 0; /* how many nodes are currently running */
101 /* Macros to access fields in the previous array */
102 #define SBDP_CT(i) sbdp_devattr[i].s_dnodetype
103 #define SBDP_DEVNAME(i) sbdp_devattr[(i)].s_devname
104 #define SBDP_OTYPE(i) sbdp_devattr[(i)].s_obp_type
107 * Prototypes
109 sbdp_wnode_t *sbdp_get_wnodep(int);
112 * Module linkage information for the kernel.
115 static struct modlmisc modlmisc = {
116 &mod_miscops,
117 "Serengeti sbdp",
120 static struct modlinkage modlinkage = {
121 MODREV_1,
122 (void *)&modlmisc,
123 NULL
127 * VA area used during CPU shutdown.
129 caddr_t sbdp_shutdown_va;
132 * Mutex to protect our inventory
134 kmutex_t sbdp_wnode_mutex;
137 _init(void)
139 int e;
141 e = mod_install(&modlinkage);
142 if (e != 0)
143 return (e);
145 sbdp_shutdown_va = vmem_alloc(heap_arena, PAGESIZE, VM_SLEEP);
146 ASSERT(sbdp_shutdown_va != NULL);
147 sbdp_valp = (uint64_t *)vmem_alloc(static_alloc_arena,
148 sizeof (uint64_t), VM_SLEEP);
150 mutex_init(&sbdp_wnode_mutex, NULL, MUTEX_DRIVER, NULL);
151 return (e);
155 _fini(void)
157 int e;
160 * Remove the module.
162 e = mod_remove(&modlinkage);
163 if (e != 0)
164 return (e);
166 vmem_free(heap_arena, sbdp_shutdown_va, PAGESIZE);
167 sbdp_shutdown_va = NULL;
168 vmem_free(static_alloc_arena, (void *)sbdp_valp, sizeof (uint64_t));
169 sbdp_valp = NULL;
171 mutex_destroy(&sbdp_wnode_mutex);
172 return (e);
176 _info(struct modinfo *modinfop)
178 return (mod_info(&modlinkage, modinfop));
182 sbdp_get_bd_and_wnode_num(pnode_t nodeid, int *bd, int *wnode)
184 int portid;
185 static fn_t f = "sbdp_get_bd_and_wnode_num";
186 extern int get_portid(pnode_t node, pnode_t *cmpp);
188 SBDP_DBG_FUNC("%s\n", f);
190 if (sbdp_is_node_bad(nodeid))
191 return (-1);
193 if ((portid = get_portid(nodeid, NULL)) == -1)
194 return (-1);
197 * decode the board number
199 *bd = SG_PORTID_TO_BOARD_NUM(portid);
200 *wnode = SG_PORTID_TO_NODEID(portid);
202 return (0);
206 sbdp_get_board_num(sbdp_handle_t *hp, dev_info_t *dip)
208 _NOTE(ARGUNUSED(hp))
210 pnode_t nodeid;
211 int bd, wnode;
212 static fn_t f = "sbdp_get_board_num";
214 SBDP_DBG_FUNC("%s\n", f);
216 if (dip == NULL)
217 return (-1);
219 nodeid = ddi_get_nodeid(dip);
222 * Portid has encoded the nodeid and the agent id. The top
223 * 4 bits are correspond to the wcnodeid and the lower 5 are the
224 * agent id.
225 * Each agent id represents a physical location hence we can
226 * obtain the board number
228 if (sbdp_get_bd_and_wnode_num(nodeid, &bd, &wnode) < 0)
229 return (-1);
231 return (bd);
235 sbd_devattr_t *
236 sbdp_get_devattr(void)
238 return (&sbdp_devattr[0]);
242 sbdp_portid_to_cpu_unit(int cmp, int core)
244 return (SG_PORTID_TO_CPU_UNIT(cmp, core));
248 sbdp_get_unit_num(sbdp_handle_t *hp, dev_info_t *dip)
250 int unit = -1;
251 int portid;
252 processorid_t cpuid;
253 sbd_comp_type_t type;
254 char dev_type[OBP_MAXPROPNAME];
255 int i;
256 pnode_t nodeid;
257 static fn_t f = "sbdp_get_unit_num";
259 SBDP_DBG_FUNC("%s\n", f);
261 if (dip == NULL)
262 return (-1);
264 nodeid = ddi_get_nodeid(dip);
266 if (sbdp_is_node_bad(nodeid))
267 return (-1);
269 if (prom_getprop(nodeid, "device_type", (caddr_t)dev_type) < 0) {
270 SBDP_DBG_MISC("%s: couldn't get device_type\n", f);
271 return (-1);
274 for (i = 0; SBDP_CT(i) != SBD_COMP_UNKNOWN; i++) {
275 if (strcmp(dev_type, SBDP_OTYPE(i)) != 0)
276 continue;
277 type = SBDP_CT(i);
280 switch (type) {
281 case SBD_COMP_CPU:
282 if ((cpuid = sbdp_get_cpuid(hp, dip)) != -1) {
283 unit = SG_CPUID_TO_CPU_UNIT(cpuid);
285 break;
286 case SBD_COMP_MEM:
287 unit = 0;
288 break;
289 case SBD_COMP_IO: {
290 regspace_t regs[3];
291 int len = 0;
294 * Check to see if this is a cpci node
295 * cpci nodes are assign unit nums of 5 for now
296 * So they don't conflict with the pci unit nums
299 if (strcmp(dev_type, "sghsc") == 0) {
300 SBDP_DBG_MISC("it is a sghsc\n");
301 return (4);
304 if (prom_getprop(nodeid, "portid", (caddr_t)&portid) <= 0) {
305 SBDP_DBG_MISC("%s: couldn't get portid\n", f);
306 return (-1);
309 len = prom_getproplen(nodeid, "reg");
310 if (len <= 0) {
311 SBDP_DBG_MISC("%s: couldn't get length\n", f);
312 return (-1);
315 if (prom_getprop(nodeid, "reg", (caddr_t)regs) < 0) {
316 SBDP_DBG_MISC("%s: couldn't get registers\n", f);
317 return (-1);
320 if ((portid % 2) != 0)
321 if ((regs[0].regspec_addr_lo & 0x700000) ==
322 0x700000)
323 unit = 0;
324 else
325 unit = 1;
326 else
327 if ((regs[0].regspec_addr_lo & 0x700000) ==
328 0x700000)
329 unit = 2;
330 else
331 unit = 3;
333 SBDP_DBG_MISC("unit is %d\n", unit);
334 break;
336 default:
337 break;
341 return (unit);
344 struct sbdp_mem_dip {
345 sbdp_bd_t *bdp;
346 dev_info_t *dip;
349 static int
350 sbdp_get_mem_dip(pnode_t node, void *arg, uint_t flags)
352 _NOTE(ARGUNUSED(flags))
354 struct sbdp_mem_dip *smdp = (struct sbdp_mem_dip *)arg;
355 mem_op_t mem = {0};
357 if (node == OBP_NONODE || node == OBP_BADNODE)
358 return (DDI_FAILURE);
360 mem.nodes = smdp->bdp->nodes;
361 mem.board = smdp->bdp->bd;
362 mem.nmem = smdp->bdp->nnum;
364 (void) sbdp_is_mem(node, &mem);
367 * We need to find the dip only for the first nodeid
369 if (smdp->bdp->nnum == 0 && mem.nmem == 1) {
370 ASSERT(smdp->dip == NULL);
371 smdp->dip = e_ddi_nodeid_to_dip(node);
374 smdp->bdp->nnum = mem.nmem;
376 return (DDI_SUCCESS);
381 * Update the board info. Required after a copy rename
383 void
384 sbdp_update_bd_info(sbdp_bd_t *bdp)
386 attach_pkt_t apkt, *apktp = &apkt;
387 struct sbdp_mem_dip smd = {0};
388 static fn_t f = "sbdp_update_bd_info";
390 SBDP_DBG_FUNC("%s\n", f);
392 if (bdp == NULL) {
393 return;
396 * Grab the lock
398 mutex_enter(&bdp->bd_mutex);
401 * we get the top nodes here. This will have a side effect of
402 * updating the present bit for cpus
404 apktp->node = bdp->wnode;
405 apktp->board = bdp->bd;
406 apktp->num_of_nodes = 0;
407 apktp->flags = 0;
408 sbdp_walk_prom_tree(prom_rootnode(), sbdp_select_top_nodes,
409 (void *) apktp);
412 * We need to clear nnum since we are looking again for the
413 * nodes
415 bdp->nnum = 0;
416 smd.bdp = bdp;
419 * If a dip is found by sbdp_get_mem_dip(), it will be
420 * returned held
422 sbdp_walk_prom_tree(prom_rootnode(), sbdp_get_mem_dip, &smd);
423 if (smd.dip != NULL) {
424 sbdp_handle_t *hp;
426 hp = kmem_zalloc(sizeof (sbdp_handle_t), KM_SLEEP);
427 hp->h_board = bdp->bd;
428 hp->h_wnode = bdp->wnode;
429 hp->h_err = kmem_zalloc(sizeof (*hp->h_err), KM_SLEEP);
430 if (bdp->ml != NULL) {
431 (void) sbdp_del_memlist(hp, bdp->ml);
433 bdp->ml = sbdp_get_memlist(hp, (dev_info_t *)NULL);
435 * if the board doesn't have banks initialize them,
436 * otherwise we assume they have been updated if
437 * necessary
439 if (bdp->banks == NULL) {
440 sbdp_init_bd_banks(bdp);
442 #ifdef DEBUG
443 sbdp_print_bd_banks(bdp);
444 #endif
446 if (sbdphw_get_base_physaddr(hp, smd.dip, &bdp->bpa))
447 bdp->bpa = -1;
448 ddi_release_devi(smd.dip);
449 kmem_free(hp->h_err, sizeof (*hp->h_err));
450 kmem_free(hp, sizeof (sbdp_handle_t));
452 mutex_exit(&bdp->bd_mutex);
456 * Initialize the board struct. This remains cached. We update it
457 * every time we have a successful show_board and after a copy-rename
459 void
460 sbdp_bd_init(sbdp_bd_t *bdp, int bd, int wnode)
462 static fn_t f = "sbdp_bd_init";
464 SBDP_DBG_FUNC("%s\n", f);
466 bdp->bd = bd;
467 bdp->wnode = wnode;
469 SBDP_UNSET_ALL_CPUS_IN_RESET(bdp);
471 bdp->cpus_present = 0;
473 sbdp_update_bd_info(bdp);
475 mutex_init(&bdp->bd_mutex, NULL, MUTEX_DRIVER, NULL);
476 bdp->bd_sc = (show_board_t *)kmem_zalloc(sizeof (show_board_t),
477 KM_SLEEP);
478 bdp->valid_cp = -1;
482 * This entry is going away. Clean up
484 void
485 sbdp_bd_fini(sbdp_bd_t *bdp)
487 static fn_t f = "sbdp_bd_fini";
489 SBDP_DBG_FUNC("%s\n", f);
491 sbdp_cleanup_bd(bdp->wnode, bdp->bd);
492 kmem_free(bdp->bd_sc, sizeof (show_board_t));
493 bdp->bd_sc = NULL;
494 mutex_destroy(&bdp->bd_mutex);
495 #ifdef DEBUG
496 sbdp_print_all_segs();
497 #endif
501 * A new wnode has arrived. Initialize the struct and create
502 * the board structures.
504 void
505 sbdp_wnode_init(sbdp_wnode_t *wnodep, int wnode, int boards)
507 int i;
508 static fn_t f = "sbdp_wnode_init";
510 SBDP_DBG_FUNC("%s\n", f);
512 wnodep->wnode = wnode;
513 wnodep->nbds = boards;
514 wnodep->bds = kmem_zalloc(sizeof (sbdp_bd_t) * boards, KM_SLEEP);
515 wnodep->next = wnodep->prev = NULL;
517 for (i = 0; i < boards; i++)
518 sbdp_bd_init(&wnodep->bds[i], i, wnode);
522 * Wnode got DRed out. Clean up all the node stuff including the boards
524 void
525 sbdp_wnode_fini(sbdp_wnode_t *wnodep)
527 int boards;
528 int i;
529 static fn_t f = "sbdp_wnode_fini";
531 SBDP_DBG_FUNC("%s\n", f);
533 boards = wnodep->nbds;
535 for (i = 0; i < boards; i++)
536 sbdp_bd_fini(&wnodep->bds[i]);
538 kmem_free(wnodep->bds, sizeof (sbdp_bd_t) * boards);
539 wnodep->next = wnodep->prev = NULL;
540 kmem_free(wnodep, sizeof (sbdp_wnode_t));
544 * Add all the necessary fields to this board's struct
546 void
547 sbdp_add_new_bd_info(int wnode, int board)
549 sbdp_wnode_t *cur;
550 static fn_t f = "sbdp_add_new_bd_info";
552 SBDP_DBG_FUNC("%s\n", f);
554 cur = sbdp_get_wnodep(wnode);
556 SBDP_DBG_MISC("adding new board info %d\n", board);
558 sbdp_update_bd_info(&cur->bds[board]);
563 * This board has gone away. Clean the necessary fields
565 void
566 sbdp_cleanup_bd(int wnode, int board)
568 sbdp_wnode_t *cur;
569 sbdp_handle_t handle, *hp;
570 sbdp_bd_t *bdp;
571 int i;
572 static fn_t f = "sbdp_cleanup_bd";
574 SBDP_DBG_FUNC("%s\n", f);
576 cur = sbdp_get_wnodep(wnode);
578 SBDP_DBG_MISC("cleaning up bd info for bd %d\n", board);
579 if (cur == NULL) {
580 SBDP_DBG_MISC("cur is null\n");
581 return;
584 bdp = &cur->bds[board];
587 * Grab the lock
589 mutex_enter(&bdp->bd_mutex);
591 for (i = 0; i < bdp->nnum; i++)
592 bdp->nodes[i] = (pnode_t)0;
593 bdp->nnum = 0;
595 sbdp_fini_bd_banks(bdp);
597 hp = &handle;
598 hp->h_board = bdp->bd;
599 hp->h_wnode = bdp->wnode;
600 if (bdp->ml) {
601 (void) sbdp_del_memlist(hp, bdp->ml);
604 bdp->ml = NULL;
606 bdp->bpa = -1;
608 sbdp_cpu_in_reset(wnode, bdp->bd, SBDP_ALL_CPUS, 0);
610 bdp->cpus_present = 0;
612 mutex_exit(&bdp->bd_mutex);
616 * Traverse the list looking for wnode. Return it when found
618 sbdp_wnode_t *
619 sbdp_get_wnodep(int wnode)
621 sbdp_wnode_t *cur;
622 int i;
623 static fn_t f = "sbdp_get_wnodep";
625 SBDP_DBG_FUNC("%s\n", f);
627 mutex_enter(&sbdp_wnode_mutex);
628 for (i = 0, cur = first_node; i < cur_num_wnodes; i++,
629 cur = cur->next) {
630 if (cur->wnode == wnode) {
631 mutex_exit(&sbdp_wnode_mutex);
632 return (cur);
635 mutex_exit(&sbdp_wnode_mutex);
637 return (NULL);
641 * Insert this brand new node into our master list. It leaves it all
642 * initialized
644 void
645 sbdp_insert_wnode(int wnode, int max_boards)
647 sbdp_wnode_t *wnodep;
648 sbdp_wnode_t *cur;
649 static fn_t f = "sbdp_insert_wnode";
651 SBDP_DBG_FUNC("%s\n", f);
653 wnodep = kmem_zalloc(sizeof (sbdp_wnode_t), KM_SLEEP);
655 mutex_enter(&sbdp_wnode_mutex);
656 if (first_node == NULL) {
657 first_node = wnodep;
658 cur_num_wnodes++;
659 } else {
660 cur = first_node + cur_num_wnodes++;
661 cur->next = wnodep;
662 wnodep->prev = cur;
664 mutex_exit(&sbdp_wnode_mutex);
665 sbdp_wnode_init(wnodep, wnode, max_boards);
669 * This node is gone. Remove it from the list and also clean up
671 void
672 sbdp_remove_wnode(sbdp_wnode_t *wnodep)
674 sbdp_wnode_t *cur;
675 static fn_t f = "sbdp_remove_wnode";
677 SBDP_DBG_FUNC("%s\n", f);
679 if (wnodep != NULL) {
680 sbdp_wnode_fini(wnodep);
681 mutex_enter(&sbdp_wnode_mutex);
683 if (first_node == wnodep)
684 first_node = NULL;
685 else {
686 cur = wnodep->prev;
687 if (cur != NULL)
688 cur->next = wnodep->next;
689 if (wnodep->next != NULL)
690 wnodep->next->prev = cur;
693 cur_num_wnodes--;
694 mutex_exit(&sbdp_wnode_mutex);
699 * Entry point from sbd. This is called when a new node is added. We
700 * create an entry in our inventory and initialize all the stuff that will be
701 * needed
704 sbdp_setup_instance(caddr_t arg)
706 ssm_sbdp_info_t *sbdp_info;
707 int instance;
708 int wnode;
709 int max_boards;
710 static fn_t f = "sbdp_setup_instance";
712 SBDP_DBG_FUNC("%s\n", f);
715 * We get this directly from ssm
717 sbdp_info = (ssm_sbdp_info_t *)arg;
719 instance = sbdp_info->instance;
720 wnode = sbdp_info->wnode;
721 max_boards = plat_max_boards();
723 SBDP_DBG_MISC("sbdp_setup_instance: instance %d wnode %d\n", instance,
724 sbdp_info->wnode);
726 if (sbdp_get_wnodep(wnode) == NULL) {
728 * This node has not been instanstiated
729 * create one
731 sbdp_insert_wnode(wnode, max_boards);
734 return (DDI_SUCCESS);
738 * Entry point from sbd. This is called when a node has been removed (or is
739 * going away. We do all the necessary cleanup
742 sbdp_teardown_instance(caddr_t arg)
744 ssm_sbdp_info_t *sbdp_info;
745 int instance;
746 int wnode;
747 sbdp_wnode_t *wnodep;
748 static fn_t f = "sbdp_teardown_instance";
750 SBDP_DBG_FUNC("%s\n", f);
753 * ssm should have set this up
755 sbdp_info = (ssm_sbdp_info_t *)arg;
757 instance = sbdp_info->instance;
758 wnode = sbdp_info->wnode;
760 SBDP_DBG_MISC("sbdp_teardown_instance: instance %d wnode %d\n",
761 instance, wnode);
764 * Find this node and then remove it
766 if ((wnodep = sbdp_get_wnodep(wnode)) != NULL) {
767 sbdp_remove_wnode(wnodep);
769 return (DDI_SUCCESS);
773 sbdp_disabled_component(sbdp_handle_t *hp)
775 #ifdef lint
776 hp = hp;
777 #endif
778 return (0);
781 /* ARGSUSED */
783 sbdp_release_component(sbdp_handle_t *hp, dev_info_t *dip)
785 return (0);
788 void
789 sbdp_set_err(sbd_error_t *ep, int ecode, char *rsc)
791 static fn_t f = "sbdp_set_err";
793 SBDP_DBG_FUNC("%s\n", f);
794 ASSERT(ep != NULL);
795 ep->e_code = ecode;
797 if (rsc != NULL) {
798 (void) strcpy((caddr_t)(ep->e_rsc), (caddr_t)rsc);
803 * Serengeti DR passthrus are for debugging purposes only.
805 static struct {
806 const char *name;
807 int (*handler)(sbdp_handle_t *, void *);
808 } sbdp_passthrus[] = {
809 #ifdef DEBUG
810 { "readmem", sbdp_passthru_readmem },
811 { "prep-script", sbdp_passthru_prep_script },
812 { "test-quiesce", sbdp_passthru_test_quiesce },
813 { "inject-error", sbdp_passthru_inject_error },
814 { "reset-error", sbdp_passthru_reset_error },
815 #endif
817 /* the following line must always be last */
818 { NULL, NULL }
822 /*ARGSUSED*/
824 sbdp_ioctl(sbdp_handle_t *hp, sbdp_ioctl_arg_t *sbdpi)
826 #ifdef DEBUG
827 char buf[512];
828 int rv;
829 sbd_ioctl_arg_t *sbdi = (sbd_ioctl_arg_t *)sbdpi->h_iap;
830 int i;
831 static fn_t f = "sbdp_ioctl";
833 SBDP_DBG_FUNC("%s\n", f);
835 if (sbdi->i_len >= sizeof (buf) ||
836 ddi_copyin(sbdi->i_opts, buf, sbdi->i_len, sbdpi->h_mode)) {
837 sbdp_set_err(hp->h_err, ESBD_FAULT, NULL);
838 return (-1);
841 i = 0;
842 while (sbdp_passthrus[i].name != NULL) {
843 int len;
845 len = strlen(sbdp_passthrus[i].name);
846 if (strncmp(sbdp_passthrus[i].name, buf, len) == 0)
847 break;
848 i++;
851 if (sbdp_passthrus[i].name == NULL) {
852 sbdp_set_err(hp->h_err, ESBD_INVAL, NULL);
853 rv = EIO;
854 } else {
855 rv = (*sbdp_passthrus[i].handler)(hp, buf);
856 if (rv != ESBD_NOERROR) {
857 sbdp_set_err(hp->h_err, rv, NULL);
858 rv = EIO;
863 return (rv);
864 #else
865 return (0);
866 #endif
870 * Check the dnode we obtained. Need to find a better way to determine
871 * if the node has the correct starting address
874 sbdp_is_node_bad(pnode_t node)
876 static fn_t f = "sbdp_is_node_bad";
878 SBDP_DBG_FUNC("%s\n", f);
880 return ((node == OBP_NONODE) || (node == OBP_BADNODE) ||
881 ((node & 0x80000000u) != 0x80000000u));
885 * Retrieve the information we have on this board from
886 * the inventory
888 sbdp_bd_t *
889 sbdp_get_bd_info(int wnode, int board)
891 sbdp_wnode_t *wnodep;
892 sbdp_bd_t *bdp;
893 int max_bds;
894 static fn_t f = "sbdp_get_bd_info";
896 SBDP_DBG_FUNC("%s\n", f);
898 wnodep = sbdp_get_wnodep(wnode);
899 max_bds = plat_max_boards();
901 if ((wnodep == NULL) || ((board < 0) && (board > max_bds))) {
902 return (NULL);
905 bdp = &wnodep->bds[board];
908 * We might not have the complete bd info. With cheetah we
909 * cannot access the memory decode registers when then cpu is
910 * in reset. If the mem info is incomplete, then we try to gather it
911 * here
913 sbdp_update_bd_info(bdp);
915 return (bdp);
919 * There are certain cases where obp marks components as failed
920 * If the status is ok the node won't have any status property. It
921 * is only there if the status is other than ok.
923 sbd_cond_t
924 sbdp_get_comp_status(pnode_t nodeid)
926 char status_buf[OBP_MAXPROPNAME];
927 static const char *status = "status";
928 static const char *failed = "fail";
929 static const char *disabled = "disabled";
930 static fn_t f = "sbdp_get_comp_status";
932 SBDP_DBG_FUNC("%s\n", f);
934 if (sbdp_is_node_bad(nodeid)) {
935 SBDP_DBG_STATE("node is not ok\n");
936 return (SBD_COND_UNKNOWN);
939 if (prom_getproplen(nodeid, (char *)status) <= 0) {
940 SBDP_DBG_STATE("status is ok\n");
941 return (SBD_COND_OK);
944 if (prom_getprop(nodeid, (char *)status, status_buf) < 0) {
945 SBDP_DBG_STATE("status is unknown\n");
946 return (SBD_COND_UNKNOWN);
949 if (strncmp(status_buf, failed, strlen(failed)) == 0) {
950 SBDP_DBG_STATE("status of failed\n");
951 return (SBD_COND_FAILED);
954 if (strcmp(status_buf, disabled) == 0) {
955 SBDP_DBG_STATE("status of unusable\n");
956 return (SBD_COND_UNUSABLE);
959 return (SBD_COND_OK);
962 void
963 sbdp_cpu_in_reset(int node, int bd, int unit, int reset)
965 sbdp_wnode_t *cur;
966 sbdp_bd_t *bdp;
967 static fn_t f = "sbdp_cpu_in_reset";
969 SBDP_DBG_FUNC("%s\n", f);
971 if ((unit < -1) || (bd < 0) || (node < 0)) {
972 return;
975 cur = sbdp_get_wnodep(node);
977 SBDP_DBG_MISC("marking cpu %d %s for board %d\n", unit,
978 (reset) ? "in reset" : "out of reset", bd);
980 if (cur == NULL) {
981 return;
984 bdp = &cur->bds[bd];
986 if (unit == SBDP_ALL_CPUS)
987 if (reset == 1)
988 SBDP_SET_ALL_CPUS_IN_RESET(bdp);
989 else
990 SBDP_UNSET_ALL_CPUS_IN_RESET(bdp);
991 else
992 if (reset == 1)
993 SBDP_SET_CPU_IN_RESET(bdp, unit);
994 else
995 SBDP_UNSET_CPU_IN_RESET(bdp, unit);
999 sbdp_set_cpu_present(int node, int bd, int unit)
1001 sbdp_wnode_t *cur;
1002 sbdp_bd_t *bdp;
1003 static fn_t f = "sbdp_set_cpu_present";
1005 SBDP_DBG_FUNC("%s\n", f);
1007 if ((unit < 0) || (bd < 0) || (node < 0)) {
1008 return (-1);
1011 cur = sbdp_get_wnodep(node);
1012 if (cur == NULL) {
1013 return (-1);
1016 bdp = &cur->bds[bd];
1018 SBDP_SET_CPU_PRESENT(bdp, unit);
1020 return (0);
1024 sbdp_is_cpu_present(int node, int bd, int unit)
1026 sbdp_wnode_t *cur;
1027 sbdp_bd_t *bdp;
1028 static fn_t f = "sbdp_is_cpu_present";
1030 SBDP_DBG_FUNC("%s\n", f);
1032 if ((unit < 0) || (bd < 0) || (node < 0)) {
1033 return (-1);
1036 cur = sbdp_get_wnodep(node);
1037 if (cur == NULL) {
1038 return (-1);
1041 bdp = &cur->bds[bd];
1043 return (SBDP_IS_CPU_PRESENT(bdp, unit));
1047 sbdp_is_cpu_in_reset(int node, int bd, int unit)
1049 sbdp_wnode_t *cur;
1050 sbdp_bd_t *bdp;
1051 static fn_t f = "sbdp_is_cpu_in_reset";
1053 SBDP_DBG_FUNC("%s\n", f);
1055 if ((unit < 0) || (bd < 0) || (node < 0)) {
1056 return (-1);
1059 cur = sbdp_get_wnodep(node);
1061 if (cur == NULL) {
1062 return (-1);
1065 bdp = &cur->bds[bd];
1067 return (SBDP_IS_CPU_IN_RESET(bdp, unit));
1071 sbdp_dr_avail(void)
1073 static fn_t f = "sbdp_dr_avail";
1075 SBDP_DBG_FUNC("%s\n", f);
1077 if (sbdp_dr_available)
1078 if (sg_prom_sb_dr_check() == 0)
1079 return (1);
1080 return (0);