xref: /illumos-gate/usr/src/psm/promif/ieee1275/common/prom_test.c (revision 2a8d6eba033e4713ab12b61178f0513f1f075482)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/promif.h>
29 #include <sys/promimpl.h>
30 
31 /*
32  * Test for existance of a specific P1275 client interface service
33  */
34 int
35 prom_test(char *service)
36 {
37 	cell_t ci[5];
38 
39 	ci[0] = p1275_ptr2cell("test");		/* Service name */
40 	ci[1] = (cell_t)1;			/* #argument cells */
41 	ci[2] = (cell_t)1;			/* #result cells */
42 	ci[3] = p1275_ptr2cell(service);	/* Arg1: requested svc name */
43 	ci[4] = (cell_t)-1;			/* Res1: Prime result */
44 
45 	promif_preprom();
46 	(void) p1275_cif_handler(&ci);
47 	promif_postprom();
48 
49 	return (p1275_cell2int(ci[4]));		/* Res1: missing flag */
50 }
51 
52 int
53 prom_test_method(char *method, pnode_t node)
54 {
55 	cell_t ci[6];
56 	int rv;
57 	char buf[80];
58 
59 	if (prom_test("test-method") == 0) {
60 		ci[0] = p1275_ptr2cell("test-method");	/* service */
61 		ci[1] = (cell_t)2;			/* #argument cells */
62 		ci[2] = (cell_t)1;			/* #result cells */
63 		ci[3] = p1275_dnode2cell(node);
64 		ci[4] = p1275_ptr2cell(method);
65 		ci[5] = (cell_t)-1;
66 
67 		promif_preprom();
68 		(void) p1275_cif_handler(&ci);
69 		promif_postprom();
70 		rv = p1275_cell2int(ci[5]);
71 	} else {
72 		(void) prom_sprintf(buf,
73 		    "\" %s\" h# %x find-method invert h# %p l!",
74 		    method, node, (void *)&rv);
75 		prom_interpret(buf, 0, 0, 0, 0, 0);
76 	}
77 	return (rv);
78 }
79