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
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
|
#
# 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.
#
PROG= prtconf
include ../Makefile.cmd
SUBDIRS += $(MACH64)
all : TARGET = all
install : TARGET = install
clean : TARGET = clean
clobber : TARGET = clobber
lint : TARGET = lint
# Hammerhead: /etc/prtconf → ../sbin/prtconf
RELUSRSBIN= ../sbin
ROOTSYMLINK= $(ROOTETC)/$(PROG)
FILEMODE= 0555
.KEEP_STATE:
all: $(SUBDIRS)
$(ROOTSYMLINK):
-$(RM) $@; $(SYMLINK) $(RELUSRSBIN)/$(PROG) $@
clean clobber lint: $(SUBDIRS)
install: $(SUBDIRS) $(ROOTSYMLINK)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
include ../Makefile.targ
#
# 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.
#
PROG= prtconf
OBJS= $(PROG).o pdevinfo.o prt_xxx.o
SRCS= $(OBJS:%.o=../%.c)
include ../../Makefile.cmd
CFLAGS += $(CCVERBOSE)
LDLIBS += -ldevinfo -lnvpair -lpcidb
FILEMODE= 02555
CLEANFILES += $(OBJS)
.KEEP_STATE:
all: $(PROG)
$(PROG): $(OBJS)
$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
$(POST_PROCESS)
lint: lint_SRCS
%.o: ../%.c
$(COMPILE.c) $<
clean:
$(RM) $(CLEANFILES)
include ../../Makefile.targ
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (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 2004 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
include ../Makefile.com
include ../../Makefile.cmd.64
# Hammerhead: Install to /sbin with /usr/sbin compat symlink
ROOTUSRSBINLINKS = $(PROG:%=$(ROOTUSRSBIN)/%)
install: all $(ROOTSBINPROG) $(ROOTUSRSBINLINKS)
$(ROOTUSRSBINLINKS):
-$(RM) $@; $(SYMLINK) ../../sbin/$(@F) $@
/*
* 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.
*/
/*
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/
/*
* Copyright (c) 2019 Peter Tribble.
* Copyright 2022 Oxide Computer Company
*/
/*
* For machines that support the openprom, fetch and print the list
* of devices that the kernel has fetched from the prom or conjured up.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <fcntl.h>
#include <ctype.h>
#include <strings.h>
#include <unistd.h>
#include <stropts.h>
#include <sys/types.h>
#include <sys/mkdev.h>
#include <sys/sunddi.h>
#include <sys/openpromio.h>
#include <sys/modctl.h>
#include <sys/stat.h>
#include <zone.h>
#include <libnvpair.h>
#include <err.h>
#include <upanic.h>
#include "prtconf.h"
typedef char *(*dump_propname_t)(void *);
typedef int (*dump_proptype_t)(void *);
typedef int (*dump_propints_t)(void *, int **);
typedef int (*dump_propint64_t)(void *, int64_t **);
typedef int (*dump_propstrings_t)(void *, char **);
typedef int (*dump_propbytes_t)(void *, uchar_t **);
typedef int (*dump_proprawdata_t)(void *, uchar_t **);
typedef struct dumpops_common {
dump_propname_t doc_propname;
dump_proptype_t doc_proptype;
dump_propints_t doc_propints;
dump_propint64_t doc_propint64;
dump_propstrings_t doc_propstrings;
dump_propbytes_t doc_propbytes;
dump_proprawdata_t doc_proprawdata;
} dumpops_common_t;
static const dumpops_common_t prop_dumpops = {
(dump_propname_t)di_prop_name,
(dump_proptype_t)di_prop_type,
(dump_propints_t)di_prop_ints,
(dump_propint64_t)di_prop_int64,
(dump_propstrings_t)di_prop_strings,
(dump_propbytes_t)di_prop_bytes,
(dump_proprawdata_t)di_prop_rawdata
}, pathprop_common_dumpops = {
(dump_propname_t)di_path_prop_name,
(dump_proptype_t)di_path_prop_type,
(dump_propints_t)di_path_prop_ints,
(dump_propint64_t)di_path_prop_int64s,
(dump_propstrings_t)di_path_prop_strings,
(dump_propbytes_t)di_path_prop_bytes,
(dump_proprawdata_t)di_path_prop_bytes
};
typedef void *(*dump_nextprop_t)(void *, void *);
typedef dev_t (*dump_propdevt_t)(void *);
typedef struct dumpops {
const dumpops_common_t *dop_common;
dump_nextprop_t dop_nextprop;
dump_propdevt_t dop_propdevt;
} dumpops_t;
typedef struct di_args {
di_prom_handle_t prom_hdl;
di_devlink_handle_t devlink_hdl;
} di_arg_t;
static const dumpops_t sysprop_dumpops = {
&prop_dumpops,
(dump_nextprop_t)di_prop_sys_next,
NULL
}, globprop_dumpops = {
&prop_dumpops,
(dump_nextprop_t)di_prop_global_next,
NULL
}, drvprop_dumpops = {
&prop_dumpops,
(dump_nextprop_t)di_prop_drv_next,
(dump_propdevt_t)di_prop_devt
}, hwprop_dumpops = {
&prop_dumpops,
(dump_nextprop_t)di_prop_hw_next,
NULL
}, pathprop_dumpops = {
&pathprop_common_dumpops,
(dump_nextprop_t)di_path_prop_next,
NULL
};
#define PROPNAME(ops) (ops->dop_common->doc_propname)
#define PROPTYPE(ops) (ops->dop_common->doc_proptype)
#define PROPINTS(ops) (ops->dop_common->doc_propints)
#define PROPINT64(ops) (ops->dop_common->doc_propint64)
#define PROPSTRINGS(ops) (ops->dop_common->doc_propstrings)
#define PROPBYTES(ops) (ops->dop_common->doc_propbytes)
#define PROPRAWDATA(ops) (ops->dop_common->doc_proprawdata)
#define NEXTPROP(ops) (ops->dop_nextprop)
#define PROPDEVT(ops) (ops->dop_propdevt)
#define NUM_ELEMENTS(A) (sizeof (A) / sizeof (A[0]))
static int prop_type_guess(const dumpops_t *, void *, void **, int *);
static void walk_driver(di_node_t, di_arg_t *);
static int dump_devs(di_node_t, void *);
static int dump_prop_list(const dumpops_t *, const char *,
int, void *, dev_t, int *);
static int is_openprom();
static void walk(uchar_t *, uint_t, int);
static void dump_node(nvlist_t *, int);
static void dump_prodinfo(di_prom_handle_t, di_node_t, const char **,
char *, int);
static di_node_t find_node_by_name(di_prom_handle_t, di_node_t, char *);
static int get_propval_by_name(di_prom_handle_t, di_node_t,
const char *, uchar_t **);
static int dump_compatible(char *, int, di_node_t);
static void dump_pathing_data(int, di_node_t);
static void dump_minor_data(int, di_node_t, di_devlink_handle_t);
static void dump_link_data(int, di_node_t, di_devlink_handle_t);
static int print_composite_string(const char *, char *, int);
static void print_one(nvpair_t *, int);
static int unprintable(char *, int);
static int promopen(int);
static void promclose();
static di_node_t find_target_node(di_node_t);
static void node_display_private_set(di_node_t);
static int node_display_set(di_node_t, void *);
static void dump_pciid(char *, int, di_node_t);
void
prtconf_devinfo(void)
{
struct di_priv_data fetch;
di_arg_t di_arg;
di_prom_handle_t prom_hdl = DI_PROM_HANDLE_NIL;
di_devlink_handle_t devlink_hdl = NULL;
di_node_t root_node;
uint_t flag;
char *rootpath;
dbgprintf("verbosemode %s\n", opts.o_verbose ? "on" : "off");
/* determine what info we need to get from kernel */
flag = DINFOSUBTREE;
rootpath = "/";
if (opts.o_target) {
flag |= (DINFOMINOR | DINFOPATH);
}
if (opts.o_pciid) {
flag |= DINFOPROP;
if ((prom_hdl = di_prom_init()) == DI_PROM_HANDLE_NIL)
err(-1, "di_prom_init() failed.");
}
if (opts.o_forcecache) {
if (dbg.d_forceload) {
warnx("option combination not supported");
}
if (strcmp(rootpath, "/") != 0) {
errx(-1, "invalid root path for option");
}
flag = DINFOCACHE;
} else if (opts.o_verbose) {
flag |= (DINFOPROP | DINFOMINOR |
DINFOPRIVDATA | DINFOPATH | DINFOLYR);
}
if (dbg.d_forceload) {
flag |= DINFOFORCE;
}
if (opts.o_verbose) {
init_priv_data(&fetch);
root_node = di_init_impl(rootpath, flag, &fetch);
/* get devlink (aka aliases) data */
if ((devlink_hdl = di_devlink_init(NULL, 0)) == NULL)
err(-1, "di_devlink_init() failed.");
} else
root_node = di_init(rootpath, flag);
if (root_node == DI_NODE_NIL) {
warnx("devinfo facility not available");
/* not an error if this isn't the global zone */
if (getzoneid() == GLOBAL_ZONEID)
exit(-1);
else
exit(0);
}
di_arg.prom_hdl = prom_hdl;
di_arg.devlink_hdl = devlink_hdl;
/*
* ...and walk all nodes to report them out...
*/
if (dbg.d_bydriver) {
opts.o_target = 0;
walk_driver(root_node, &di_arg);
if (prom_hdl != DI_PROM_HANDLE_NIL)
di_prom_fini(prom_hdl);
if (devlink_hdl != NULL)
(void) di_devlink_fini(&devlink_hdl);
di_fini(root_node);
return;
}
if (opts.o_target) {
di_node_t target_node, node;
target_node = find_target_node(root_node);
if (target_node == DI_NODE_NIL) {
(void) fprintf(stderr, "%s: "
"invalid device path specified\n",
opts.o_progname);
exit(1);
}
/* mark the target node so we display it */
node_display_private_set(target_node);
if (opts.o_ancestors) {
/*
* mark the ancestors of this node so we display
* them as well
*/
node = target_node;
while ((node = di_parent_node(node)) != DI_NODE_NIL)
node_display_private_set(node);
} else {
/*
* when we display device tree nodes the indentation
* level is based off of tree depth.
*
* here we increment o_target to reflect the
* depth of the target node in the tree. we do
* this so that when we calculate the indentation
* level we can subtract o_target so that the
* target node starts with an indentation of zero.
*/
node = target_node;
while ((node = di_parent_node(node)) != DI_NODE_NIL)
opts.o_target++;
}
if (opts.o_children) {
/*
* mark the children of this node so we display
* them as well
*/
(void) di_walk_node(target_node, DI_WALK_CLDFIRST,
(void *)1, node_display_set);
}
}
(void) di_walk_node(root_node, DI_WALK_CLDFIRST, &di_arg,
dump_devs);
if (prom_hdl != DI_PROM_HANDLE_NIL)
di_prom_fini(prom_hdl);
if (devlink_hdl != NULL)
(void) di_devlink_fini(&devlink_hdl);
di_fini(root_node);
}
/*
* utility routines
*/
static int
i_find_target_node(di_node_t node, void *arg)
{
di_node_t *target = (di_node_t *)arg;
if (opts.o_devices_path != NULL) {
char *path;
if ((path = di_devfs_path(node)) == NULL)
err(-1, "failed to allocate memory");
if (strcmp(opts.o_devices_path, path) == 0) {
di_devfs_path_free(path);
*target = node;
return (DI_WALK_TERMINATE);
}
di_devfs_path_free(path);
} else if (opts.o_devt != DDI_DEV_T_NONE) {
di_minor_t minor = DI_MINOR_NIL;
while ((minor = di_minor_next(node, minor)) != DI_MINOR_NIL) {
if (opts.o_devt == di_minor_devt(minor)) {
*target = node;
return (DI_WALK_TERMINATE);
}
}
} else {
/* we should never get here */
const char *msg = "internal error";
upanic(msg, strlen(msg));
}
return (DI_WALK_CONTINUE);
}
static di_node_t
find_target_node(di_node_t root_node)
{
di_node_t target = DI_NODE_NIL;
/* special case to allow displaying of the root node */
if (opts.o_devices_path != NULL) {
if (strlen(opts.o_devices_path) == 0)
return (root_node);
if (strcmp(opts.o_devices_path, ".") == 0)
return (root_node);
}
(void) di_walk_node(root_node, DI_WALK_CLDFIRST, &target,
i_find_target_node);
return (target);
}
#define NODE_DISPLAY (1<<0)
static long
node_display(di_node_t node)
{
long data = (long)di_node_private_get(node);
return (data & NODE_DISPLAY);
}
static void
node_display_private_set(di_node_t node)
{
long data = (long)di_node_private_get(node);
data |= NODE_DISPLAY;
di_node_private_set(node, (void *)data);
}
static int
node_display_set(di_node_t node, void *arg __unused)
{
node_display_private_set(node);
return (0);
}
#define LNODE_DISPLAYED (1<<0)
static long
lnode_displayed(di_lnode_t lnode)
{
long data = (long)di_lnode_private_get(lnode);
return (data & LNODE_DISPLAYED);
}
static void
lnode_displayed_set(di_lnode_t lnode)
{
long data = (long)di_lnode_private_get(lnode);
data |= LNODE_DISPLAYED;
di_lnode_private_set(lnode, (void *)data);
}
static void
lnode_displayed_clear(di_lnode_t lnode)
{
long data = (long)di_lnode_private_get(lnode);
data &= ~LNODE_DISPLAYED;
di_lnode_private_set(lnode, (void *)data);
}
#define MINOR_DISPLAYED (1<<0)
#define MINOR_PTR (~(0x3))
static long
minor_displayed(di_minor_t minor)
{
long data = (long)di_minor_private_get(minor);
return (data & MINOR_DISPLAYED);
}
static void
minor_displayed_set(di_minor_t minor)
{
long data = (long)di_minor_private_get(minor);
data |= MINOR_DISPLAYED;
di_minor_private_set(minor, (void *)data);
}
static void
minor_displayed_clear(di_minor_t minor)
{
long data = (long)di_minor_private_get(minor);
data &= ~MINOR_DISPLAYED;
di_minor_private_set(minor, (void *)data);
}
static void *
minor_ptr(di_minor_t minor)
{
long data = (long)di_minor_private_get(minor);
return ((void *)(data & MINOR_PTR));
}
static void
minor_ptr_set(di_minor_t minor, void *ptr)
{
long data = (long)di_minor_private_get(minor);
data = (data & ~MINOR_PTR) | (((long)ptr) & MINOR_PTR);
di_minor_private_set(minor, (void *)data);
}
/*
* In this comment typed properties are those of type DI_PROP_TYPE_UNDEF_IT,
* DI_PROP_TYPE_BOOLEAN, DI_PROP_TYPE_INT, DI_PROP_TYPE_INT64,
* DI_PROP_TYPE_BYTE, and DI_PROP_TYPE_STRING.
*
* The guessing algorithm is:
* 1. If the property is typed and the type is consistent with the value of
* the property, then the property is of that type. If the type is not
* consistent with value of the property, then the type is treated as
* alien to prtconf.
* 2. If the property is of type DI_PROP_TYPE_UNKNOWN the following steps
* are carried out.
* a. If the value of the property is consistent with a string property,
* the type of the property is DI_PROP_TYPE_STRING.
* b. Otherwise, if the value of the property is consistent with an integer
* property, the type of the property is DI_PROP_TYPE_INT.
* c. Otherwise, the property type is treated as alien to prtconf.
* 3. If the property type is alien to prtconf, then the property value is
* read by the appropriate routine for untyped properties and the following
* steps are carried out.
* a. If the length that the property routine returned is zero, the
* property is of type DI_PROP_TYPE_BOOLEAN.
* b. Otherwise, if the length that the property routine returned is
* positive, then the property value is treated as raw data of type
* DI_PROP_TYPE_UNKNOWN.
* c. Otherwise, if the length that the property routine returned is
* negative, then there is some internal inconsistency and this is
* treated as an error and no type is determined.
*/
static int
prop_type_guess(const dumpops_t *propops, void *prop, void **prop_data,
int *prop_type)
{
int len, type;
type = PROPTYPE(propops)(prop);
switch (type) {
case DI_PROP_TYPE_UNDEF_IT:
case DI_PROP_TYPE_BOOLEAN:
*prop_data = NULL;
*prop_type = type;
return (0);
case DI_PROP_TYPE_INT:
len = PROPINTS(propops)(prop, (int **)prop_data);
break;
case DI_PROP_TYPE_INT64:
len = PROPINT64(propops)(prop, (int64_t **)prop_data);
break;
case DI_PROP_TYPE_BYTE:
len = PROPBYTES(propops)(prop, (uchar_t **)prop_data);
break;
case DI_PROP_TYPE_STRING:
len = PROPSTRINGS(propops)(prop, (char **)prop_data);
break;
case DI_PROP_TYPE_UNKNOWN:
len = PROPSTRINGS(propops)(prop, (char **)prop_data);
if ((len > 0) && ((*(char **)prop_data)[0] != 0)) {
*prop_type = DI_PROP_TYPE_STRING;
return (len);
}
len = PROPINTS(propops)(prop, (int **)prop_data);
type = DI_PROP_TYPE_INT;
break;
default:
len = -1;
}
if (len > 0) {
*prop_type = type;
return (len);
}
len = PROPRAWDATA(propops)(prop, (uchar_t **)prop_data);
if (len < 0) {
return (-1);
} else if (len == 0) {
*prop_type = DI_PROP_TYPE_BOOLEAN;
return (0);
}
*prop_type = DI_PROP_TYPE_UNKNOWN;
return (len);
}
/*
* Returns 0 if nothing is printed, 1 otherwise
*/
static int
dump_prop_list(const dumpops_t *dumpops, const char *name, int ilev,
void *node, dev_t dev, int *compat_printed)
{
void *prop = DI_PROP_NIL, *prop_data;
di_minor_t minor;
char *p;
int i, prop_type, nitems;
dev_t pdev = DDI_DEV_T_NONE;
int nprop = 0;
if (compat_printed)
*compat_printed = 0;
while ((prop = NEXTPROP(dumpops)(node, prop)) != DI_PROP_NIL) {
/* Skip properties a dev_t oriented caller is not requesting */
if (PROPDEVT(dumpops)) {
pdev = PROPDEVT(dumpops)(prop);
if (dev == DDI_DEV_T_ANY) {
/*
* Caller requesting print all properties
*/
goto print;
} else if (dev == DDI_DEV_T_NONE) {
/*
* Caller requesting print of properties
* associated with devinfo (not minor).
*/
if ((pdev == DDI_DEV_T_ANY) ||
(pdev == DDI_DEV_T_NONE))
goto print;
/*
* Property has a minor association, see if
* we have a minor with this dev_t. If there
* is no such minor we print the property now
* so it gets displayed.
*/
minor = DI_MINOR_NIL;
while ((minor = di_minor_next((di_node_t)node,
minor)) != DI_MINOR_NIL) {
if (di_minor_devt(minor) == pdev)
break;
}
if (minor == DI_MINOR_NIL)
goto print;
} else if (dev == pdev) {
/*
* Caller requesting print of properties
* associated with a specific matching minor
* node.
*/
goto print;
}
/* otherwise skip print */
continue;
}
print: nitems = prop_type_guess(dumpops, prop, &prop_data, &prop_type);
if (nitems < 0)
continue;
if (nprop == 0) {
if (name) {
indent_to_level(ilev);
(void) printf("%s properties:\n", name);
}
ilev++;
}
nprop++;
indent_to_level(ilev);
(void) printf("name='%s' type=", PROPNAME(dumpops)(prop));
/* report 'compatible' as processed */
if (compat_printed &&
(strcmp(PROPNAME(dumpops)(prop), "compatible") == 0))
*compat_printed = 1;
switch (prop_type) {
case DI_PROP_TYPE_UNDEF_IT:
(void) printf("undef");
break;
case DI_PROP_TYPE_BOOLEAN:
(void) printf("boolean");
break;
case DI_PROP_TYPE_INT:
(void) printf("int");
break;
case DI_PROP_TYPE_INT64:
(void) printf("int64");
break;
case DI_PROP_TYPE_BYTE:
(void) printf("byte");
break;
case DI_PROP_TYPE_STRING:
(void) printf("string");
break;
case DI_PROP_TYPE_UNKNOWN:
(void) printf("unknown");
break;
default:
/* Should never be here */
(void) printf("0x%x", prop_type);
}
if (nitems != 0)
(void) printf(" items=%i", nitems);
/* print the major and minor numbers for a device property */
if (PROPDEVT(dumpops)) {
if ((pdev == DDI_DEV_T_NONE) ||
(pdev == DDI_DEV_T_ANY)) {
(void) printf(" dev=none");
} else {
(void) printf(" dev=(%u,%u)",
(uint_t)major(pdev), (uint_t)minor(pdev));
}
}
(void) putchar('\n');
if (nitems == 0)
continue;
indent_to_level(ilev);
(void) printf(" value=");
switch (prop_type) {
case DI_PROP_TYPE_INT:
for (i = 0; i < nitems - 1; i++)
(void) printf("%8.8x.", ((int *)prop_data)[i]);
(void) printf("%8.8x", ((int *)prop_data)[i]);
break;
case DI_PROP_TYPE_INT64:
for (i = 0; i < nitems - 1; i++)
(void) printf("%16.16llx.",
((long long *)prop_data)[i]);
(void) printf("%16.16llx", ((long long *)prop_data)[i]);
break;
case DI_PROP_TYPE_STRING:
p = (char *)prop_data;
for (i = 0; i < nitems - 1; i++) {
(void) printf("'%s' + ", p);
p += strlen(p) + 1;
}
(void) printf("'%s'", p);
break;
default:
for (i = 0; i < nitems - 1; i++)
(void) printf("%2.2x.",
((uint8_t *)prop_data)[i]);
(void) printf("%2.2x", ((uint8_t *)prop_data)[i]);
}
(void) putchar('\n');
}
return (nprop ? 1 : 0);
}
/*
* walk_driver is a debugging facility.
*/
static void
walk_driver(di_node_t root, di_arg_t *di_arg)
{
di_node_t node;
node = di_drv_first_node(dbg.d_drivername, root);
while (node != DI_NODE_NIL) {
(void) dump_devs(node, di_arg);
node = di_drv_next_node(node);
}
}
static const char *
devinfo_is_pci(di_node_t node)
{
char *t = NULL;
di_node_t pnode = di_parent_node(node);
if (di_prop_lookup_strings(DDI_DEV_T_ANY, pnode,
"device_type", &t) <= 0)
return (NULL);
if (t == NULL || (strcmp(t, "pci") != 0 &&
strcmp(t, "pciex") != 0))
return (NULL);
return (t);
}
/*
* print out information about this node, returns appropriate code.
*/
/*ARGSUSED1*/
static int
dump_devs(di_node_t node, void *arg)
{
di_arg_t *di_arg = arg;
di_devlink_handle_t devlink_hdl = di_arg->devlink_hdl;
int ilev = 0; /* indentation level */
char *driver_name;
di_node_t root_node, tmp;
int compat_printed;
int printed;
if (dbg.d_debug) {
char *path = di_devfs_path(node);
dbgprintf("Dump node %s\n", path);
di_devfs_path_free(path);
}
if (dbg.d_bydriver) {
ilev = 1;
} else {
/* figure out indentation level */
tmp = node;
while ((tmp = di_parent_node(tmp)) != DI_NODE_NIL)
ilev++;
if (opts.o_target && !opts.o_ancestors) {
ilev -= opts.o_target - 1;
}
}
if (opts.o_target && !node_display(node)) {
/*
* if we're only displaying certain nodes and this one
* isn't flagged, skip it.
*/
return (DI_WALK_CONTINUE);
}
indent_to_level(ilev);
(void) printf("%s", di_node_name(node));
if (opts.o_pciid) {
int *vid, *did;
const char *dtype = devinfo_is_pci(node);
if (dtype != NULL &&
di_prop_lookup_ints(DDI_DEV_T_ANY, node, "vendor-id",
&vid) > 0 && vid[0] <= UINT16_MAX &&
di_prop_lookup_ints(DDI_DEV_T_ANY, node, "device-id",
&did) > 0 && did[0] <= UINT16_MAX) {
print_pciid(dtype, (uint16_t)vid[0], (uint16_t)did[0],
opts.o_pcidb);
}
}
/*
* if this node does not have an instance number or is the
* root node (1229946), we don't print an instance number
*/
root_node = tmp = node;
while ((tmp = di_parent_node(tmp)) != DI_NODE_NIL)
root_node = tmp;
if ((di_instance(node) >= 0) && (node != root_node))
(void) printf(", instance #%d", di_instance(node));
if (opts.o_drv_name) {
driver_name = di_driver_name(node);
if (driver_name != NULL)
(void) printf(" (driver name: %s)", driver_name);
} else if (di_retired(node)) {
(void) printf(" (retired)");
} else if (di_state(node) & DI_DRIVER_DETACHED)
(void) printf(" (driver not attached)");
(void) printf("\n");
if (opts.o_verbose) {
if (dump_prop_list(&sysprop_dumpops, "System", ilev + 1,
node, DDI_DEV_T_ANY, NULL)) {
(void) dump_prop_list(&globprop_dumpops, NULL, ilev + 1,
node, DDI_DEV_T_ANY, NULL);
} else {
(void) dump_prop_list(&globprop_dumpops,
"System software", ilev + 1,
node, DDI_DEV_T_ANY, NULL);
}
(void) dump_prop_list(&drvprop_dumpops, "Driver", ilev + 1,
node, DDI_DEV_T_NONE, NULL);
printed = dump_prop_list(&hwprop_dumpops, "Hardware",
ilev + 1, node, DDI_DEV_T_ANY, &compat_printed);
/* Ensure that 'compatible' is printed under Hardware header */
if (!compat_printed)
printed |= dump_compatible(printed ? NULL : "Hardware",
ilev + 1, node);
/* Ensure that pci id information is printed under Hardware */
dump_pciid(printed ? NULL : "Hardware", ilev + 1, node);
dump_priv_data(ilev + 1, node);
dump_pathing_data(ilev + 1, node);
dump_link_data(ilev + 1, node, devlink_hdl);
dump_minor_data(ilev + 1, node, devlink_hdl);
}
if (opts.o_target)
return (DI_WALK_CONTINUE);
if (!opts.o_pseudodevs && (strcmp(di_node_name(node), "pseudo") == 0))
return (DI_WALK_PRUNECHILD);
return (DI_WALK_CONTINUE);
}
/*
* The rest of the routines handle printing the raw prom devinfo (-p option).
*
* 128 is the size of the largest (currently) property name
* 16k - MAXNAMESZ - sizeof (int) is the size of the largest
* (currently) property value that is allowed.
* the sizeof (uint_t) is from struct openpromio
*/
#define MAXNAMESZ 128
#define MAXVALSIZE (16384 - MAXNAMESZ - sizeof (uint_t))
#define BUFSIZE (MAXNAMESZ + MAXVALSIZE + sizeof (uint_t))
typedef union {
char buf[BUFSIZE];
struct openpromio opp;
} Oppbuf;
static int prom_fd;
static int
is_openprom(void)
{
Oppbuf oppbuf;
struct openpromio *opp = &(oppbuf.opp);
unsigned int i;
opp->oprom_size = MAXVALSIZE;
if (ioctl(prom_fd, OPROMGETCONS, opp) < 0)
err(-1, "OPROMGETCONS");
i = (unsigned int)((unsigned char)opp->oprom_array[0]);
return ((i & OPROMCONS_OPENPROM) == OPROMCONS_OPENPROM);
}
int
do_prominfo(void)
{
uint_t arg = 0;
uint_t *ptr;
uchar_t *prom_snapshot;
if (promopen(O_RDONLY)) {
err(-1, "openeepr device open failed");
}
if (is_openprom() == 0) {
(void) fprintf(stderr, "System architecture does not "
"support this option of this command.\n");
return (1);
}
/*
* If we're eiher in verbose mode or asked to get device information,
* then we need to actually ask for verbose information from the prom by
* setting a non-zero value.
*/
if (opts.o_verbose != 0 || opts.o_pciid != 0) {
arg = 1;
}
/* OPROMSNAPSHOT returns size in arg */
if (ioctl(prom_fd, OPROMSNAPSHOT, &arg) < 0)
err(-1, "OPROMSNAPSHOT");
/*
* ioctl OPROMCOPYOUT is expecting buffer with at least
* sizeof (uint_t).
*/
if (arg < sizeof (uint_t))
return (1);
if ((ptr = malloc(arg)) == NULL)
err(-1, "failed to allocate memory");
/* copy out the snapshot for printing */
*ptr = arg;
prom_snapshot = (uchar_t *)ptr;
if (ioctl(prom_fd, OPROMCOPYOUT, prom_snapshot) < 0)
err(-1, "OPROMCOPYOUT");
promclose();
/* print out information */
walk(prom_snapshot, arg, 0);
free(ptr);
return (0);
}
static void
walk(uchar_t *buf, uint_t size, int level)
{
int error;
nvlist_t *nvl, *cnvl;
nvpair_t *child = NULL;
uchar_t *cbuf = NULL;
uint_t csize;
/* Expand to an nvlist */
if (nvlist_unpack((char *)buf, size, &nvl, 0))
err(-1, "error processing snapshot");
/* print current node */
dump_node(nvl, level);
/* print children */
error = nvlist_lookup_byte_array(nvl, "@child", &cbuf, &csize);
if ((error == ENOENT) || (cbuf == NULL))
return; /* no child exists */
if (error || nvlist_unpack((char *)cbuf, csize, &cnvl, 0))
err(-1, "error processing snapshot");
while ((child = nvlist_next_nvpair(cnvl, child)) != NULL) {
char *name = nvpair_name(child);
data_type_t type = nvpair_type(child);
uchar_t *nodebuf;
uint_t nodesize;
if (strcmp("node", name) != 0) {
dbgprintf("unexpected nvpair name %s != name\n", name);
continue;
}
if (type != DATA_TYPE_BYTE_ARRAY) {
dbgprintf("unexpected nvpair type %d, "
"not byte array \n", type);
continue;
}
(void) nvpair_value_byte_array(child,
(uchar_t **)&nodebuf, &nodesize);
walk(nodebuf, nodesize, level + 1);
}
nvlist_free(nvl);
}
/*
* The encoding of the name property depends on whether we got verbose prom
* information or not. If we didn't, it'll just be a string in the nvlist_t.
* However, otherwise it'll end up being byte data that the kernel guarantees
* for 'name' is actually a null terminated string.
*/
static const char *
prom_node_name(nvlist_t *nvl)
{
char *str;
uchar_t *bval;
uint_t len;
if (nvlist_lookup_string(nvl, "name", &str) == 0) {
return (str);
}
if (nvlist_lookup_byte_array(nvl, "name", &bval, &len) == 0) {
if (bval[len - 1] == '\0')
return ((char *)bval);
}
return ("data not available");
}
/*
* Given a node at a given level, try to determine if this is a PCI device. We
* do this through a two step process mostly due to the fact that we don't have
* easy linkage to the parent here and not all nodes have everything we expect.
* This test is more similar to the pcieadm test than what we use for the normal
* devinfo part.
*
* 1. Check the node name to see if it starts with pci with another character
* (to avoid the synthetic pci instances).
* 2. Look at the compatible property for the class strings.
*/
static boolean_t
prom_is_pci(nvlist_t *nvl, const char *name)
{
uchar_t *value;
uint_t len;
if (strncmp("pci", name, 3) == 0 && name[3] != '\0') {
return (B_TRUE);
}
/*
* This is a composite string. Unlike with devinfo, we just have the
* array of strings here and we have to manually make sure we don't
* exceed the size as we don't have the total number of entries.
*/
if (nvlist_lookup_byte_array(nvl, "compatible", &value, &len) == 0) {
const char *str;
/*
* Adjust by one to account or the extra NUL that the driver
* inserts.
*/
len--;
for (str = (char *)value; str < ((char *)value + len);
str += strlen(str) + 1) {
if (strncmp("pciclass,", str,
sizeof ("pciclass,") - 1) == 0 ||
strncmp("pciexclass,", str,
sizeof ("pciexclass,") - 1) == 0) {
return (B_TRUE);
}
}
}
return (B_FALSE);
}
static boolean_t
prom_extract_u16(nvlist_t *nvl, const char *name, uint16_t *valp)
{
uchar_t *value;
uint_t len;
uint32_t u32;
if (nvlist_lookup_byte_array(nvl, name, &value, &len) != 0) {
return (B_FALSE);
}
/*
* A uint32_t will be encoded as a 4-byte value followed by a NUL
* regardless.
*/
if (len != 5 || value[4] != '\0') {
return (B_FALSE);
}
/*
* The current PROM code puts values in the native-endianness for x86
* and SPARC as opposed to always translating into what 1275 wants of
* big endian. It is unclear what'll happen for subsequent platforms.
*/
#if !defined(__x86)
#error "determine endianness of the platform's openprom interface"
#endif
(void) memcpy(&u32, value, sizeof (u32));
if (u32 > UINT16_MAX) {
return (B_FALSE);
}
*valp = (uint16_t)u32;
return (B_TRUE);
}
/*
* Similar to the above, synthesize the device type as either pci or pciex based
* on the compatible array. A PCI Express device will have their first entry
* start with 'pciexXXXX,XXXX'. A device without that will just start with pci.
*/
static const char *
prom_pci_device_type(nvlist_t *nvl)
{
uchar_t *value;
uint_t len;
if (nvlist_lookup_byte_array(nvl, "compatible", &value, &len) != 0) {
return (NULL);
}
if (strncmp("pciex", (char *)value, 5) == 0 && value[5] != '\0') {
return ("pciex");
}
if (strncmp("pci", (char *)value, 3) == 0 && value[3] != '\0') {
return ("pci");
}
return (NULL);
}
static void
dump_pcidb(int level, uint16_t vid, uint16_t did, boolean_t do_sub,
uint16_t svid, uint16_t sdid)
{
const char *vstr = "unknown vendor";
const char *dstr = "unknown device";
const char *sstr = "unknown subsystem";
pcidb_vendor_t *pciv = NULL;
pcidb_device_t *pcid = NULL;
pcidb_subvd_t *pcis = NULL;
if (opts.o_pcidb == NULL)
return;
pciv = pcidb_lookup_vendor(opts.o_pcidb, vid);
if (pciv != NULL) {
vstr = pcidb_vendor_name(pciv);
pcid = pcidb_lookup_device_by_vendor(pciv, did);
if (pcid != NULL) {
dstr = pcidb_device_name(pcid);
}
}
indent_to_level(level);
(void) printf("vendor-name: '%s'\n", vstr);
indent_to_level(level);
(void) printf("device-name: '%s'\n", dstr);
if (!do_sub)
return;
if (pciv != NULL && pcid != NULL) {
pcis = pcidb_lookup_subvd_by_device(pcid, svid, sdid);
if (pcis != NULL) {
sstr = pcidb_subvd_name(pcis);
}
}
indent_to_level(level);
(void) printf("subsystem-name: '%s'\n", sstr);
}
/*
* Print all properties and values. When o_verbose is specified then rather than
* printing the name of the node (and potentially the PCI ID and DB info), we
* print the node name and instead include all that information in properties.
* This mimics the behavior of the non-prom path.
*/
static void
dump_node(nvlist_t *nvl, int level)
{
int id = 0;
const char *name;
nvpair_t *nvp = NULL;
indent_to_level(level);
name = prom_node_name(nvl);
(void) printf("Node");
if (!opts.o_verbose) {
(void) printf(" '%s'", name);
if (opts.o_pciid && prom_is_pci(nvl, name)) {
const char *dtype = prom_pci_device_type(nvl);
uint16_t vid, did;
if (prom_extract_u16(nvl, "vendor-id", &vid) &&
prom_extract_u16(nvl, "device-id", &did) &&
dtype != NULL) {
print_pciid(dtype, vid, did, opts.o_pcidb);
}
}
} else {
(void) nvlist_lookup_int32(nvl, "@nodeid", &id);
(void) printf(" %#08x\n", id);
}
if (!opts.o_verbose) {
(void) putchar('\n');
return;
}
while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
name = nvpair_name(nvp);
if (name[0] == '@')
continue;
print_one(nvp, level + 1);
}
/*
* Go through and create synthetic properties for PCI devices like the
* normal device tree path.
*/
if (prom_is_pci(nvl, name)) {
uint16_t vid = UINT16_MAX, did = UINT16_MAX;
uint16_t svid = UINT16_MAX, sdid = UINT16_MAX;
boolean_t valid_sub = B_FALSE;
if (prom_extract_u16(nvl, "subsystem-vendor-id", &svid) &&
prom_extract_u16(nvl, "subsystem-id", &sdid)) {
valid_sub = B_TRUE;
}
if (prom_extract_u16(nvl, "vendor-id", &vid) &&
prom_extract_u16(nvl, "device-id", &did)) {
dump_pcidb(level + 1, vid, did, valid_sub, svid, sdid);
}
}
(void) putchar('\n');
}
static const char *
path_state_name(di_path_state_t st)
{
switch (st) {
case DI_PATH_STATE_ONLINE:
return ("online");
case DI_PATH_STATE_STANDBY:
return ("standby");
case DI_PATH_STATE_OFFLINE:
return ("offline");
case DI_PATH_STATE_FAULT:
return ("faulted");
case DI_PATH_STATE_UNKNOWN:
default:
return ("unknown");
}
}
/*
* Print all phci's each client is connected to.
*/
static void
dump_pathing_data(int ilev, di_node_t node)
{
di_path_t pi = DI_PATH_NIL;
di_node_t phci_node;
char *phci_path;
int path_instance;
int firsttime = 1;
if (node == DI_PATH_NIL)
return;
while ((pi = di_path_client_next_path(node, pi)) != DI_PATH_NIL) {
/* It is not really a path if we failed to capture the pHCI */
phci_node = di_path_phci_node(pi);
if (phci_node == DI_NODE_NIL)
continue;
/* Print header for the first path */
if (firsttime) {
indent_to_level(ilev);
firsttime = 0;
ilev++;
(void) printf("Paths from multipath bus adapters:\n");
}
/*
* Print the path instance and full "pathinfo" path, which is
* the same as the /devices devifo path had the device been
* enumerated under pHCI.
*/
phci_path = di_devfs_path(phci_node);
if (phci_path) {
path_instance = di_path_instance(pi);
if (path_instance > 0) {
indent_to_level(ilev);
(void) printf("Path %d: %s/%s@%s\n",
path_instance, phci_path,
di_node_name(node),
di_path_bus_addr(pi));
}
di_devfs_path_free(phci_path);
}
/* print phci driver, instance, and path state information */
indent_to_level(ilev);
(void) printf("%s#%d (%s)\n", di_driver_name(phci_node),
di_instance(phci_node), path_state_name(di_path_state(pi)));
(void) dump_prop_list(&pathprop_dumpops, NULL, ilev + 1,
pi, DDI_DEV_T_ANY, NULL);
}
}
static int
dump_minor_data_links(di_devlink_t devlink, void *arg)
{
int ilev = (intptr_t)arg;
indent_to_level(ilev);
(void) printf("dev_link=%s\n", di_devlink_path(devlink));
return (DI_WALK_CONTINUE);
}
static void
dump_minor_data_paths(int ilev, di_minor_t minor,
di_devlink_handle_t devlink_hdl)
{
char *path, *type;
int spec_type;
/* get the path to the device and the minor node name */
if ((path = di_devfs_minor_path(minor)) == NULL)
err(-1, "failed to allocate memory");
/* display the path to this minor node */
indent_to_level(ilev);
(void) printf("dev_path=%s\n", path);
if (devlink_hdl != NULL) {
/* get the device minor node information */
spec_type = di_minor_spectype(minor);
switch (di_minor_type(minor)) {
case DDM_MINOR:
type = "minor";
break;
case DDM_ALIAS:
type = "alias";
break;
case DDM_DEFAULT:
type = "default";
break;
case DDM_INTERNAL_PATH:
type = "internal";
break;
default:
type = "unknown";
break;
}
/* display the device minor node information */
indent_to_level(ilev + 1);
(void) printf("spectype=%s type=%s\n",
(spec_type == S_IFBLK) ? "blk" : "chr", type);
/* display all the devlinks for this device minor node */
(void) di_devlink_walk(devlink_hdl, NULL, path,
0, (void *)(intptr_t)(ilev + 1), dump_minor_data_links);
}
di_devfs_path_free(path);
}
static void
create_minor_list(di_node_t node)
{
di_minor_t minor, minor_head, minor_tail, minor_prev, minor_walk;
int major;
/* if there are no minor nodes, bail */
if (di_minor_next(node, DI_MINOR_NIL) == DI_MINOR_NIL)
return;
/*
* here we want to create lists of minor nodes with the same
* dev_t. to do this we first sort all the minor nodes by devt.
*
* the algorithm used here is a bubble sort, so performance sucks.
* but it's probably ok here because most device instances don't
* have that many minor nodes. also we're doing this as we're
* displaying each node so it doesn't look like we're pausing
* output for a long time.
*/
major = di_driver_major(node);
minor_head = minor_tail = minor = DI_MINOR_NIL;
while ((minor = di_minor_next(node, minor)) != DI_MINOR_NIL) {
dev_t dev = di_minor_devt(minor);
/* skip /pseudo/clone@0 minor nodes */
if (major != major(dev))
continue;
minor_ptr_set(minor, DI_MINOR_NIL);
if (minor_head == DI_MINOR_NIL) {
/* this is the first minor node we're looking at */
minor_head = minor_tail = minor;
continue;
}
/*
* if the new dev is less than the old dev, update minor_head
* so it points to the beginning of the list. ie it points
* to the node with the lowest dev value
*/
if (dev <= di_minor_devt(minor_head)) {
minor_ptr_set(minor, minor_head);
minor_head = minor;
continue;
}
minor_prev = minor_head;
minor_walk = minor_ptr(minor_head);
while ((minor_walk != DI_MINOR_NIL) &&
(dev > di_minor_devt(minor_walk))) {
minor_prev = minor_walk;
minor_walk = minor_ptr(minor_walk);
}
minor_ptr_set(minor, minor_walk);
minor_ptr_set(minor_prev, minor);
if (minor_walk == NULL)
minor_tail = minor;
}
/* check if there were any non /pseudo/clone@0 nodes. if not, bail */
if (minor_head == DI_MINOR_NIL)
return;
/*
* now that we have a list of minor nodes sorted by devt
* we walk through the list and break apart the entire list
* to create circular lists of minor nodes with matching devts.
*/
minor_prev = minor_head;
minor_walk = minor_ptr(minor_head);
while (minor_walk != DI_MINOR_NIL) {
if (di_minor_devt(minor_prev) != di_minor_devt(minor_walk)) {
minor_ptr_set(minor_prev, minor_head);
minor_head = minor_walk;
}
minor_prev = minor_walk;
minor_walk = minor_ptr(minor_walk);
}
minor_ptr_set(minor_tail, minor_head);
}
static void
link_lnode_disp(di_link_t link, uint_t endpoint, int ilev,
di_devlink_handle_t devlink_hdl)
{
di_lnode_t lnode;
char *name, *path;
int displayed_path, spec_type;
di_node_t node = DI_NODE_NIL;
dev_t devt = DDI_DEV_T_NONE;
lnode = di_link_to_lnode(link, endpoint);
indent_to_level(ilev);
name = di_lnode_name(lnode);
spec_type = di_link_spectype(link);
(void) printf("mod=%s", name);
/*
* if we're displaying the source of a link, we should display
* the target access mode. (either block or char.)
*/
if (endpoint == DI_LINK_SRC)
(void) printf(" accesstype=%s",
(spec_type == S_IFBLK) ? "blk" : "chr");
/*
* check if the lnode is bound to a specific device
* minor node (i.e. if it's bound to a dev_t) and
* if so display the dev_t value and any possible
* minor node pathing information.
*/
displayed_path = 0;
if (di_lnode_devt(lnode, &devt) == 0) {
di_minor_t minor = DI_MINOR_NIL;
(void) printf(" dev=(%u,%u)\n",
(uint_t)major(devt), (uint_t)minor(devt));
/* display paths to the src devt minor node */
while ((minor = di_minor_next(node, minor)) != DI_MINOR_NIL) {
if (devt != di_minor_devt(minor))
continue;
if ((endpoint == DI_LINK_TGT) &&
(spec_type != di_minor_spectype(minor)))
continue;
dump_minor_data_paths(ilev + 1, minor, devlink_hdl);
displayed_path = 1;
}
} else {
(void) printf("\n");
}
if (displayed_path)
return;
/*
* This device lnode is not did not have any minor node
* pathing information so display the path to device node.
*/
node = di_lnode_devinfo(lnode);
if ((path = di_devfs_path(node)) == NULL)
err(-1, "failed to allocate memory");
indent_to_level(ilev + 1);
(void) printf("dev_path=%s\n", path);
di_devfs_path_free(path);
}
static void
dump_minor_link_data(int ilev, di_node_t node, dev_t devt,
di_devlink_handle_t devlink_hdl)
{
int first = 1;
di_link_t link;
link = DI_LINK_NIL;
while ((link = di_link_next_by_node(node, link, DI_LINK_TGT)) !=
DI_LINK_NIL) {
di_lnode_t tgt_lnode;
dev_t tgt_devt = DDI_DEV_T_NONE;
tgt_lnode = di_link_to_lnode(link, DI_LINK_TGT);
if (di_lnode_devt(tgt_lnode, &tgt_devt) != 0)
continue;
if (devt != tgt_devt)
continue;
if (first) {
first = 0;
indent_to_level(ilev);
(void) printf("Device Minor Layered Under:\n");
}
/* displayed this lnode */
lnode_displayed_set(tgt_lnode);
link_lnode_disp(link, DI_LINK_SRC, ilev + 1, devlink_hdl);
}
link = DI_LINK_NIL;
while ((link = di_link_next_by_node(node, link, DI_LINK_SRC)) !=
DI_LINK_NIL) {
di_lnode_t src_lnode;
dev_t src_devt = DDI_DEV_T_NONE;
src_lnode = di_link_to_lnode(link, DI_LINK_SRC);
if (di_lnode_devt(src_lnode, &src_devt) != 0)
continue;
if (devt != src_devt)
continue;
if (first) {
first = 0;
indent_to_level(ilev);
(void) printf("Device Minor Layered Over:\n");
}
/* displayed this lnode */
lnode_displayed_set(src_lnode);
link_lnode_disp(link, DI_LINK_TGT, ilev + 1, devlink_hdl);
}
}
static void
dump_minor_data(int ilev, di_node_t node, di_devlink_handle_t devlink_hdl)
{
di_minor_t minor, minor_next;
di_lnode_t lnode;
di_link_t link;
int major, firstminor = 1;
/*
* first go through and mark all lnodes and minor nodes for this
* node as undisplayed
*/
lnode = DI_LNODE_NIL;
while ((lnode = di_lnode_next(node, lnode)) != DI_LNODE_NIL)
lnode_displayed_clear(lnode);
minor = DI_MINOR_NIL;
while ((minor = di_minor_next(node, minor)) != DI_MINOR_NIL) {
minor_displayed_clear(minor);
}
/*
* when we display the minor nodes we want to coalesce nodes
* that have the same dev_t. we do this by creating circular
* lists of minor nodes with the same devt.
*/
create_minor_list(node);
/* now we display the driver defined minor nodes */
major = di_driver_major(node);
minor = DI_MINOR_NIL;
while ((minor = di_minor_next(node, minor)) != DI_MINOR_NIL) {
dev_t devt;
/*
* skip /pseudo/clone@0 minor nodes.
* these are only created for DLPIv2 network devices.
* since these minor nodes are associated with a driver
* and are only bound to a device instance after they
* are opened and attached we don't print them out
* here.
*/
devt = di_minor_devt(minor);
if (major != major(devt))
continue;
/* skip nodes that may have already been displayed */
if (minor_displayed(minor))
continue;
if (firstminor) {
firstminor = 0;
indent_to_level(ilev++);
(void) printf("Device Minor Nodes:\n");
}
/* display the device minor node information */
indent_to_level(ilev);
(void) printf("dev=(%u,%u)\n",
(uint_t)major(devt), (uint_t)minor(devt));
minor_next = minor;
do {
/* display device minor node path info */
minor_displayed_set(minor_next);
dump_minor_data_paths(ilev + 1, minor_next,
devlink_hdl);
/* get a pointer to the next node */
minor_next = minor_ptr(minor_next);
} while (minor_next != minor);
/* display who has this device minor node open */
dump_minor_link_data(ilev + 1, node, devt, devlink_hdl);
/* display properties associated with this devt */
(void) dump_prop_list(&drvprop_dumpops, "Minor",
ilev + 1, node, devt, NULL);
}
/*
* now go through all the target lnodes for this node and
* if they haven't yet been displayed, display them now.
*
* this happens in the case of clone opens when an "official"
* minor node does not exist for the opened devt
*/
link = DI_LINK_NIL;
while ((link = di_link_next_by_node(node, link, DI_LINK_TGT)) !=
DI_LINK_NIL) {
dev_t devt;
lnode = di_link_to_lnode(link, DI_LINK_TGT);
/* if we've already displayed this target lnode, skip it */
if (lnode_displayed(lnode))
continue;
if (firstminor) {
firstminor = 0;
indent_to_level(ilev++);
(void) printf("Device Minor Nodes:\n");
}
/* display the device minor node information */
indent_to_level(ilev);
(void) di_lnode_devt(lnode, &devt);
(void) printf("dev=(%u,%u)\n",
(uint_t)major(devt), (uint_t)minor(devt));
indent_to_level(ilev + 1);
(void) printf("dev_path=<clone>\n");
/* display who has this cloned device minor node open */
dump_minor_link_data(ilev + 1, node, devt, devlink_hdl);
/* mark node as displayed */
lnode_displayed_set(lnode);
}
}
static void
dump_link_data(int ilev, di_node_t node, di_devlink_handle_t devlink_hdl)
{
int first = 1;
di_link_t link;
link = DI_LINK_NIL;
while ((link = di_link_next_by_node(node, link, DI_LINK_SRC)) !=
DI_LINK_NIL) {
di_lnode_t src_lnode;
dev_t src_devt = DDI_DEV_T_NONE;
src_lnode = di_link_to_lnode(link, DI_LINK_SRC);
/*
* here we only want to print out layering information
* if we are the source and our source lnode is not
* associated with any particular dev_t. (which means
* we won't display this link while dumping minor node
* info.)
*/
if (di_lnode_devt(src_lnode, &src_devt) != -1)
continue;
if (first) {
first = 0;
indent_to_level(ilev);
(void) printf("Device Layered Over:\n");
}
/* displayed this lnode */
link_lnode_disp(link, DI_LINK_TGT, ilev + 1, devlink_hdl);
}
}
/*
* certain 'known' property names may contain 'composite' strings.
* Handle them here, and print them as 'string1' + 'string2' ...
*/
static int
print_composite_string(const char *var, char *value, int size)
{
char *p, *q;
char *firstp;
if ((strcmp(var, "version") != 0) &&
(strcmp(var, "compatible") != 0))
return (0); /* Not a known composite string */
/*
* Verify that each string in the composite string is non-NULL,
* is within the bounds of the property length, and contains
* printable characters or white space. Otherwise let the
* caller deal with it.
*/
for (firstp = p = value; p < (value + size); p += strlen(p) + 1) {
if (strlen(p) == 0)
return (0); /* NULL string */
for (q = p; *q; q++) {
if (!(isascii(*q) && (isprint(*q) || isspace(*q))))
return (0); /* Not printable or space */
}
if (q > (firstp + size))
return (0); /* Out of bounds */
}
for (firstp = p = value; p < (value + size); p += strlen(p) + 1) {
if (p == firstp)
(void) printf("'%s'", p);
else
(void) printf(" + '%s'", p);
}
(void) putchar('\n');
return (1);
}
/*
* Print one property and its value. Handle the verbose case.
*/
static void
print_one(nvpair_t *nvp, int level)
{
int i;
int endswap = 0;
uint_t valsize;
char *value;
char *var = nvpair_name(nvp);
indent_to_level(level);
(void) printf("%s: ", var);
switch (nvpair_type(nvp)) {
case DATA_TYPE_BOOLEAN:
(void) printf(" \n");
return;
case DATA_TYPE_BYTE_ARRAY:
if (nvpair_value_byte_array(nvp, (uchar_t **)&value,
&valsize)) {
(void) printf("data not available.\n");
return;
}
valsize--; /* take out null added by driver */
/*
* Do not print valsize > MAXVALSIZE, to be compatible
* with old behavior. E.g. intel's eisa-nvram property
* has a size of 65 K.
*/
if (valsize > MAXVALSIZE) {
(void) printf(" \n");
return;
}
break;
default:
(void) printf("data type unexpected.\n");
return;
}
/*
* Handle printing verbosely
*/
if (print_composite_string(var, value, valsize)) {
return;
}
if (!unprintable(value, valsize)) {
(void) printf(" '%s'\n", value);
return;
}
(void) printf(" ");
#ifdef __x86
/*
* Due to backwards compatibility constraints x86 int
* properties are not in big-endian (ieee 1275) byte order.
* If we have a property that is a multiple of 4 bytes,
* let's assume it is an array of ints and print the bytes
* in little endian order to make things look nicer for
* the user.
*/
endswap = (valsize % 4) == 0;
#endif /* __x86 */
for (i = 0; i < valsize; i++) {
int out;
if (i && (i % 4 == 0))
(void) putchar('.');
if (endswap)
out = value[i + (3 - 2 * (i % 4))] & 0xff;
else
out = value[i] & 0xff;
(void) printf("%02x", out);
}
(void) putchar('\n');
}
static int
unprintable(char *value, int size)
{
int i;
/*
* Is this just a zero?
*/
if (size == 0 || value[0] == '\0')
return (1);
/*
* If any character is unprintable, or if a null appears
* anywhere except at the end of a string, the whole
* property is "unprintable".
*/
for (i = 0; i < size; ++i) {
if (value[i] == '\0')
return (i != (size - 1));
if (!isascii(value[i]) || iscntrl(value[i]))
return (1);
}
return (0);
}
static int
promopen(int oflag)
{
for (;;) {
if ((prom_fd = open(opts.o_promdev, oflag)) < 0) {
if (errno == EAGAIN) {
(void) sleep(5);
continue;
}
if (errno == ENXIO)
return (-1);
if (getzoneid() == GLOBAL_ZONEID) {
err(-1, "cannot open %s", opts.o_promdev);
}
/* not an error if this isn't the global zone */
warnx("openprom facility not available");
exit(0);
} else
return (0);
}
}
static void
promclose(void)
{
if (close(prom_fd) < 0)
err(-1, "close error on %s", opts.o_promdev);
}
/*
* Get and print the name of the frame buffer device.
*/
int
do_fbname(void)
{
int retval;
char fbuf_path[MAXPATHLEN];
retval = modctl(MODGETFBNAME, (caddr_t)fbuf_path);
if (retval == 0) {
(void) printf("%s\n", fbuf_path);
} else {
if (retval == EFAULT) {
(void) fprintf(stderr,
"Error copying fb path to userland\n");
} else {
(void) fprintf(stderr,
"Console output device is not a frame buffer\n");
}
return (1);
}
return (0);
}
/*
* Get and print the PROM version.
*/
int
do_promversion(void)
{
Oppbuf oppbuf;
struct openpromio *opp = &(oppbuf.opp);
if (promopen(O_RDONLY)) {
(void) fprintf(stderr, "Cannot open openprom device\n");
return (1);
}
opp->oprom_size = MAXVALSIZE;
if (ioctl(prom_fd, OPROMGETVERSION, opp) < 0)
err(-1, "OPROMGETVERSION");
(void) printf("%s\n", opp->oprom_array);
promclose();
return (0);
}
int
do_productinfo(void)
{
di_node_t root, next_node;
di_prom_handle_t promh;
static const char *root_prop[] = { "name", "model", "banner-name",
"compatible" };
static const char *root_propv[] = { "name", "model", "banner-name",
"compatible", "idprom" };
static const char *oprom_prop[] = { "model", "version" };
root = di_init("/", DINFOCPYALL);
if (root == DI_NODE_NIL) {
(void) fprintf(stderr, "di_init() failed\n");
return (1);
}
promh = di_prom_init();
if (promh == DI_PROM_HANDLE_NIL) {
(void) fprintf(stderr, "di_prom_init() failed\n");
return (1);
}
if (opts.o_verbose) {
dump_prodinfo(promh, root, root_propv, "root",
NUM_ELEMENTS(root_propv));
/* Get model and version properties under node "openprom" */
next_node = find_node_by_name(promh, root, "openprom");
if (next_node != DI_NODE_NIL)
dump_prodinfo(promh, next_node, oprom_prop,
"openprom", NUM_ELEMENTS(oprom_prop));
} else
dump_prodinfo(promh, root, root_prop, "root",
NUM_ELEMENTS(root_prop));
di_prom_fini(promh);
di_fini(root);
return (0);
}
di_node_t
find_node_by_name(di_prom_handle_t promh, di_node_t parent,
char *node_name)
{
di_node_t next_node;
uchar_t *prop_valp;
for (next_node = di_child_node(parent); next_node != DI_NODE_NIL;
next_node = di_sibling_node(next_node)) {
int len;
len = get_propval_by_name(promh, next_node, "name", &prop_valp);
if ((len != -1) && (strcmp((char *)prop_valp, node_name) == 0))
return (next_node);
}
return (DI_NODE_NIL);
}
int
get_propval_by_name(di_prom_handle_t promh, di_node_t node, const char *name,
uchar_t **valp)
{
int len;
uchar_t *bufp;
len = di_prom_prop_lookup_bytes(promh, node, name,
(uchar_t **)&bufp);
if (len != -1) {
*valp = (uchar_t *)malloc(len);
(void) memcpy(*valp, bufp, len);
}
return (len);
}
static void
dump_prodinfo(di_prom_handle_t promh, di_node_t node, const char **propstr,
char *node_name, int num)
{
int out, len, index1, index, endswap = 0;
uchar_t *prop_valp;
for (index1 = 0; index1 < num; index1++) {
len = get_propval_by_name(promh, node, propstr[index1],
&prop_valp);
if (len != -1) {
if (strcmp(node_name, "root"))
(void) printf("%s ", node_name);
(void) printf("%s: ", propstr[index1]);
if (print_composite_string((const char *)
propstr[index1], (char *)prop_valp, len)) {
free(prop_valp);
continue;
}
if (!unprintable((char *)prop_valp, len)) {
(void) printf(" %s\n", (char *)prop_valp);
free(prop_valp);
continue;
}
(void) printf(" ");
#ifdef __x86
endswap = (len % 4) == 0;
#endif /* __x86 */
for (index = 0; index < len; index++) {
if (index && (index % 4 == 0))
(void) putchar('.');
if (endswap)
out = prop_valp[index +
(3 - 2 * (index % 4))] & 0xff;
else
out = prop_valp[index] & 0xff;
(void) printf("%02x", out);
}
(void) putchar('\n');
free(prop_valp);
}
}
}
static int
dump_compatible(char *name, int ilev, di_node_t node)
{
int ncompat;
char *compat_array;
char *p, *q;
int i;
if (node == DI_PATH_NIL)
return (0);
ncompat = di_compatible_names(node, &compat_array);
if (ncompat <= 0)
return (0); /* no 'compatible' available */
/* verify integrety of compat_array */
for (i = 0, p = compat_array; i < ncompat; i++, p += strlen(p) + 1) {
if (strlen(p) == 0)
return (0); /* NULL string */
for (q = p; *q; q++) {
if (!(isascii(*q) && (isprint(*q) || isspace(*q))))
return (0); /* Not printable or space */
}
}
/* If name is non-NULL, produce header */
if (name) {
indent_to_level(ilev);
(void) printf("%s properties:\n", name);
}
ilev++;
/* process like a string array property */
indent_to_level(ilev);
(void) printf("name='compatible' type=string items=%d\n", ncompat);
indent_to_level(ilev);
(void) printf(" value=");
for (i = 0, p = compat_array; i < (ncompat - 1);
i++, p += strlen(p) + 1)
(void) printf("'%s' + ", p);
(void) printf("'%s'", p);
(void) putchar('\n');
return (1);
}
static void
dump_pciid(char *name, int ilev, di_node_t node)
{
int *vid, *did, *svid, *sdid;
const char *vname, *dname, *sname;
pcidb_vendor_t *pciv;
pcidb_device_t *pcid;
pcidb_subvd_t *pcis;
const char *unov = "unknown vendor";
const char *unod = "unknown device";
const char *unos = "unknown subsystem";
if (opts.o_pcidb == NULL)
return;
vname = unov;
dname = unod;
sname = unos;
if (devinfo_is_pci(node) == NULL) {
return;
}
/*
* All devices should have a vendor and device id, if we fail to find
* one, then we're going to return right here and not print anything.
*
* We're going to also check for the subsystem-vendor-id and
* subsystem-id. If we don't find one of them, we're going to assume
* that this device does not have one. In that case, we will never
* attempt to try and print anything related to that. If it does have
* both, then we are going to look them up and print the appropriate
* string if we find it or not.
*/
if (di_prop_lookup_ints(DDI_DEV_T_ANY, node, "vendor-id", &vid) <= 0)
return;
if (di_prop_lookup_ints(DDI_DEV_T_ANY, node, "device-id", &did) <= 0)
return;
if (di_prop_lookup_ints(DDI_DEV_T_ANY, node, "subsystem-vendor-id",
&svid) <= 0 || di_prop_lookup_ints(DDI_DEV_T_ANY, node,
"subsystem-id", &sdid) <= 0) {
svid = NULL;
sdid = NULL;
sname = NULL;
}
pciv = pcidb_lookup_vendor(opts.o_pcidb, vid[0]);
if (pciv == NULL)
goto print;
vname = pcidb_vendor_name(pciv);
pcid = pcidb_lookup_device_by_vendor(pciv, did[0]);
if (pcid == NULL)
goto print;
dname = pcidb_device_name(pcid);
if (svid != NULL) {
pcis = pcidb_lookup_subvd_by_device(pcid, svid[0], sdid[0]);
if (pcis == NULL)
goto print;
sname = pcidb_subvd_name(pcis);
}
print:
/* If name is non-NULL, produce header */
if (name) {
indent_to_level(ilev);
(void) printf("%s properties:\n", name);
}
ilev++;
/* These are all going to be single string properties */
indent_to_level(ilev);
(void) printf("name='vendor-name' type=string items=1\n");
indent_to_level(ilev);
(void) printf(" value='%s'\n", vname);
indent_to_level(ilev);
(void) printf("name='device-name' type=string items=1\n");
indent_to_level(ilev);
(void) printf(" value='%s'\n", dname);
if (sname != NULL) {
indent_to_level(ilev);
(void) printf("name='subsystem-name' type=string items=1\n");
indent_to_level(ilev);
(void) printf(" value='%s'\n", sname);
}
}
/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
* Copyright 2022 Oxide Computer Company
*/
#include <stdio.h>
#include <stddef.h>
#include <fcntl.h>
#include <string.h>
#include <libdevinfo.h>
#include <sys/pctypes.h>
#include <sys/pcmcia.h>
#include <sys/utsname.h>
#include <sys/avintr.h>
#include "prtconf.h"
struct priv_data {
char *drv_name; /* parent name */
void (*pd_print)(uintptr_t, int); /* print function */
};
extern void indent_to_level();
static void obio_printregs(struct regspec *, int);
static void obio_printranges(struct rangespec *, int);
static void obio_printintr(struct intrspec *, int);
static void obio_print(uintptr_t, int);
static void pcmcia_printregs(struct pcm_regs *, int);
static void pcmcia_printintr(struct intrspec *, int);
static void pcmcia_print(uintptr_t, int);
static void sbus_print(uintptr_t, int);
static struct priv_data *match_priv_data(di_node_t);
/*
* This is a hardcoded list of drivers we print parent private
* data as of Solaris 7.
*/
static struct di_priv_format ppd_format[] = {
{
/*
* obio format: applies the following list
* of nexus drivers. Note that obio driver
* went away with sun4m.
*/
#ifdef __sparc
"central dma ebus fhc isa pci rootnex",
#else
"central dma ebus fhc isa pci pci_pci rootnex",
#endif /* __sparc */
sizeof (struct ddi_parent_private_data),
sizeof (struct regspec), /* first pointer */
offsetof(struct ddi_parent_private_data, par_reg),
offsetof(struct ddi_parent_private_data, par_nreg),
sizeof (struct intrspec), /* second pointer */
offsetof(struct ddi_parent_private_data, par_intr),
offsetof(struct ddi_parent_private_data, par_nintr),
sizeof (struct rangespec), /* third pointer */
offsetof(struct ddi_parent_private_data, par_rng),
offsetof(struct ddi_parent_private_data, par_nrng),
0, 0, 0, /* no more pointers */
0, 0, 0
},
{ /* pcmcia format */
"pcic",
sizeof (struct pcmcia_parent_private),
sizeof (struct pcm_regs), /* first pointer */
offsetof(struct pcmcia_parent_private, ppd_reg),
offsetof(struct pcmcia_parent_private, ppd_nreg),
sizeof (struct intrspec), /* second pointer */
offsetof(struct pcmcia_parent_private, ppd_intrspec),
offsetof(struct pcmcia_parent_private, ppd_intr),
0, 0, 0, /* no more pointers */
0, 0, 0,
0, 0, 0
},
{ /* sbus format--it's different on sun4u!! */
"sbus",
sizeof (struct ddi_parent_private_data),
sizeof (struct regspec), /* first pointer */
offsetof(struct ddi_parent_private_data, par_reg),
offsetof(struct ddi_parent_private_data, par_nreg),
sizeof (struct intrspec), /* second pointer */
offsetof(struct ddi_parent_private_data, par_intr),
offsetof(struct ddi_parent_private_data, par_nintr),
sizeof (struct rangespec), /* third pointer */
offsetof(struct ddi_parent_private_data, par_rng),
offsetof(struct ddi_parent_private_data, par_nrng),
0, 0, 0, /* no more pointers */
0, 0, 0
}
};
static struct priv_data prt_priv_data[] = {
{ ppd_format[0].drv_name, obio_print},
{ ppd_format[1].drv_name, pcmcia_print},
{ ppd_format[2].drv_name, sbus_print}
};
static int nprt_priv_data = sizeof (prt_priv_data)/sizeof (struct priv_data);
void
init_priv_data(struct di_priv_data *fetch)
{
/* no driver private data */
fetch->version = DI_PRIVDATA_VERSION_0;
fetch->n_driver = 0;
fetch->driver = NULL;
fetch->n_parent = nprt_priv_data;
fetch->parent = ppd_format;
}
static void
obio_printregs(struct regspec *rp, int ilev)
{
indent_to_level(ilev);
(void) printf(" Bus Type=0x%x, Address=0x%x, Size=0x%x\n",
rp->regspec_bustype, rp->regspec_addr, rp->regspec_size);
}
static void
obio_printranges(struct rangespec *rp, int ilev)
{
indent_to_level(ilev);
(void) printf(" Ch: %.2x,%.8x Pa: %.2x,%.8x, Sz: %x\n",
rp->rng_cbustype, rp->rng_coffset,
rp->rng_bustype, rp->rng_offset,
rp->rng_size);
}
static void
obio_printintr(struct intrspec *ip, int ilev)
{
indent_to_level(ilev);
(void) printf(" Interrupt Priority=0x%x (ipl %d)",
ip->intrspec_pri, INT_IPL(ip->intrspec_pri));
if (ip->intrspec_vec)
(void) printf(", vector=0x%x (%d)",
ip->intrspec_vec, ip->intrspec_vec);
(void) printf("\n");
}
static void
obio_print(uintptr_t data, int ilev)
{
int i, nreg, nrng, nintr;
struct ddi_parent_private_data *dp;
struct regspec *reg;
struct intrspec *intr;
struct rangespec *rng;
dp = (struct ddi_parent_private_data *)data;
#ifdef DEBUG
dbgprintf("obio parent private data: nreg = 0x%x offset = 0x%x"
" nintr = 0x%x offset = 0x%x nrng = 0x%x offset = %x\n",
dp->par_nreg, *((di_off_t *)(&dp->par_reg)),
dp->par_nintr, *((di_off_t *)(&dp->par_intr)),
dp->par_nrng, *((di_off_t *)(&dp->par_rng)));
#endif /* DEBUG */
nreg = dp->par_nreg;
nintr = dp->par_nintr;
nrng = dp->par_nrng;
/*
* All pointers are translated to di_off_t by the devinfo driver.
* This is a private agreement between libdevinfo and prtconf.
*/
if (nreg != 0) {
indent_to_level(ilev);
(void) printf("Register Specifications:\n");
reg = (struct regspec *)(data + *(di_off_t *)(&dp->par_reg));
for (i = 0; i < nreg; ++i)
obio_printregs(reg + i, ilev);
}
if (nrng != 0) {
indent_to_level(ilev);
(void) printf("Range Specifications:\n");
rng = (struct rangespec *)(data + *(di_off_t *)(&dp->par_rng));
for (i = 0; i < nrng; ++i)
obio_printranges(rng + i, ilev);
}
if (nintr != 0) {
indent_to_level(ilev);
(void) printf("Interrupt Specifications:\n");
intr = (struct intrspec *)(data + *(di_off_t *)(&dp->par_intr));
for (i = 0; i < nintr; ++i)
obio_printintr(intr + i, ilev);
}
}
static void
pcmcia_printregs(struct pcm_regs *rp, int ilev)
{
indent_to_level(ilev);
(void) printf(" Phys hi=0x%x, Phys lo=0x%x, Phys len=%x\n",
rp->phys_hi, rp->phys_lo, rp->phys_len);
}
static void
pcmcia_printintr(struct intrspec *ip, int ilev)
{
obio_printintr(ip, ilev);
}
static void
pcmcia_print(uintptr_t data, int ilev)
{
int i, nreg, nintr;
struct pcmcia_parent_private *dp;
struct pcm_regs *reg;
struct intrspec *intr;
dp = (struct pcmcia_parent_private *)data;
#ifdef DEBUG
dbgprintf("pcmcia parent private data: nreg = 0x%x offset = 0x%x"
" intr = 0x%x offset = %x\n",
dp->ppd_nreg, *(di_off_t *)(&dp->ppd_reg),
dp->ppd_intr, *(di_off_t *)(&dp->ppd_intrspec));
#endif /* DEBUG */
nreg = dp->ppd_nreg;
nintr = dp->ppd_intr;
/*
* All pointers are translated to di_off_t by the devinfo driver.
* This is a private agreement between libdevinfo and prtconf.
*/
if (nreg != 0) {
indent_to_level(ilev);
(void) printf("Register Specifications:\n");
reg = (struct pcm_regs *)(data + *(di_off_t *)(&dp->ppd_reg));
for (i = 0; i < nreg; ++i)
pcmcia_printregs(reg + i, ilev);
}
if (nintr != 0) {
indent_to_level(ilev);
(void) printf("Interrupt Specifications:\n");
intr = (struct intrspec *)
(data + *(di_off_t *)(&dp->ppd_intrspec));
for (i = 0; i < nintr; ++i)
pcmcia_printintr(intr + i, ilev);
}
}
static void
sbus_print(uintptr_t data, int ilev)
{
int i, nreg, nrng, nintr;
struct ddi_parent_private_data *dp;
struct regspec *reg;
struct intrspec *intr;
struct rangespec *rng;
dp = (struct ddi_parent_private_data *)data;
#ifdef DEBUG
dbgprintf("sbus parent private data: nreg = 0x%x offset = 0x%x"
" nintr = 0x%x offset = 0x%x nrng = 0x%x offset = %x\n",
dp->par_nreg, *((di_off_t *)(&dp->par_reg)),
dp->par_nintr, *((di_off_t *)(&dp->par_intr)),
dp->par_nrng, *((di_off_t *)(&dp->par_rng)));
#endif /* DEBUG */
nreg = dp->par_nreg;
nintr = dp->par_nintr;
nrng = dp->par_nrng;
/*
* All pointers are translated to di_off_t by the devinfo driver.
* This is a private agreement between libdevinfo and prtconf.
*/
if (nreg != 0) {
indent_to_level(ilev);
(void) printf("Register Specifications:\n");
reg = (struct regspec *)(data + *(di_off_t *)(&dp->par_reg));
for (i = 0; i < nreg; ++i)
obio_printregs(reg + i, ilev);
}
if (nrng != 0) {
indent_to_level(ilev);
(void) printf("Range Specifications:\n");
rng = (struct rangespec *)(data + *(di_off_t *)(&dp->par_rng));
for (i = 0; i < nrng; ++i)
obio_printranges(rng + i, ilev);
}
/*
* To print interrupt property for children of sbus on sun4u requires
* definitions in sysiosbus.h.
*
* We can't #include <sys/sysiosbus.h> to have the build work on
* non sun4u machines. It's not right either to
* #include "../../uts/sun4u/sys/sysiosbus.h"
* As a result, we will not print the information.
*/
if ((nintr != 0) && (strcmp(opts.o_uts.machine, "sun4u") != 0)) {
indent_to_level(ilev);
(void) printf("Interrupt Specifications:\n");
for (i = 0; i < nintr; ++i) {
intr = (struct intrspec *)
(data + *(di_off_t *)(&dp->par_intr));
obio_printintr(intr + i, ilev);
}
}
}
static struct priv_data *
match_priv_data(di_node_t node)
{
int i;
size_t len;
char *drv_name, *tmp;
di_node_t parent;
struct priv_data *pdp;
if ((parent = di_parent_node(node)) == DI_NODE_NIL)
return (NULL);
if ((drv_name = di_driver_name(parent)) == NULL)
return (NULL);
pdp = prt_priv_data;
len = strlen(drv_name);
for (i = 0; i < nprt_priv_data; ++i, ++pdp) {
tmp = pdp->drv_name;
while (tmp && (*tmp != '\0')) {
if (strncmp(tmp, drv_name, len) == 0) {
#ifdef DEBUG
dbgprintf("matched parent private data"
" at Node <%s> parent driver <%s>\n",
di_node_name(node), drv_name);
#endif /* DEBUG */
return (pdp);
}
/*
* skip a white space
*/
if ((tmp = strchr(tmp, ' ')) != NULL)
tmp++;
}
}
return (NULL);
}
void
dump_priv_data(int ilev, di_node_t node)
{
uintptr_t priv;
struct priv_data *pdp;
if ((priv = (uintptr_t)di_parent_private_data(node)) == (uintptr_t)NULL)
return;
if ((pdp = match_priv_data(node)) == NULL) {
#ifdef DEBUG
dbgprintf("Error: parent private data format unknown\n");
#endif /* DEBUG */
return;
}
pdp->pd_print(priv, ilev);
/* ignore driver private data for now */
}
/*
* Print vendor ID and device ID for PCI devices
*/
void
print_pciid(const char *type, uint16_t vid, uint16_t did, pcidb_hdl_t *pci)
{
const char *vstr, *dstr;
(void) printf(" (%s%x,%x)", type, vid, did);
vstr = "unknown vendor";
dstr = "unknown device";
if (pci != NULL) {
pcidb_vendor_t *vend = NULL;
pcidb_device_t *dev = NULL;
vend = pcidb_lookup_vendor(pci, vid);
if (vend != NULL) {
vstr = pcidb_vendor_name(vend);
dev = pcidb_lookup_device_by_vendor(vend, did);
}
if (dev != NULL) {
dstr = pcidb_device_name(dev);
}
}
(void) printf(" [%s %s]", vstr, dstr);
}
/*
* 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 (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2011, Joyent, Inc. All rights reserved.
* Copyright (c) 2019 Peter Tribble.
* Copyright (c) 2022 Sachidananda Urs <sacchi@gmail.com>
* Copyright 2022 Oxide Computer Company
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <sys/systeminfo.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include "prtconf.h"
struct prt_opts opts;
struct prt_dbg dbg;
static char new_path[MAXPATHLEN];
#define INDENT_LENGTH 4
static const char *usage =
"%s [ -F | -m | -V | -x | -abcdvpPD ] [ <device_path > ]\n";
static void
setpname(const char *name)
{
char *p;
if (name == NULL)
opts.o_progname = "prtconf";
else if ((p = strrchr(name, '/')) != NULL)
opts.o_progname = (const char *) p + 1;
else
opts.o_progname = name;
}
/*PRINTFLIKE1*/
void
dbgprintf(const char *fmt, ...)
{
if (dbg.d_debug) {
va_list ap;
va_start(ap, fmt);
(void) vfprintf(stderr, fmt, ap);
va_end(ap);
}
}
void
indent_to_level(int ilev)
{
(void) printf("%*s", INDENT_LENGTH * ilev, "");
}
/*
* debug version has two more flags:
* -L force load driver
* -M: print per driver list
*/
#ifdef DEBUG
static const char *optstring = "abcdDvVxmpPFf:M:LuC";
#else
static const char *optstring = "abcdDvVxmpPFf:uC";
#endif /* DEBUG */
int
main(int argc, char *argv[])
{
long pagesize, npages;
int c, ret;
char hw_provider[SYS_NMLN];
setpname(argv[0]);
opts.o_promdev = "/dev/openprom";
while ((c = getopt(argc, argv, optstring)) != -1) {
switch (c) {
case 'a':
++opts.o_ancestors;
break;
case 'b':
++opts.o_productinfo;
break;
case 'c':
++opts.o_children;
break;
case 'd':
++opts.o_pciid;
break;
case 'D':
++opts.o_drv_name;
break;
case 'v':
++opts.o_verbose;
break;
case 'm':
++opts.o_memory;
break;
case 'p':
++opts.o_prominfo;
break;
case 'f':
opts.o_promdev = optarg;
break;
case 'V':
++opts.o_promversion;
break;
case 'x':
++opts.o_prom_ready64;
break;
case 'F':
++opts.o_fbname;
++opts.o_noheader;
break;
case 'P':
++opts.o_pseudodevs;
break;
case 'C':
++opts.o_forcecache;
break;
#ifdef DEBUG
case 'M':
dbg.d_drivername = optarg;
++dbg.d_bydriver;
break;
case 'L':
++dbg.d_forceload;
break;
#endif /* DEBUG */
default:
(void) fprintf(stderr, usage, opts.o_progname);
return (1);
}
}
(void) uname(&opts.o_uts);
if (opts.o_verbose || opts.o_pciid) {
opts.o_pcidb = pcidb_open(PCIDB_VERSION);
if (opts.o_pcidb == NULL) {
warn("pcidb facility not available, PCI names will "
"not be translated");
}
}
if (opts.o_fbname)
return (do_fbname());
if (opts.o_promversion)
return (do_promversion());
if (opts.o_prom_ready64)
return (0);
if (opts.o_productinfo)
return (do_productinfo());
opts.o_devices_path = NULL;
opts.o_devt = DDI_DEV_T_NONE;
opts.o_target = 0;
if (optind < argc) {
struct stat sinfo;
char *path = argv[optind];
int error;
if (opts.o_prominfo) {
/* PROM tree cannot be used with path */
(void) fprintf(stderr, "%s: path and -p option are "
"mutually exclusive\n", opts.o_progname);
return (1);
}
if (strlen(path) >= MAXPATHLEN) {
(void) fprintf(stderr, "%s: "
"path specified is too long\n", opts.o_progname);
return (1);
}
if ((error = stat(path, &sinfo)) != 0) {
/* an invalid path was specified */
(void) fprintf(stderr, "%s: invalid path specified\n",
opts.o_progname);
return (1);
} else if (((sinfo.st_mode & S_IFMT) == S_IFCHR) ||
((sinfo.st_mode & S_IFMT) == S_IFBLK)) {
opts.o_devt = sinfo.st_rdev;
error = 0;
} else if ((sinfo.st_mode & S_IFMT) == S_IFDIR) {
size_t len, plen;
if (realpath(path, new_path) == NULL) {
(void) fprintf(stderr, "%s: invalid device"
" path specified\n",
opts.o_progname);
return (1);
}
len = strlen(new_path);
plen = strlen("/devices");
if (len < plen) {
/* This is not a valid /devices path */
error = 1;
} else if ((len == plen) &&
(strcmp(new_path, "/devices") == 0)) {
/* /devices is the root nexus */
opts.o_devices_path = "/";
error = 0;
} else if (strncmp(new_path, "/devices/", plen + 1)) {
/* This is not a valid /devices path */
error = 1;
} else {
/* a /devices/ path was specified */
opts.o_devices_path = new_path + plen;
error = 0;
}
} else {
/* an invalid device path was specified */
error = 1;
}
if (error) {
(void) fprintf(stderr, "%s: "
"invalid device path specified\n",
opts.o_progname);
return (1);
}
opts.o_target = 1;
}
if ((opts.o_ancestors || opts.o_children) && (!opts.o_target)) {
(void) fprintf(stderr, "%s: options require a device path\n",
opts.o_progname);
return (1);
}
if (opts.o_target) {
prtconf_devinfo();
return (0);
}
if (!opts.o_memory) {
ret = sysinfo(SI_HW_PROVIDER, hw_provider,
sizeof (hw_provider));
/*
* If 0 bytes are returned (the system returns '1', for the \0),
* we're probably on x86, default to "Unknown Hardware Vendor".
*/
if (ret <= 1) {
(void) strncpy(hw_provider, "Unknown Hardware Vendor",
sizeof (hw_provider));
}
(void) printf("System Configuration: %s %s\n", hw_provider,
opts.o_uts.machine);
}
pagesize = sysconf(_SC_PAGESIZE);
npages = sysconf(_SC_PHYS_PAGES);
if (pagesize == -1 || npages == -1) {
if (opts.o_memory) {
(void) printf("0\n");
return (1);
} else {
(void) printf("Memory size: unable to determine\n");
}
} else {
const int64_t mbyte = 1024 * 1024;
int64_t ii = (int64_t)pagesize * npages;
if (opts.o_memory) {
(void) printf("%ld\n", (long)((ii+mbyte-1) / mbyte));
return (0);
} else {
(void) printf("Memory size: %ld Megabytes\n",
(long)((ii+mbyte-1) / mbyte));
}
}
if (opts.o_prominfo) {
(void) printf("System Peripherals (PROM Nodes):\n\n");
if (do_prominfo() == 0)
return (0);
(void) fprintf(stderr, "%s: Defaulting to non-PROM mode...\n",
opts.o_progname);
}
(void) printf("System Peripherals (Software Nodes):\n\n");
(void) prtconf_devinfo();
return (0);
}
/*
* 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.
* Copyright (c) 2012 Joyent, Inc. All rights reserved.
* Copyright (c) 2019 Peter Tribble.
*/
#ifndef _PRT_CONF_H
#define _PRT_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
#include <libdevinfo.h>
#include <pcidb.h>
#include <sys/utsname.h>
extern void init_priv_data(struct di_priv_data *);
extern void dump_priv_data(int, di_node_t);
extern void print_pciid(const char *, uint16_t, uint16_t, pcidb_hdl_t *);
extern void indent_to_level(int);
extern void prtconf_devinfo();
extern int do_fbname();
extern int do_promversion();
extern int do_prominfo();
void indent_to_level(int);
extern int do_productinfo();
extern void dbgprintf(const char *, ...);
struct prt_opts {
int o_verbose;
int o_drv_name;
int o_pseudodevs;
int o_fbname;
int o_memory;
int o_noheader;
int o_prominfo;
int o_productinfo;
int o_promversion;
int o_prom_ready64;
int o_forcecache;
char *o_devices_path;
dev_t o_devt;
int o_target;
int o_ancestors;
int o_children;
int o_pciid;
const char *o_promdev;
const char *o_progname;
struct utsname o_uts;
pcidb_hdl_t *o_pcidb;
};
struct prt_dbg {
int d_debug;
int d_bydriver;
int d_forceload;
char *d_drivername;
};
extern struct prt_opts opts;
extern struct prt_dbg dbg;
#ifdef __cplusplus
}
#endif
#endif /* _PRT_CONF_H */
|