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 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * PICL plug-in that creates device tree nodes for all platforms
28 */
29
30 #include <stdio.h>
31 #include <string.h>
32 #include <ctype.h>
33 #include <limits.h>
34 #include <stdlib.h>
35 #include <assert.h>
36 #include <alloca.h>
37 #include <unistd.h>
38 #include <stropts.h>
39 #include <syslog.h>
40 #include <libdevinfo.h>
41 #include <sys/dkio.h>
42 #include <sys/vtoc.h>
43 #include <sys/time.h>
44 #include <fcntl.h>
45 #include <picl.h>
46 #include <picltree.h>
1753 check_stale_node(di_node_t node, void *arg)
1754 {
1755 di_prom_prop_t promp;
1756
1757 errno = 0;
1758 promp = di_prom_prop_next(ph, node, DI_PROM_PROP_NIL);
1759 if (promp == DI_PROM_PROP_NIL && errno == EINVAL) {
1760 snapshot_stale = 1;
1761 return (DI_WALK_TERMINATE);
1762 }
1763 return (DI_WALK_CONTINUE);
1764 }
1765
1766 /*
1767 * Walk the snapshot and check the OBP properties of each node.
1768 */
1769 static int
1770 is_snapshot_stale(di_node_t root)
1771 {
1772 snapshot_stale = 0;
1773 di_walk_node(root, DI_WALK_CLDFIRST, NULL, check_stale_node);
1774 return (snapshot_stale);
1775 }
1776
1777 /*
1778 * This function processes the data from libdevinfo and creates nodes
1779 * in the PICL tree.
1780 */
1781 static int
1782 libdevinfo_init(picl_nodehdl_t rooth)
1783 {
1784 di_node_t di_root;
1785 picl_nodehdl_t plafh;
1786 picl_nodehdl_t obph;
1787 int err;
1788
1789 /*
1790 * Use DINFOCACHE so that we obtain all attributes for all
1791 * device instances (without necessarily doing a load/attach
1792 * of all drivers). Once the (on-disk) cache file is built, it
1793 * exists over a reboot and can be read into memory at a very
2529 opp = (struct openpromio *)malloc(sizeof (struct openpromio) +
2530 listsize);
2531 if (opp == NULL) {
2532 (void) close(d);
2533 return (0);
2534 }
2535 (void) memset(opp, '\0', sizeof (struct openpromio) + listsize);
2536 opp->oprom_size = listsize;
2537 if (ioctl(d, OPROMEXPORT, opp) == -1) {
2538 free(opp);
2539 (void) close(d);
2540 return (0);
2541 }
2542 *exportlist = malloc(listsize);
2543 if (*exportlist == NULL) {
2544 free(opp);
2545 (void) close(d);
2546 return (0);
2547 }
2548 (void) memcpy(*exportlist, opp->oprom_array, opp->oprom_size);
2549 free(opp);
2550 *exportlistlen = opp->oprom_size;
2551 (void) close(d);
2552 return (1);
2553 }
2554
2555 /*
2556 * Parses properties string, fills in triplet structure with first
2557 * type, name, val triplet and returns pointer to next property.
2558 * Returns NULL if no valid triplet found
2559 * CAUTION: drops \0 characters over separator characters: if you
2560 * want to parse the string twice, you'll have to take a copy.
2561 */
2562 static char *
2563 parse_props_string(char *props, asr_prop_triplet_t *triplet)
2564 {
2565 char *prop_name;
2566 char *prop_val;
2567 char *prop_next;
2568
2569 prop_name = strchr(props, '?');
2570 if (prop_name == NULL)
|
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 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Copyright (c) 2018, Joyent, Inc.
28 */
29
30 /*
31 * PICL plug-in that creates device tree nodes for all platforms
32 */
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <ctype.h>
37 #include <limits.h>
38 #include <stdlib.h>
39 #include <assert.h>
40 #include <alloca.h>
41 #include <unistd.h>
42 #include <stropts.h>
43 #include <syslog.h>
44 #include <libdevinfo.h>
45 #include <sys/dkio.h>
46 #include <sys/vtoc.h>
47 #include <sys/time.h>
48 #include <fcntl.h>
49 #include <picl.h>
50 #include <picltree.h>
1757 check_stale_node(di_node_t node, void *arg)
1758 {
1759 di_prom_prop_t promp;
1760
1761 errno = 0;
1762 promp = di_prom_prop_next(ph, node, DI_PROM_PROP_NIL);
1763 if (promp == DI_PROM_PROP_NIL && errno == EINVAL) {
1764 snapshot_stale = 1;
1765 return (DI_WALK_TERMINATE);
1766 }
1767 return (DI_WALK_CONTINUE);
1768 }
1769
1770 /*
1771 * Walk the snapshot and check the OBP properties of each node.
1772 */
1773 static int
1774 is_snapshot_stale(di_node_t root)
1775 {
1776 snapshot_stale = 0;
1777 (void) di_walk_node(root, DI_WALK_CLDFIRST, NULL, check_stale_node);
1778 return (snapshot_stale);
1779 }
1780
1781 /*
1782 * This function processes the data from libdevinfo and creates nodes
1783 * in the PICL tree.
1784 */
1785 static int
1786 libdevinfo_init(picl_nodehdl_t rooth)
1787 {
1788 di_node_t di_root;
1789 picl_nodehdl_t plafh;
1790 picl_nodehdl_t obph;
1791 int err;
1792
1793 /*
1794 * Use DINFOCACHE so that we obtain all attributes for all
1795 * device instances (without necessarily doing a load/attach
1796 * of all drivers). Once the (on-disk) cache file is built, it
1797 * exists over a reboot and can be read into memory at a very
2533 opp = (struct openpromio *)malloc(sizeof (struct openpromio) +
2534 listsize);
2535 if (opp == NULL) {
2536 (void) close(d);
2537 return (0);
2538 }
2539 (void) memset(opp, '\0', sizeof (struct openpromio) + listsize);
2540 opp->oprom_size = listsize;
2541 if (ioctl(d, OPROMEXPORT, opp) == -1) {
2542 free(opp);
2543 (void) close(d);
2544 return (0);
2545 }
2546 *exportlist = malloc(listsize);
2547 if (*exportlist == NULL) {
2548 free(opp);
2549 (void) close(d);
2550 return (0);
2551 }
2552 (void) memcpy(*exportlist, opp->oprom_array, opp->oprom_size);
2553 *exportlistlen = opp->oprom_size;
2554 free(opp);
2555 (void) close(d);
2556 return (1);
2557 }
2558
2559 /*
2560 * Parses properties string, fills in triplet structure with first
2561 * type, name, val triplet and returns pointer to next property.
2562 * Returns NULL if no valid triplet found
2563 * CAUTION: drops \0 characters over separator characters: if you
2564 * want to parse the string twice, you'll have to take a copy.
2565 */
2566 static char *
2567 parse_props_string(char *props, asr_prop_triplet_t *triplet)
2568 {
2569 char *prop_name;
2570 char *prop_val;
2571 char *prop_next;
2572
2573 prop_name = strchr(props, '?');
2574 if (prop_name == NULL)
|