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
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
|
/*
* 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.
*/
/*
* IOSRAM leaf driver to SBBC nexus driver. This driver is used
* by Starcat Domain SW to read/write from/to the IO sram.
*/
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/ddi_impldefs.h>
#include <sys/obpdefs.h>
#include <sys/promif.h>
#include <sys/prom_plat.h>
#include <sys/cmn_err.h>
#include <sys/conf.h> /* req. by dev_ops flags MTSAFE etc. */
#include <sys/modctl.h> /* for modldrv */
#include <sys/stat.h> /* ddi_create_minor_node S_IFCHR */
#include <sys/errno.h>
#include <sys/kmem.h>
#include <sys/kstat.h>
#include <sys/debug.h>
#include <sys/axq.h>
#include <sys/iosramreg.h>
#include <sys/iosramio.h>
#include <sys/iosramvar.h>
#if defined(DEBUG)
int iosram_debug = 0;
static void iosram_dprintf(const char *fmt, ...);
#define DPRINTF(level, arg) \
{ if (iosram_debug >= level) iosram_dprintf arg; }
#else /* !DEBUG */
#define DPRINTF(level, arg)
#endif /* !DEBUG */
/*
* IOSRAM module global state
*/
static void *iosramsoft_statep; /* IOSRAM state pointer */
static kmutex_t iosram_mutex; /* mutex lock */
static iosram_chunk_t *chunks = NULL; /* array of TOC entries */
static int nchunks = 0; /* # of TOC entries */
static iosram_chunk_t *iosram_hashtab[IOSRAM_HASHSZ]; /* key hash table */
static kcondvar_t iosram_tswitch_wait; /* tunnel switch wait cv */
static int iosram_tswitch_wakeup = 0; /* flag indicationg one or */
/* more threads waiting on */
/* iosram_tswitch_wait cv */
static int iosram_tswitch_active = 0; /* tunnel switch active flag */
static int iosram_tswitch_aborted = 0; /* tunnel switch abort flag */
static clock_t iosram_tswitch_tstamp = 0; /* lbolt of last tswitch end */
static kcondvar_t iosram_rw_wait; /* read/write wait cv */
static int iosram_rw_wakeup = 0; /* flag indicationg one or */
/* more threads waiting on */
/* iosram_rw_wait cv */
static int iosram_rw_active = 0; /* # threads accessing IOSRAM */
#if defined(DEBUG)
static int iosram_rw_active_max = 0;
#endif
static struct iosramsoft *iosram_new_master = NULL; /* new tunnel target */
static struct iosramsoft *iosram_master = NULL; /* master tunnel */
static struct iosramsoft *iosram_instances = NULL; /* list of softstates */
static ddi_acc_handle_t iosram_handle = NULL; /* master IOSRAM map handle */
static void (*iosram_hdrchange_handler)() = NULL;
#if IOSRAM_STATS
static struct iosram_stat iosram_stats; /* IOSRAM statistics */
static void iosram_print_stats(); /* forward declaration */
#endif /* IOSRAM_STATS */
#if IOSRAM_LOG
kmutex_t iosram_log_mutex;
int iosram_log_level = 1;
int iosram_log_print = 0; /* print log when recorded */
uint32_t iosram_logseq;
iosram_log_t iosram_logbuf[IOSRAM_MAXLOG];
static void iosram_print_log(int cnt); /* forward declaration */
#endif /* IOSRAM_LOG */
/* driver entry point fn definitions */
static int iosram_open(dev_t *, int, int, cred_t *);
static int iosram_close(dev_t, int, int, cred_t *);
static int iosram_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
/* configuration entry point fn definitions */
static int iosram_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
static int iosram_attach(dev_info_t *, ddi_attach_cmd_t);
static int iosram_detach(dev_info_t *, ddi_detach_cmd_t);
/* forward declaractions */
static iosram_chunk_t *iosram_find_chunk(uint32_t key);
static void iosram_set_master(struct iosramsoft *softp);
static int iosram_is_chosen(struct iosramsoft *softp);
static int iosram_tunnel_capable(struct iosramsoft *softp);
static int iosram_read_toc(struct iosramsoft *softp);
static void iosram_init_hashtab(void);
static void iosram_update_addrs(struct iosramsoft *softp);
static int iosram_setup_map(struct iosramsoft *softp);
static void iosram_remove_map(struct iosramsoft *softp);
static int iosram_add_intr(iosramsoft_t *);
static int iosram_remove_intr(iosramsoft_t *);
static void iosram_add_instance(struct iosramsoft *softp);
static void iosram_remove_instance(int instance);
static int iosram_switch_tunnel(iosramsoft_t *softp);
static void iosram_abort_tswitch();
#if defined(DEBUG)
/* forward declaractions for debugging */
static int iosram_get_keys(iosram_toc_entry_t *buf, uint32_t *len);
static void iosram_print_cback();
static void iosram_print_state(int);
static void iosram_print_flags();
#endif
/*
* cb_ops
*/
static struct cb_ops iosram_cb_ops = {
iosram_open, /* cb_open */
iosram_close, /* cb_close */
nodev, /* cb_strategy */
nodev, /* cb_print */
nodev, /* cb_dump */
nodev, /* cb_read */
nodev, /* cb_write */
iosram_ioctl, /* cb_ioctl */
nodev, /* cb_devmap */
nodev, /* cb_mmap */
nodev, /* cb_segmap */
nochpoll, /* cb_chpoll */
ddi_prop_op, /* cb_prop_op */
NULL, /* cb_stream */
(int)(D_NEW | D_MP | D_HOTPLUG) /* cb_flag */
};
/*
* Declare ops vectors for auto configuration.
*/
struct dev_ops iosram_ops = {
DEVO_REV, /* devo_rev */
0, /* devo_refcnt */
iosram_getinfo, /* devo_getinfo */
nulldev, /* devo_identify */
nulldev, /* devo_probe */
iosram_attach, /* devo_attach */
iosram_detach, /* devo_detach */
nodev, /* devo_reset */
&iosram_cb_ops, /* devo_cb_ops */
(struct bus_ops *)NULL, /* devo_bus_ops */
nulldev, /* devo_power */
ddi_quiesce_not_supported, /* devo_quiesce */
};
/*
* Loadable module support.
*/
extern struct mod_ops mod_driverops;
static struct modldrv iosrammodldrv = {
&mod_driverops, /* type of module - driver */
"IOSRAM Leaf driver",
&iosram_ops,
};
static struct modlinkage iosrammodlinkage = {
MODREV_1,
&iosrammodldrv,
NULL
};
int
_init(void)
{
int error;
int i;
mutex_init(&iosram_mutex, NULL, MUTEX_DRIVER, (void *)NULL);
cv_init(&iosram_tswitch_wait, NULL, CV_DRIVER, NULL);
cv_init(&iosram_rw_wait, NULL, CV_DRIVER, NULL);
#if defined(IOSRAM_LOG)
mutex_init(&iosram_log_mutex, NULL, MUTEX_DRIVER, (void *)NULL);
#endif
DPRINTF(1, ("_init:IOSRAM\n"));
for (i = 0; i < IOSRAM_HASHSZ; i++) {
iosram_hashtab[i] = NULL;
}
if ((error = ddi_soft_state_init(&iosramsoft_statep,
sizeof (struct iosramsoft), 1)) != 0) {
goto failed;
}
if ((error = mod_install(&iosrammodlinkage)) != 0) {
ddi_soft_state_fini(&iosramsoft_statep);
goto failed;
}
IOSRAMLOG(0, "_init:IOSRAM ... error:%d statep:%p\n",
error, iosramsoft_statep, NULL, NULL);
return (error);
failed:
cv_destroy(&iosram_tswitch_wait);
cv_destroy(&iosram_rw_wait);
mutex_destroy(&iosram_mutex);
#if defined(IOSRAM_LOG)
mutex_destroy(&iosram_log_mutex);
#endif
IOSRAMLOG(0, "_init:IOSRAM ... error:%d statep:%p\n",
error, iosramsoft_statep, NULL, NULL);
return (error);
}
int
_fini(void)
{
#ifndef DEBUG
return (EBUSY);
#else /* !DEBUG */
int error;
if ((error = mod_remove(&iosrammodlinkage)) == 0) {
ddi_soft_state_fini(&iosramsoft_statep);
cv_destroy(&iosram_tswitch_wait);
cv_destroy(&iosram_rw_wait);
mutex_destroy(&iosram_mutex);
#if defined(IOSRAM_LOG)
mutex_destroy(&iosram_log_mutex);
#endif
}
DPRINTF(1, ("_fini:IOSRAM error:%d\n", error));
return (error);
#endif /* !DEBUG */
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&iosrammodlinkage, modinfop));
}
static int
iosram_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
int instance;
int propval;
int length;
char name[32];
struct iosramsoft *softp;
instance = ddi_get_instance(dip);
DPRINTF(1, ("iosram(%d): attach dip:%p\n", instance));
IOSRAMLOG(1, "ATTACH: dip:%p instance %d ... start\n",
dip, instance, NULL, NULL);
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
if (!(softp = ddi_get_soft_state(iosramsoft_statep,
instance))) {
return (DDI_FAILURE);
}
mutex_enter(&iosram_mutex);
mutex_enter(&softp->intr_mutex);
if (!softp->suspended) {
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
return (DDI_FAILURE);
}
softp->suspended = 0;
/*
* enable SBBC interrupts if SBBC is mapped in
* restore the value saved during detach
*/
if (softp->sbbc_region) {
ddi_put32(softp->sbbc_handle,
&(softp->sbbc_region->int_enable.reg),
softp->int_enable_sav);
}
/*
* Trigger soft interrupt handler to process any pending
* interrupts.
*/
if (softp->intr_pending && !softp->intr_busy &&
(softp->softintr_id != NULL)) {
ddi_trigger_softintr(softp->softintr_id);
}
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
if (ddi_soft_state_zalloc(iosramsoft_statep, instance) != 0) {
return (DDI_FAILURE);
}
if ((softp = ddi_get_soft_state(iosramsoft_statep, instance)) == NULL) {
return (DDI_FAILURE);
}
softp->dip = dip;
softp->instance = instance;
softp->sbbc_region = NULL;
/*
* If this instance is not tunnel capable, we don't attach it.
*/
if (iosram_tunnel_capable(softp) == 0) {
DPRINTF(1, ("iosram(%d): not tunnel_capable\n", instance));
IOSRAMLOG(1, "ATTACH(%d): not tunnel_capable\n", instance, NULL,
NULL, NULL);
goto attach_fail;
}
/*
* Need to create an "interrupt-priorities" property to define the PIL
* to be used with the interrupt service routine.
*/
if (ddi_getproplen(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
"interrupt-priorities", &length) == DDI_PROP_NOT_FOUND) {
DPRINTF(1, ("iosram(%d): creating interrupt priority property",
instance));
propval = IOSRAM_PIL;
if (ddi_prop_create(DDI_DEV_T_NONE, dip, 0,
"interrupt-priorities", (caddr_t)&propval, sizeof (propval))
!= DDI_PROP_SUCCESS) {
cmn_err(CE_WARN,
"iosram_attach: failed to create property");
goto attach_fail;
}
}
/*
* Get interrupts cookies and initialize per-instance mutexes
*/
if (ddi_get_iblock_cookie(softp->dip, 0, &softp->real_iblk)
!= DDI_SUCCESS) {
IOSRAMLOG(1, "ATTACH(%d): cannot get soft intr cookie\n",
instance, NULL, NULL, NULL);
goto attach_fail;
}
mutex_init(&softp->intr_mutex, NULL, MUTEX_DRIVER,
(void *)softp->real_iblk);
/*
* Add this instance to the iosram_instances list so that it can be used
* for tunnel in future.
*/
mutex_enter(&iosram_mutex);
softp->state = IOSRAM_STATE_INIT;
iosram_add_instance(softp);
/*
* If this is the chosen IOSRAM and there is no master IOSRAM yet, then
* let's set this instance as the master.
*/
if (iosram_master == NULL && iosram_is_chosen(softp)) {
iosram_switch_tunnel(softp);
/*
* XXX Do we need to panic if unable to setup master IOSRAM?
*/
if (iosram_master == NULL) {
cmn_err(CE_WARN,
"iosram(%d): can't setup master tunnel\n",
instance);
softp->state = 0;
iosram_remove_instance(softp->instance);
mutex_exit(&iosram_mutex);
mutex_destroy(&softp->intr_mutex);
goto attach_fail;
}
}
mutex_exit(&iosram_mutex);
/*
* Create minor node
*/
(void) sprintf(name, "iosram%d", instance);
if (ddi_create_minor_node(dip, name, S_IFCHR, instance, NULL, NULL) ==
DDI_FAILURE) {
/*
* Minor node seems to be needed only for debugging purposes.
* Therefore, there is no need to fail this attach request.
* Simply print a message out.
*/
cmn_err(CE_NOTE, "!iosram(%d): can't create minor node\n",
instance);
}
ddi_report_dev(dip);
DPRINTF(1, ("iosram_attach(%d): success.\n", instance));
IOSRAMLOG(1, "ATTACH: dip:%p instance:%d ... success softp:%p\n",
dip, instance, softp, NULL);
return (DDI_SUCCESS);
attach_fail:
DPRINTF(1, ("iosram_attach(%d):failed.\n", instance));
IOSRAMLOG(1, "ATTACH: dip:%p instance:%d ... failed.\n",
dip, instance, NULL, NULL);
ddi_soft_state_free(iosramsoft_statep, instance);
return (DDI_FAILURE);
}
static int
iosram_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
{
int instance;
struct iosramsoft *softp;
instance = ddi_get_instance(dip);
if (!(softp = ddi_get_soft_state(iosramsoft_statep, instance))) {
return (DDI_FAILURE);
}
IOSRAMLOG(1, "DETACH: dip:%p instance %d softp:%p\n",
dip, instance, softp, NULL);
switch (cmd) {
case DDI_DETACH:
break;
case DDI_SUSPEND:
mutex_enter(&iosram_mutex);
mutex_enter(&softp->intr_mutex);
if (softp->suspended) {
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
return (DDI_FAILURE);
}
softp->suspended = 1;
/*
* Disable SBBC interrupts if SBBC is mapped in
*/
if (softp->sbbc_region) {
/* save current interrupt enable register */
softp->int_enable_sav = ddi_get32(softp->sbbc_handle,
&(softp->sbbc_region->int_enable.reg));
ddi_put32(softp->sbbc_handle,
&(softp->sbbc_region->int_enable.reg), 0x0);
}
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
/*
* Indicate that this instance is being detached so that this instance
* does not become a target for tunnel switch in future.
*/
mutex_enter(&iosram_mutex);
softp->state |= IOSRAM_STATE_DETACH;
/*
* If this instance is currently the master or the target of the tunnel
* switch, then we need to wait and switch tunnel, if necessary.
*/
if (iosram_master == softp || (softp->state & IOSRAM_STATE_TSWITCH)) {
mutex_exit(&iosram_mutex);
iosram_switchfrom(instance);
mutex_enter(&iosram_mutex);
}
/*
* If the tunnel switch is in progress and we are the master or target
* of tunnel relocation, then we can't detach this instance right now.
*/
if (softp->state & IOSRAM_STATE_TSWITCH) {
softp->state &= ~IOSRAM_STATE_DETACH;
mutex_exit(&iosram_mutex);
return (DDI_FAILURE);
}
/*
* We can't allow master IOSRAM to be detached as we won't be able to
* communicate otherwise.
*/
if (iosram_master == softp) {
softp->state &= ~IOSRAM_STATE_DETACH;
mutex_exit(&iosram_mutex);
return (DDI_FAILURE);
}
/*
* Now remove our instance from the iosram_instances list.
*/
iosram_remove_instance(instance);
mutex_exit(&iosram_mutex);
/*
* Instances should only ever be mapped if they are the master and/or
* participating in a tunnel switch. Neither should be the case here.
*/
ASSERT((softp->state & IOSRAM_STATE_MAPPED) == 0);
/*
* Destroy per-instance mutexes
*/
mutex_destroy(&softp->intr_mutex);
ddi_remove_minor_node(dip, NULL);
/*
* Finally remove our soft state structure
*/
ddi_soft_state_free(iosramsoft_statep, instance);
return (DDI_SUCCESS);
}
/* ARGSUSED0 */
static int
iosram_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
void **result)
{
dev_t dev = (dev_t)arg;
struct iosramsoft *softp;
int instance, ret;
instance = getminor(dev);
IOSRAMLOG(2, "GETINFO: dip:%x instance %d dev:%x infocmd:%x\n",
dip, instance, dev, infocmd);
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
softp = ddi_get_soft_state(iosramsoft_statep, instance);
if (softp == NULL) {
*result = NULL;
ret = DDI_FAILURE;
} else {
*result = softp->dip;
ret = DDI_SUCCESS;
}
break;
case DDI_INFO_DEVT2INSTANCE:
*result = (void *)(uintptr_t)instance;
ret = DDI_SUCCESS;
break;
default:
ret = DDI_FAILURE;
break;
}
return (ret);
}
/*ARGSUSED1*/
static int
iosram_open(dev_t *dev, int flag, int otype, cred_t *credp)
{
struct iosramsoft *softp;
int instance;
instance = getminor(*dev);
softp = ddi_get_soft_state(iosramsoft_statep, instance);
if (softp == NULL) {
return (ENXIO);
}
IOSRAMLOG(1, "OPEN: dev:%p otype:%x ... instance:%d softp:%p\n",
*dev, otype, softp->instance, softp);
return (0);
}
/*ARGSUSED1*/
static int
iosram_close(dev_t dev, int flag, int otype, cred_t *credp)
{
struct iosramsoft *softp;
int instance;
instance = getminor(dev);
softp = ddi_get_soft_state(iosramsoft_statep, instance);
if (softp == NULL) {
return (ENXIO);
}
IOSRAMLOG(1, "CLOSE: dev:%p otype:%x ... instance:%d softp:%p\n",
dev, otype, softp->instance, softp);
return (0);
}
int
iosram_rd(uint32_t key, uint32_t off, uint32_t len, caddr_t dptr)
{
iosram_chunk_t *chunkp;
uint32_t chunk_len;
uint8_t *iosramp;
ddi_acc_handle_t handle;
int boff;
union {
uchar_t cbuf[UINT32SZ];
uint32_t data;
} word;
int error = 0;
uint8_t *buf = (uint8_t *)dptr;
/*
* We try to read from the IOSRAM using double word or word access
* provided both "off" and "buf" are (or can be) double word or word
* aligned. Othewise, we try to align the "off" to a word boundary and
* then try to read data from the IOSRAM using word access, but store it
* into buf buffer using byte access.
*
* If the leading/trailing portion of the IOSRAM data is not word
* aligned, it will always be copied using byte access.
*/
IOSRAMLOG(1, "RD: key: 0x%x off:%x len:%x buf:%p\n",
key, off, len, buf);
/*
* Acquire lock and look for the requested chunk. If it exists, make
* sure the requested read is within the chunk's bounds and no tunnel
* switch is active.
*/
mutex_enter(&iosram_mutex);
chunkp = iosram_find_chunk(key);
chunk_len = (chunkp != NULL) ? chunkp->toc_data.len : 0;
if (iosram_master == NULL) {
error = EIO;
} else if (chunkp == NULL) {
error = EINVAL;
} else if ((off >= chunk_len) || (len > chunk_len) ||
((off + len) > chunk_len)) {
error = EMSGSIZE;
} else if (iosram_tswitch_active) {
error = EAGAIN;
}
if (error) {
mutex_exit(&iosram_mutex);
return (error);
}
/*
* Bump reference count to indicate #thread accessing IOSRAM and release
* the lock.
*/
iosram_rw_active++;
#if defined(DEBUG)
if (iosram_rw_active > iosram_rw_active_max) {
iosram_rw_active_max = iosram_rw_active;
}
#endif
mutex_exit(&iosram_mutex);
IOSRAM_STAT(read);
IOSRAM_STAT_ADD(bread, len);
/* Get starting address and map handle */
iosramp = chunkp->basep + off;
handle = iosram_handle;
/*
* Align the off to word boundary and then try reading/writing data
* using double word or word access.
*/
if ((boff = ((uintptr_t)iosramp & (UINT32SZ - 1))) != 0) {
int cnt = UINT32SZ - boff;
if (cnt > len) {
cnt = len;
}
IOSRAMLOG(2,
"RD: align rep_get8(buf:%p sramp:%p cnt:%x) len:%x\n",
buf, iosramp, cnt, len);
ddi_rep_get8(handle, buf, iosramp, cnt, DDI_DEV_AUTOINCR);
buf += cnt;
iosramp += cnt;
len -= cnt;
}
if ((len >= UINT64SZ) &&
((((uintptr_t)iosramp | (uintptr_t)buf) & (UINT64SZ - 1)) == 0)) {
/*
* Both source and destination are double word aligned
*/
int cnt = len/UINT64SZ;
IOSRAMLOG(2,
"RD: rep_get64(buf:%p sramp:%p cnt:%x) len:%x\n",
buf, iosramp, cnt, len);
ddi_rep_get64(handle, (uint64_t *)buf, (uint64_t *)iosramp,
cnt, DDI_DEV_AUTOINCR);
iosramp += cnt * UINT64SZ;
buf += cnt * UINT64SZ;
len -= cnt * UINT64SZ;
/*
* read remaining data using word and byte access
*/
if (len >= UINT32SZ) {
IOSRAMLOG(2,
"RD: get32(buf:%p sramp:%p) len:%x\n",
buf, iosramp, len, NULL);
*(uint32_t *)buf = ddi_get32(handle,
(uint32_t *)iosramp);
iosramp += UINT32SZ;
buf += UINT32SZ;
len -= UINT32SZ;
}
if (len != 0) {
ddi_rep_get8(handle, buf, iosramp, len,
DDI_DEV_AUTOINCR);
}
} else if ((len >= UINT32SZ) &&
((((uintptr_t)iosramp | (uintptr_t)buf) & (UINT32SZ - 1)) == 0)) {
/*
* Both source and destination are word aligned
*/
int cnt = len/UINT32SZ;
IOSRAMLOG(2,
"RD: rep_get32(buf:%p sramp:%p cnt:%x) len:%x\n",
buf, iosramp, cnt, len);
ddi_rep_get32(handle, (uint32_t *)buf, (uint32_t *)iosramp,
cnt, DDI_DEV_AUTOINCR);
iosramp += cnt * UINT32SZ;
buf += cnt * UINT32SZ;
len -= cnt * UINT32SZ;
/*
* copy the remainder using byte access
*/
if (len != 0) {
ddi_rep_get8(handle, buf, iosramp, len,
DDI_DEV_AUTOINCR);
}
} else if (len != 0) {
/*
* We know that the "off" (i.e. iosramp) is at least word
* aligned. We need to read IOSRAM word at a time and copy it
* byte at a time.
*/
ASSERT(((uintptr_t)iosramp & (UINT32SZ - 1)) == 0);
IOSRAMLOG(2,
"RD: unaligned get32(buf:%p sramp:%p) len:%x\n",
buf, iosramp, len, NULL);
for (; len >= UINT32SZ; len -= UINT32SZ, iosramp += UINT32SZ) {
word.data = ddi_get32(handle, (uint32_t *)iosramp);
*buf++ = word.cbuf[0];
*buf++ = word.cbuf[1];
*buf++ = word.cbuf[2];
*buf++ = word.cbuf[3];
}
/*
* copy the remaining data using byte access
*/
if (len != 0) {
ddi_rep_get8(handle, buf, iosramp, len,
DDI_DEV_AUTOINCR);
}
}
/*
* Reacquire mutex lock, decrement refcnt and if refcnt is 0 and any
* threads are waiting for r/w activity to complete, wake them up.
*/
mutex_enter(&iosram_mutex);
ASSERT(iosram_rw_active > 0);
if ((--iosram_rw_active == 0) && iosram_rw_wakeup) {
iosram_rw_wakeup = 0;
cv_broadcast(&iosram_rw_wait);
}
mutex_exit(&iosram_mutex);
return (error);
}
/*
* _iosram_write(key, off, len, dptr, force)
* Internal common routine to write to the IOSRAM.
*/
static int
_iosram_write(uint32_t key, uint32_t off, uint32_t len, caddr_t dptr, int force)
{
iosram_chunk_t *chunkp;
uint32_t chunk_len;
uint8_t *iosramp;
ddi_acc_handle_t handle;
int boff;
union {
uint8_t cbuf[UINT32SZ];
uint32_t data;
} word;
int error = 0;
uint8_t *buf = (uint8_t *)dptr;
/*
* We try to write to the IOSRAM using double word or word access
* provided both "off" and "buf" are (or can be) double word or word
* aligned. Othewise, we try to align the "off" to a word boundary and
* then try to write data to the IOSRAM using word access, but read data
* from the buf buffer using byte access.
*
* If the leading/trailing portion of the IOSRAM data is not word
* aligned, it will always be written using byte access.
*/
IOSRAMLOG(1, "WR: key: 0x%x off:%x len:%x buf:%p\n",
key, off, len, buf);
/*
* Acquire lock and look for the requested chunk. If it exists, make
* sure the requested write is within the chunk's bounds and no tunnel
* switch is active.
*/
mutex_enter(&iosram_mutex);
chunkp = iosram_find_chunk(key);
chunk_len = (chunkp != NULL) ? chunkp->toc_data.len : 0;
if (iosram_master == NULL) {
error = EIO;
} else if (chunkp == NULL) {
error = EINVAL;
} else if ((off >= chunk_len) || (len > chunk_len) ||
((off+len) > chunk_len)) {
error = EMSGSIZE;
} else if (iosram_tswitch_active && !force) {
error = EAGAIN;
}
if (error) {
mutex_exit(&iosram_mutex);
return (error);
}
/*
* If this is a forced write and there's a tunnel switch in progress,
* abort the switch.
*/
if (iosram_tswitch_active && force) {
cmn_err(CE_NOTE, "!iosram: Aborting tswitch on force_write");
iosram_abort_tswitch();
}
/*
* Bump reference count to indicate #thread accessing IOSRAM
* and release the lock.
*/
iosram_rw_active++;
#if defined(DEBUG)
if (iosram_rw_active > iosram_rw_active_max) {
iosram_rw_active_max = iosram_rw_active;
}
#endif
mutex_exit(&iosram_mutex);
IOSRAM_STAT(write);
IOSRAM_STAT_ADD(bwrite, len);
/* Get starting address and map handle */
iosramp = chunkp->basep + off;
handle = iosram_handle;
/*
* Align the off to word boundary and then try reading/writing
* data using double word or word access.
*/
if ((boff = ((uintptr_t)iosramp & (UINT32SZ - 1))) != 0) {
int cnt = UINT32SZ - boff;
if (cnt > len) {
cnt = len;
}
IOSRAMLOG(2,
"WR: align rep_put8(buf:%p sramp:%p cnt:%x) len:%x\n",
buf, iosramp, cnt, len);
ddi_rep_put8(handle, buf, iosramp, cnt, DDI_DEV_AUTOINCR);
buf += cnt;
iosramp += cnt;
len -= cnt;
}
if ((len >= UINT64SZ) &&
((((uintptr_t)iosramp | (uintptr_t)buf) & (UINT64SZ - 1)) == 0)) {
/*
* Both source and destination are double word aligned
*/
int cnt = len/UINT64SZ;
IOSRAMLOG(2,
"WR: rep_put64(buf:%p sramp:%p cnt:%x) len:%x\n",
buf, iosramp, cnt, len);
ddi_rep_put64(handle, (uint64_t *)buf, (uint64_t *)iosramp,
cnt, DDI_DEV_AUTOINCR);
iosramp += cnt * UINT64SZ;
buf += cnt * UINT64SZ;
len -= cnt * UINT64SZ;
/*
* Copy the remaining data using word & byte access
*/
if (len >= UINT32SZ) {
IOSRAMLOG(2,
"WR: put32(buf:%p sramp:%p) len:%x\n", buf, iosramp,
len, NULL);
ddi_put32(handle, (uint32_t *)iosramp,
*(uint32_t *)buf);
iosramp += UINT32SZ;
buf += UINT32SZ;
len -= UINT32SZ;
}
if (len != 0) {
ddi_rep_put8(handle, buf, iosramp, len,
DDI_DEV_AUTOINCR);
}
} else if ((len >= UINT32SZ) &&
((((uintptr_t)iosramp | (uintptr_t)buf) & (UINT32SZ - 1)) == 0)) {
/*
* Both source and destination are word aligned
*/
int cnt = len/UINT32SZ;
IOSRAMLOG(2,
"WR: rep_put32(buf:%p sramp:%p cnt:%x) len:%x\n",
buf, iosramp, cnt, len);
ddi_rep_put32(handle, (uint32_t *)buf, (uint32_t *)iosramp,
cnt, DDI_DEV_AUTOINCR);
iosramp += cnt * UINT32SZ;
buf += cnt * UINT32SZ;
len -= cnt * UINT32SZ;
/*
* copy the remainder using byte access
*/
if (len != 0) {
ddi_rep_put8(handle, buf, iosramp, len,
DDI_DEV_AUTOINCR);
}
} else if (len != 0) {
/*
* We know that the "off" is at least word aligned. We
* need to read data from buf buffer byte at a time, and
* write it to the IOSRAM word at a time.
*/
ASSERT(((uintptr_t)iosramp & (UINT32SZ - 1)) == 0);
IOSRAMLOG(2,
"WR: unaligned put32(buf:%p sramp:%p) len:%x\n",
buf, iosramp, len, NULL);
for (; len >= UINT32SZ; len -= UINT32SZ, iosramp += UINT32SZ) {
word.cbuf[0] = *buf++;
word.cbuf[1] = *buf++;
word.cbuf[2] = *buf++;
word.cbuf[3] = *buf++;
ddi_put32(handle, (uint32_t *)iosramp, word.data);
}
/*
* copy the remaining data using byte access
*/
if (len != 0) {
ddi_rep_put8(handle, buf, iosramp,
len, DDI_DEV_AUTOINCR);
}
}
/*
* Reacquire mutex lock, decrement refcnt and if refcnt is 0 and
* any threads are waiting for r/w activity to complete, wake them up.
*/
mutex_enter(&iosram_mutex);
ASSERT(iosram_rw_active > 0);
if ((--iosram_rw_active == 0) && iosram_rw_wakeup) {
iosram_rw_wakeup = 0;
cv_broadcast(&iosram_rw_wait);
}
mutex_exit(&iosram_mutex);
return (error);
}
int
iosram_force_write(uint32_t key, uint32_t off, uint32_t len, caddr_t dptr)
{
return (_iosram_write(key, off, len, dptr, 1 /* force */));
}
int
iosram_wr(uint32_t key, uint32_t off, uint32_t len, caddr_t dptr)
{
return (_iosram_write(key, off, len, dptr, 0));
}
/*
* iosram_register(key, handler, arg)
* Register a handler and an arg for the specified chunk. This handler
* will be invoked when an interrupt is received from the other side and
* the int_pending flag for the corresponding key is marked
* IOSRAM_INT_TO_DOM.
*/
/* ARGSUSED */
int
iosram_register(uint32_t key, void (*handler)(), void *arg)
{
struct iosram_chunk *chunkp;
int error = 0;
/*
* Acquire lock and look for the requested chunk. If it exists, and no
* other callback is registered, proceed with the registration.
*/
mutex_enter(&iosram_mutex);
chunkp = iosram_find_chunk(key);
if (iosram_master == NULL) {
error = EIO;
} else if (chunkp == NULL) {
error = EINVAL;
} else if (chunkp->cback.handler != NULL) {
error = EBUSY;
} else {
chunkp->cback.busy = 0;
chunkp->cback.unregister = 0;
chunkp->cback.handler = handler;
chunkp->cback.arg = arg;
}
mutex_exit(&iosram_mutex);
IOSRAMLOG(1, "REG: key: 0x%x hdlr:%p arg:%p error:%d\n",
key, handler, arg, error);
return (error);
}
/*
* iosram_unregister()
* Unregister handler associated with the specified chunk.
*/
int
iosram_unregister(uint32_t key)
{
struct iosram_chunk *chunkp;
int error = 0;
/*
* Acquire lock and look for the requested chunk. If it exists and has
* a callback registered, unregister it.
*/
mutex_enter(&iosram_mutex);
chunkp = iosram_find_chunk(key);
if (iosram_master == NULL) {
error = EIO;
} else if (chunkp == NULL) {
error = EINVAL;
} else if (chunkp->cback.busy) {
/*
* If the handler is already busy (being invoked), then we flag
* it so it will be unregistered after the invocation completes.
*/
DPRINTF(1, ("IOSRAM(%d): unregister: delaying unreg k:0x%08x\n",
iosram_master->instance, key));
chunkp->cback.unregister = 1;
} else if (chunkp->cback.handler != NULL) {
chunkp->cback.handler = NULL;
chunkp->cback.arg = NULL;
}
mutex_exit(&iosram_mutex);
IOSRAMLOG(1, "UNREG: key:%x error:%d\n", key, error, NULL, NULL);
return (error);
}
/*
* iosram_get_flag():
* Get data_valid and/or int_pending flags associated with the
* specified key.
*/
int
iosram_get_flag(uint32_t key, uint8_t *data_valid, uint8_t *int_pending)
{
iosram_chunk_t *chunkp;
iosram_flags_t flags;
int error = 0;
/*
* Acquire lock and look for the requested chunk. If it exists, and no
* tunnel switch is in progress, read the chunk's flags.
*/
mutex_enter(&iosram_mutex);
chunkp = iosram_find_chunk(key);
if (iosram_master == NULL) {
error = EIO;
} else if (chunkp == NULL) {
error = EINVAL;
} else if (iosram_tswitch_active) {
error = EAGAIN;
} else {
IOSRAM_STAT(getflag);
/*
* Read the flags
*/
ddi_rep_get8(iosram_handle, (uint8_t *)&flags,
(uint8_t *)(chunkp->flagsp), sizeof (iosram_flags_t),
DDI_DEV_AUTOINCR);
/*
* Get each flag value that the caller is interested in.
*/
if (data_valid != NULL) {
*data_valid = flags.data_valid;
}
if (int_pending != NULL) {
*int_pending = flags.int_pending;
}
}
mutex_exit(&iosram_mutex);
IOSRAMLOG(1, "GetFlag key:%x data_valid:%x int_pending:%x error:%d\n",
key, flags.data_valid, flags.int_pending, error);
return (error);
}
/*
* iosram_set_flag():
* Set data_valid and int_pending flags associated with the specified key.
*/
int
iosram_set_flag(uint32_t key, uint8_t data_valid, uint8_t int_pending)
{
iosram_chunk_t *chunkp;
iosram_flags_t flags;
int error = 0;
/*
* Acquire lock and look for the requested chunk. If it exists, and no
* tunnel switch is in progress, write the chunk's flags.
*/
mutex_enter(&iosram_mutex);
chunkp = iosram_find_chunk(key);
if (iosram_master == NULL) {
error = EIO;
} else if ((chunkp == NULL) ||
((data_valid != IOSRAM_DATA_INVALID) &&
(data_valid != IOSRAM_DATA_VALID)) ||
((int_pending != IOSRAM_INT_NONE) &&
(int_pending != IOSRAM_INT_TO_SSC) &&
(int_pending != IOSRAM_INT_TO_DOM))) {
error = EINVAL;
} else if (iosram_tswitch_active) {
error = EAGAIN;
} else {
IOSRAM_STAT(setflag);
flags.data_valid = data_valid;
flags.int_pending = int_pending;
ddi_rep_put8(iosram_handle, (uint8_t *)&flags,
(uint8_t *)(chunkp->flagsp), sizeof (iosram_flags_t),
DDI_DEV_AUTOINCR);
}
mutex_exit(&iosram_mutex);
IOSRAMLOG(1, "SetFlag key:%x data_valid:%x int_pending:%x error:%d\n",
key, flags.data_valid, flags.int_pending, error);
return (error);
}
/*
* iosram_ctrl()
* This function provides access to a variety of services not available
* through the basic API.
*/
int
iosram_ctrl(uint32_t key, uint32_t cmd, void *arg)
{
struct iosram_chunk *chunkp;
int error = 0;
/*
* Acquire lock and do some argument sanity checking.
*/
mutex_enter(&iosram_mutex);
chunkp = iosram_find_chunk(key);
if (iosram_master == NULL) {
error = EIO;
} else if (chunkp == NULL) {
error = EINVAL;
}
if (error != 0) {
mutex_exit(&iosram_mutex);
return (error);
}
/*
* Arguments seem okay so far, so process the command.
*/
switch (cmd) {
case IOSRAM_CMD_CHUNKLEN:
/*
* Return the length of the chunk indicated by the key.
*/
if (arg == NULL) {
error = EINVAL;
break;
}
*(uint32_t *)arg = chunkp->toc_data.len;
break;
default:
error = ENOTSUP;
break;
}
mutex_exit(&iosram_mutex);
return (error);
}
/*
* iosram_hdr_ctrl()
* This function provides an interface for the Mailbox Protocol
* implementation to use when interacting with the IOSRAM header.
*/
int
iosram_hdr_ctrl(uint32_t cmd, void *arg)
{
int error = 0;
/*
* Acquire lock and do some argument sanity checking.
*/
mutex_enter(&iosram_mutex);
if (iosram_master == NULL) {
error = EIO;
}
if (error != 0) {
mutex_exit(&iosram_mutex);
return (error);
}
switch (cmd) {
case IOSRAM_HDRCMD_GET_SMS_MBOX_VER:
/*
* Return the value of the sms_mbox_version field.
*/
if (arg == NULL) {
error = EINVAL;
break;
}
*(uint32_t *)arg = IOSRAM_GET_HDRFIELD32(iosram_master,
sms_mbox_version);
break;
case IOSRAM_HDRCMD_SET_OS_MBOX_VER:
/*
* Set the value of the os_mbox_version field.
*/
IOSRAM_SET_HDRFIELD32(iosram_master, os_mbox_version,
(uint32_t)(uintptr_t)arg);
IOSRAM_SET_HDRFIELD32(iosram_master, os_change_mask,
IOSRAM_HDRFIELD_OS_MBOX_VER);
iosram_send_intr();
break;
case IOSRAM_HDRCMD_REG_CALLBACK:
iosram_hdrchange_handler = (void (*)())arg;
break;
default:
error = ENOTSUP;
break;
}
mutex_exit(&iosram_mutex);
return (error);
}
/*
* iosram_softintr()
* IOSRAM soft interrupt handler
*/
static uint_t
iosram_softintr(caddr_t arg)
{
uint32_t hdr_changes;
iosramsoft_t *softp = (iosramsoft_t *)arg;
iosram_chunk_t *chunkp;
void (*handler)();
int i;
uint8_t flag;
DPRINTF(1, ("iosram(%d): in iosram_softintr\n", softp->instance));
IOSRAMLOG(2, "SINTR arg/softp:%p pending:%d busy:%d\n",
arg, softp->intr_pending, softp->intr_busy, NULL);
mutex_enter(&iosram_mutex);
mutex_enter(&softp->intr_mutex);
/*
* Do not process interrupt if interrupt handler is already running or
* no interrupts are pending.
*/
if (softp->intr_busy || !softp->intr_pending) {
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM(%d): softintr: busy=%d pending=%d\n",
softp->instance, softp->intr_busy, softp->intr_pending));
return (softp->intr_pending ? DDI_INTR_CLAIMED :
DDI_INTR_UNCLAIMED);
}
/*
* It's possible for the SC to send an interrupt on the new master
* before we are able to set our internal state. If so, we'll retrigger
* soft interrupt right after tunnel switch completion.
*/
if (softp->state & IOSRAM_STATE_TSWITCH) {
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM(%d): softintr: doing switch "
"state=0x%x\n", softp->instance, softp->state));
return (DDI_INTR_CLAIMED);
}
/*
* Do not process interrupt if we are not the master.
*/
if (!(softp->state & IOSRAM_STATE_MASTER)) {
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM(%d): softintr: no master state=0x%x\n ",
softp->instance, softp->state));
return (DDI_INTR_CLAIMED);
}
IOSRAM_STAT(sintr_recv);
/*
* If the driver is suspended, then we should not process any
* interrupts. Instead, we trigger a soft interrupt when the driver
* resumes.
*/
if (softp->suspended) {
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM(%d): softintr: suspended\n",
softp->instance));
return (DDI_INTR_CLAIMED);
}
/*
* Indicate that the IOSRAM interrupt handler is busy. Note that this
* includes incrementing the reader/writer count, since we don't want
* any tunnel switches to start up while we're processing callbacks.
*/
softp->intr_busy = 1;
iosram_rw_active++;
#if defined(DEBUG)
if (iosram_rw_active > iosram_rw_active_max) {
iosram_rw_active_max = iosram_rw_active;
}
#endif
do {
DPRINTF(1, ("IOSRAM(%d): softintr: processing interrupt\n",
softp->instance));
softp->intr_pending = 0;
mutex_exit(&softp->intr_mutex);
/*
* Process changes to the IOSRAM header.
*/
hdr_changes = IOSRAM_GET_HDRFIELD32(iosram_master,
sms_change_mask);
if (hdr_changes != 0) {
int error;
IOSRAM_SET_HDRFIELD32(iosram_master, sms_change_mask,
0);
if (hdr_changes & IOSRAM_HDRFIELD_TOC_INDEX) {
/*
* XXX is it safe to temporarily release the
* iosram_mutex here?
*/
mutex_exit(&iosram_mutex);
error = iosram_read_toc(iosram_master);
mutex_enter(&iosram_mutex);
if (error) {
cmn_err(CE_WARN, "iosram_read_toc: new"
" TOC invalid; using old TOC.");
}
iosram_update_addrs(iosram_master);
}
if (iosram_hdrchange_handler != NULL) {
mutex_exit(&iosram_mutex);
iosram_hdrchange_handler();
mutex_enter(&iosram_mutex);
}
}
/*
* Get data_valid/int_pending flags and generate a callback if
* applicable. For now, we read only those flags for which a
* callback has been registered. We can optimize reading of
* flags by reading them all at once and then process them
* later.
*/
for (i = 0, chunkp = chunks; i < nchunks; i++,
chunkp++) {
#if DEBUG
flag = ddi_get8(iosram_handle,
&(chunkp->flagsp->int_pending));
DPRINTF(1, ("IOSRAM(%d): softintr chunk #%d "
"flag=0x%x handler=%p\n",
softp->instance, i, (int)flag,
chunkp->cback.handler));
#endif
if ((handler = chunkp->cback.handler) == NULL) {
continue;
}
flag = ddi_get8(iosram_handle,
&(chunkp->flagsp->int_pending));
if (flag == IOSRAM_INT_TO_DOM) {
DPRINTF(1,
("IOSRAM(%d): softintr: invoking handler\n",
softp->instance));
IOSRAMLOG(1,
"SINTR invoking hdlr:%p arg:%p index:%d\n",
handler, chunkp->cback.arg, i, NULL);
IOSRAM_STAT(callbacks);
ddi_put8(iosram_handle,
&(chunkp->flagsp->int_pending),
IOSRAM_INT_NONE);
chunkp->cback.busy = 1;
mutex_exit(&iosram_mutex);
(*handler)(chunkp->cback.arg);
mutex_enter(&iosram_mutex);
chunkp->cback.busy = 0;
/*
* If iosram_unregister was called while the
* callback was being invoked, complete the
* unregistration here.
*/
if (chunkp->cback.unregister) {
DPRINTF(1, ("IOSRAM(%d): softintr: "
"delayed unreg k:0x%08x\n",
softp->instance,
chunkp->toc_data.key));
chunkp->cback.handler = NULL;
chunkp->cback.arg = NULL;
chunkp->cback.unregister = 0;
}
}
/*
* If there's a tunnel switch waiting to run, give it
* higher priority than these callbacks by bailing out.
* They'll still be invoked on the new master iosram
* when the tunnel switch is done.
*/
if (iosram_tswitch_active) {
break;
}
}
mutex_enter(&softp->intr_mutex);
} while (softp->intr_pending && !softp->suspended &&
!iosram_tswitch_active);
/*
* Indicate IOSRAM interrupt handler is not BUSY any more
*/
softp->intr_busy = 0;
ASSERT(iosram_rw_active > 0);
if ((--iosram_rw_active == 0) && iosram_rw_wakeup) {
iosram_rw_wakeup = 0;
cv_broadcast(&iosram_rw_wait);
}
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
DPRINTF(1, ("iosram(%d): softintr exit\n", softp->instance));
return (DDI_INTR_CLAIMED);
}
/*
* iosram_intr()
* IOSRAM real interrupt handler
*/
static uint_t
iosram_intr(caddr_t arg)
{
iosramsoft_t *softp = (iosramsoft_t *)arg;
int result = DDI_INTR_UNCLAIMED;
uint32_t int_status;
DPRINTF(2, ("iosram(%d): in iosram_intr\n", softp->instance));
mutex_enter(&softp->intr_mutex);
if (softp->sbbc_handle == NULL) {
/*
* The SBBC registers region is not mapped in.
* Set the interrupt pending flag here, and process the
* interrupt after the tunnel switch.
*/
DPRINTF(1, ("IOSRAM(%d): iosram_intr: SBBC not mapped\n",
softp->instance));
softp->intr_pending = 1;
mutex_exit(&softp->intr_mutex);
return (DDI_INTR_UNCLAIMED);
}
int_status = ddi_get32(softp->sbbc_handle,
&(softp->sbbc_region->int_status.reg));
DPRINTF(1, ("iosram_intr: int_status = 0x%08x\n", int_status));
if (int_status & IOSRAM_SBBC_INT0) {
result = DDI_INTR_CLAIMED;
DPRINTF(1, ("iosram_intr: int0 detected!\n"));
}
if (int_status & IOSRAM_SBBC_INT1) {
result = DDI_INTR_CLAIMED;
DPRINTF(1, ("iosram_intr: int1 detected!\n"));
}
if (result == DDI_INTR_CLAIMED) {
ddi_put32(softp->sbbc_handle,
&(softp->sbbc_region->int_status.reg), int_status);
int_status = ddi_get32(softp->sbbc_handle,
&(softp->sbbc_region->int_status.reg));
DPRINTF(1, ("iosram_intr: int_status = 0x%08x\n",
int_status));
softp->intr_pending = 1;
/*
* Trigger soft interrupt if not executing and
* not suspended.
*/
if (!softp->intr_busy && !softp->suspended &&
(softp->softintr_id != NULL)) {
DPRINTF(1, ("iosram(%d): trigger softint\n",
softp->instance));
ddi_trigger_softintr(softp->softintr_id);
}
}
IOSRAM_STAT(intr_recv);
mutex_exit(&softp->intr_mutex);
IOSRAMLOG(2, "INTR arg/softp:%p pending:%d busy:%d\n",
arg, softp->intr_pending, softp->intr_busy, NULL);
DPRINTF(1, ("iosram(%d): iosram_intr exit\n", softp->instance));
return (result);
}
/*
* iosram_send_intr()
* Send an interrupt to the SSP side via AXQ driver
*/
int
iosram_send_intr()
{
IOSRAMLOG(1, "SendIntr called\n", NULL, NULL, NULL, NULL);
IOSRAM_STAT(intr_send);
DPRINTF(1, ("iosram iosram_send_intr invoked\n"));
return (axq_cpu2ssc_intr(0));
}
#if defined(DEBUG)
static void
iosram_dummy_cback(void *arg)
{
DPRINTF(1, ("iosram_dummy_cback invoked arg:%p\n", arg));
}
#endif /* DEBUG */
/*ARGSUSED1*/
static int
iosram_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
int *rvalp)
{
struct iosramsoft *softp;
int error = DDI_SUCCESS;
softp = ddi_get_soft_state(iosramsoft_statep, getminor(dev));
if (softp == NULL) {
return (ENXIO);
}
IOSRAMLOG(1, "IOCTL: dev:%p cmd:%x arg:%p ... instance %d\n",
dev, cmd, arg, softp->instance);
switch (cmd) {
#if defined(DEBUG)
case IOSRAM_GET_FLAG:
{
iosram_io_t req;
uint8_t data_valid, int_pending;
if (ddi_copyin((void *)arg, &req, sizeof (req), mode)) {
return (EFAULT);
}
DPRINTF(2, ("IOSRAM_GET_FLAG(key:%x\n", req.key));
req.retval = iosram_get_flag(req.key, &data_valid,
&int_pending);
req.data_valid = (uint32_t)data_valid;
req.int_pending = (uint32_t)int_pending;
if (ddi_copyout(&req, (void *)arg, sizeof (req), mode)) {
DPRINTF(1,
("IOSRAM_GET_FLAG: can't copyout req.retval (%x)",
req.retval));
error = EFAULT;
}
return (error);
}
case IOSRAM_SET_FLAG:
{
iosram_io_t req;
if (ddi_copyin((void *)arg, &req, sizeof (req), mode)) {
return (EFAULT);
}
DPRINTF(2, ("IOSRAM_SET_FLAG(key:%x data_valid:%x "
"int_pending:%x\n", req.key, req.data_valid,
req.int_pending));
req.retval = iosram_set_flag(req.key, req.data_valid,
req.int_pending);
if (ddi_copyout(&req, (void *)arg, sizeof (req), mode)) {
DPRINTF(1, ("IOSRAM_SET_FLAG: can't copyout req.retval"
" (%x)\n", req.retval));
error = EFAULT;
}
return (error);
}
case IOSRAM_RD:
{
caddr_t bufp;
int len;
iosram_io_t req;
if (ddi_copyin((void *)arg, &req, sizeof (req), mode)) {
return (EFAULT);
}
DPRINTF(2, ("IOSRAM_RD(k:%x o:%x len:%x bufp:%p\n", req.key,
req.off, req.len, (void *)(uintptr_t)req.bufp));
len = req.len;
bufp = kmem_alloc(len, KM_SLEEP);
req.retval = iosram_rd(req.key, req.off, req.len, bufp);
if (ddi_copyout(bufp, (void *)(uintptr_t)req.bufp, len, mode)) {
DPRINTF(1, ("IOSRAM_RD: copyout(%p, %p,%x,%x) failed\n",
bufp, (void *)(uintptr_t)req.bufp, len, mode));
error = EFAULT;
} else if (ddi_copyout(&req, (void *)arg, sizeof (req), mode)) {
DPRINTF(1, ("IOSRAM_RD: can't copyout retval (%x)\n",
req.retval));
error = EFAULT;
}
kmem_free(bufp, len);
return (error);
}
case IOSRAM_WR:
{
caddr_t bufp;
iosram_io_t req;
int len;
if (ddi_copyin((void *)arg, &req, sizeof (req), mode)) {
return (EFAULT);
}
DPRINTF(2, ("IOSRAM_WR(k:%x o:%x len:%x bufp:%p\n",
req.key, req.off, req.len, req.bufp));
len = req.len;
bufp = kmem_alloc(len, KM_SLEEP);
if (ddi_copyin((void *)(uintptr_t)req.bufp, bufp, len, mode)) {
error = EFAULT;
} else {
req.retval = iosram_wr(req.key, req.off, req.len,
bufp);
if (ddi_copyout(&req, (void *)arg, sizeof (req),
mode)) {
error = EFAULT;
}
}
kmem_free(bufp, len);
return (error);
}
case IOSRAM_TOC:
{
caddr_t bufp;
int len;
iosram_io_t req;
if (ddi_copyin((void *)arg, &req, sizeof (req), mode)) {
return (EFAULT);
}
DPRINTF(2, ("IOSRAM_TOC (req.bufp:%x req.len:%x) \n",
req.bufp, req.len));
len = req.len;
bufp = kmem_alloc(len, KM_SLEEP);
req.retval = iosram_get_keys((iosram_toc_entry_t *)bufp,
&req.len);
if (ddi_copyout(bufp, (void *)(uintptr_t)req.bufp, req.len,
mode)) {
DPRINTF(1,
("IOSRAM_TOC: copyout(%p, %p,%x,%x) failed\n",
bufp, (void *)(uintptr_t)req.bufp, req.len, mode));
error = EFAULT;
} else if (ddi_copyout(&req, (void *)arg, sizeof (req), mode)) {
DPRINTF(1, ("IOSRAM_TOC: can't copyout retval (%x)\n",
req.retval));
error = EFAULT;
}
kmem_free(bufp, len);
return (error);
}
case IOSRAM_SEND_INTR:
{
DPRINTF(2, ("IOSRAM_SEND_INTR\n"));
switch ((int)arg) {
case 0x11:
case 0x22:
case 0x44:
case 0x88:
ddi_put32(softp->sbbc_handle,
&(softp->sbbc_region->int_enable.reg), (int)arg);
DPRINTF(1, ("Wrote 0x%x to int_enable.reg\n",
(int)arg));
break;
case 0xBB:
ddi_put32(softp->sbbc_handle,
&(softp->sbbc_region->p0_int_gen.reg), 1);
DPRINTF(1, ("Wrote 1 to p0_int_gen.reg\n"));
break;
default:
error = iosram_send_intr();
}
return (error);
}
case IOSRAM_PRINT_CBACK:
iosram_print_cback();
break;
case IOSRAM_PRINT_STATE:
iosram_print_state((int)arg);
break;
#if IOSRAM_STATS
case IOSRAM_PRINT_STATS:
iosram_print_stats();
break;
#endif
#if IOSRAM_LOG
case IOSRAM_PRINT_LOG:
iosram_print_log((int)arg);
break;
#endif
case IOSRAM_TUNNEL_SWITCH:
error = iosram_switchfrom((int)arg);
break;
case IOSRAM_PRINT_FLAGS:
iosram_print_flags();
break;
case IOSRAM_REG_CBACK:
{
iosram_io_t req;
if (ddi_copyin((void *)arg, &req, sizeof (req), mode)) {
return (EFAULT);
}
DPRINTF(2, ("IOSRAM_REG_CBACK(k:%x)\n", req.key));
req.retval = iosram_register(req.key, iosram_dummy_cback,
(void *)(uintptr_t)req.key);
if (ddi_copyout(&req, (void *)arg, sizeof (req), mode)) {
error = EFAULT;
}
return (error);
}
case IOSRAM_UNREG_CBACK:
{
iosram_io_t req;
if (ddi_copyin((void *)arg, &req, sizeof (req), mode)) {
return (EFAULT);
}
DPRINTF(2, ("IOSRAM_REG_CBACK(k:%x)\n", req.key));
req.retval = iosram_unregister(req.key);
if (ddi_copyout(&req, (void *)arg, sizeof (req), mode)) {
error = EFAULT;
}
return (error);
}
case IOSRAM_SEMA_ACQUIRE:
{
DPRINTF(1, ("IOSRAM_SEMA_ACQUIRE\n"));
error = iosram_sema_acquire(NULL);
return (error);
}
case IOSRAM_SEMA_RELEASE:
{
DPRINTF(1, ("IOSRAM_SEMA_RELEASE\n"));
error = iosram_sema_release();
return (error);
}
#endif /* DEBUG */
default:
DPRINTF(1, ("iosram_ioctl: Illegal command %x\n", cmd));
error = ENOTTY;
}
return (error);
}
/*
* iosram_switch_tunnel(softp)
* Switch master tunnel to the specified instance
* Must be called while holding iosram_mutex
*/
/*ARGSUSED*/
static int
iosram_switch_tunnel(iosramsoft_t *softp)
{
#ifdef DEBUG
int instance = softp->instance;
#endif
int error = 0;
iosramsoft_t *prev_master;
ASSERT(mutex_owned(&iosram_mutex));
DPRINTF(1, ("tunnel switch new master:%p (%d) current master:%p (%d)\n",
softp, instance, iosram_master,
((iosram_master) ? iosram_master->instance : -1)));
IOSRAMLOG(1, "TSWTCH: new_master:%p (%p) iosram_master:%p (%d)\n",
softp, instance, iosram_master,
((iosram_master) ? iosram_master->instance : -1));
if (softp == NULL || (softp->state & IOSRAM_STATE_DETACH)) {
return (ENXIO);
}
if (iosram_master == softp) {
return (0);
}
/*
* We protect against the softp structure being deallocated by setting
* the IOSRAM_STATE_TSWITCH state flag. The detach routine will check
* for this flag and if set, it will wait for this flag to be reset or
* refuse the detach operation.
*/
iosram_new_master = softp;
softp->state |= IOSRAM_STATE_TSWITCH;
prev_master = iosram_master;
if (prev_master) {
prev_master->state |= IOSRAM_STATE_TSWITCH;
}
mutex_exit(&iosram_mutex);
/*
* Map the target IOSRAM, read the TOC, and register interrupts if not
* already done.
*/
DPRINTF(1, ("iosram(%d): mapping IOSRAM and SBBC\n",
softp->instance));
IOSRAMLOG(1, "TSWTCH: mapping instance:%d softp:%p\n",
instance, softp, NULL, NULL);
if (iosram_setup_map(softp) != DDI_SUCCESS) {
error = ENXIO;
} else if ((chunks == NULL) && (iosram_read_toc(softp) != 0)) {
iosram_remove_map(softp);
error = EINVAL;
} else if (iosram_add_intr(softp) != DDI_SUCCESS) {
/*
* If there was no previous master, purge the TOC data that
* iosram_read_toc() created.
*/
if ((prev_master == NULL) && (chunks != NULL)) {
kmem_free(chunks, nchunks * sizeof (iosram_chunk_t));
chunks = NULL;
nchunks = 0;
iosram_init_hashtab();
}
iosram_remove_map(softp);
error = ENXIO;
}
/*
* If we are asked to abort tunnel switch, do so now, before invoking
* the OBP callback.
*/
if (iosram_tswitch_aborted) {
/*
* Once the tunnel switch is aborted, this thread should not
* resume. If it does, we simply log a message. We can't unmap
* the new master IOSRAM as it may be accessed in
* iosram_abort_tswitch(). It will be unmapped when it is
* detached.
*/
IOSRAMLOG(1,
"TSWTCH: aborted (pre OBP cback). Thread resumed.\n",
NULL, NULL, NULL, NULL);
error = EIO;
}
if (error) {
IOSRAMLOG(1,
"TSWTCH: map failed instance:%d softp:%p error:%x\n",
instance, softp, error, NULL);
goto done;
}
if (prev_master != NULL) {
int result;
/*
* Now invoke the OBP interface to do the tunnel switch.
*/
result = prom_starcat_switch_tunnel(softp->portid,
OBP_TSWITCH_REQREPLY);
if (result != 0) {
error = EIO;
}
IOSRAMLOG(1,
"TSWTCH: OBP tswitch portid:%x result:%x error:%x\n",
softp->portid, result, error, NULL);
IOSRAM_STAT(tswitch);
iosram_tswitch_tstamp = ddi_get_lbolt();
}
mutex_enter(&iosram_mutex);
if (iosram_tswitch_aborted) {
/*
* Tunnel switch aborted. This thread should not resume.
* For now, we simply log a message, but don't unmap any
* IOSRAM at this stage as it may be accessed within the
* isoram_abort_tswitch(). The IOSRAM will be unmapped
* when that instance is detached.
*/
if (iosram_tswitch_aborted) {
IOSRAMLOG(1,
"TSWTCH: aborted (post OBP cback). Thread"
" resumed.\n", NULL, NULL, NULL, NULL);
error = EIO;
mutex_exit(&iosram_mutex);
}
} else if (error) {
/*
* Tunnel switch failed. Continue using previous tunnel.
* However, unmap new (target) IOSRAM.
*/
iosram_new_master = NULL;
mutex_exit(&iosram_mutex);
iosram_remove_intr(softp);
iosram_remove_map(softp);
} else {
/*
* Tunnel switch was successful. Set the new master.
* Also unmap old master IOSRAM and remove any interrupts
* associated with that.
*
* Note that a call to iosram_force_write() allows access
* to the IOSRAM while tunnel switch is in progress. That
* means we need to set the new master before unmapping
* the old master.
*/
iosram_set_master(softp);
iosram_new_master = NULL;
mutex_exit(&iosram_mutex);
if (prev_master) {
IOSRAMLOG(1, "TSWTCH: unmapping prev_master:%p (%d)\n",
prev_master, prev_master->instance, NULL, NULL);
iosram_remove_intr(prev_master);
iosram_remove_map(prev_master);
}
}
done:
mutex_enter(&iosram_mutex);
/*
* Clear the tunnel switch flag on the source and destination
* instances.
*/
if (prev_master) {
prev_master->state &= ~IOSRAM_STATE_TSWITCH;
}
softp->state &= ~IOSRAM_STATE_TSWITCH;
/*
* Since incoming interrupts could get lost during a tunnel switch,
* trigger a soft interrupt just in case. No harm other than a bit
* of wasted effort will be caused if no interrupts were dropped.
*/
mutex_enter(&softp->intr_mutex);
iosram_master->intr_pending = 1;
if ((iosram_master->softintr_id != NULL) &&
(iosram_master->intr_busy == 0)) {
ddi_trigger_softintr(iosram_master->softintr_id);
}
mutex_exit(&softp->intr_mutex);
IOSRAMLOG(1, "TSWTCH: done error:%d iosram_master:%p instance:%d\n",
error, iosram_master,
(iosram_master) ? iosram_master->instance : -1, NULL);
return (error);
}
/*
* iosram_abort_tswitch()
* Must be called while holding iosram_mutex.
*/
static void
iosram_abort_tswitch()
{
uint32_t master_valid, new_master_valid;
ASSERT(mutex_owned(&iosram_mutex));
if ((!iosram_tswitch_active) || iosram_tswitch_aborted) {
return;
}
ASSERT(iosram_master != NULL);
IOSRAMLOG(1, "ABORT: iosram_master:%p (%d) iosram_new_master:%p (%d)\n",
iosram_master, iosram_master->instance, iosram_new_master,
(iosram_new_master == NULL) ? -1 : iosram_new_master->instance);
/*
* The first call to iosram_force_write() in the middle of tunnel switch
* will get here. We lookup IOSRAM VALID location and setup appropriate
* master, if one is still valid. We also set iosram_tswitch_aborted to
* prevent reentering this code and to catch if the OBP callback thread
* somehow resumes.
*/
iosram_tswitch_aborted = 1;
if ((iosram_new_master == NULL) ||
(iosram_new_master = iosram_master)) {
/*
* New master hasn't been selected yet, or OBP callback
* succeeded and we already selected new IOSRAM as master, but
* system crashed in the middle of unmapping previous master or
* cleaning up state. Use the existing master.
*/
ASSERT(iosram_master->iosramp != NULL);
ASSERT(IOSRAM_GET_HDRFIELD32(iosram_master, status) ==
IOSRAM_VALID);
IOSRAMLOG(1, "ABORT: master (%d) already determined.\n",
iosram_master->instance, NULL, NULL, NULL);
return;
}
/*
* System crashed in the middle of tunnel switch and we know that the
* new target has not been marked master yet. That means, the old
* master should still be mapped. We need to abort the tunnel switch
* and setup a valid master, if possible, so that we can write to the
* IOSRAM.
*
* We select a new master based upon the IOSRAM header status fields in
* the previous master IOSRAM and the target IOSRAM as follows:
*
* iosram_master iosram-tswitch
* (Prev Master) (New Target) Decision
* --------------- --------------- -----------
* VALID don't care prev master
* INTRANSIT INVALID prev master
* INTRANSIT INTRANSIT prev master
* INTRANSIT VALID new target
* INVALID INVALID shouldn't ever happen
* INVALID INTRANSIT shouldn't ever happen
* INVALID VALID new target
*/
master_valid = (iosram_master->iosramp != NULL) ?
IOSRAM_GET_HDRFIELD32(iosram_master, status) : IOSRAM_INVALID;
new_master_valid = (iosram_new_master->iosramp != NULL) ?
IOSRAM_GET_HDRFIELD32(iosram_new_master, status) : IOSRAM_INVALID;
if (master_valid == IOSRAM_VALID) {
/* EMPTY */
/*
* OBP hasn't been called yet or, if it has, it hasn't started
* copying yet. Use the existing master. Note that the new
* master may not be mapped yet.
*/
IOSRAMLOG(1, "ABORT: prev master(%d) is VALID\n",
iosram_master->instance, NULL, NULL, NULL);
} else if (master_valid == IOSRAM_INTRANSIT) {
/*
* The system crashed after OBP started processing the tunnel
* switch but before the iosram driver determined that it was
* complete. Use the new master if it has been marked valid,
* meaning that OBP finished copying data to it, or the old
* master otherwise.
*/
IOSRAMLOG(1, "ABORT: prev master(%d) is INTRANSIT\n",
iosram_master->instance, NULL, NULL, NULL);
if (new_master_valid == IOSRAM_VALID) {
iosram_set_master(iosram_new_master);
IOSRAMLOG(1, "ABORT: new master(%d) is VALID\n",
iosram_new_master->instance, NULL, NULL,
NULL);
} else {
prom_starcat_switch_tunnel(iosram_master->portid,
OBP_TSWITCH_NOREPLY);
IOSRAMLOG(1, "ABORT: new master(%d) is INVALID\n",
iosram_new_master->instance, NULL, NULL,
NULL);
}
} else {
/*
* The system crashed after OBP marked the old master INVALID,
* which means the new master is the way to go.
*/
IOSRAMLOG(1, "ABORT: prev master(%d) is INVALID\n",
iosram_master->instance, NULL, NULL, NULL);
ASSERT(new_master_valid == IOSRAM_VALID);
iosram_set_master(iosram_new_master);
}
IOSRAMLOG(1, "ABORT: Instance %d selected as master\n",
iosram_master->instance, NULL, NULL, NULL);
}
/*
* iosram_switchfrom(instance)
* Switch master tunnel away from the specified instance
*/
/*ARGSUSED*/
int
iosram_switchfrom(int instance)
{
struct iosramsoft *softp;
int error = 0;
int count;
clock_t current_tstamp;
clock_t tstamp_interval;
struct iosramsoft *last_master = NULL;
static int last_master_instance = -1;
IOSRAMLOG(1, "SwtchFrom: instance:%d iosram_master:%p (%d)\n",
instance, iosram_master,
((iosram_master) ? iosram_master->instance : -1), NULL);
mutex_enter(&iosram_mutex);
/*
* Wait if another tunnel switch is in progress
*/
for (count = 0; iosram_tswitch_active && count < IOSRAM_TSWITCH_RETRY;
count++) {
iosram_tswitch_wakeup = 1;
cv_wait(&iosram_tswitch_wait, &iosram_mutex);
}
if (iosram_tswitch_active) {
mutex_exit(&iosram_mutex);
return (EAGAIN);
}
/*
* Check if the specified instance holds the tunnel. If not,
* then we are done.
*/
if ((iosram_master == NULL) || (iosram_master->instance != instance)) {
mutex_exit(&iosram_mutex);
return (0);
}
/*
* Before beginning the tunnel switch process, wait for any outstanding
* read/write activity to complete.
*/
iosram_tswitch_active = 1;
while (iosram_rw_active) {
iosram_rw_wakeup = 1;
cv_wait(&iosram_rw_wait, &iosram_mutex);
}
/*
* If a previous tunnel switch just completed, we have to make sure
* HWAD has enough time to find the new tunnel before we switch
* away from it. Otherwise, OBP's mailbox message to OSD will never
* get through. Just to be paranoid about synchronization of lbolt
* across different CPUs, make sure the current attempt isn't noted
* as starting _before_ the last tunnel switch completed.
*/
current_tstamp = ddi_get_lbolt();
if (current_tstamp > iosram_tswitch_tstamp) {
tstamp_interval = current_tstamp - iosram_tswitch_tstamp;
} else {
tstamp_interval = 0;
}
if (drv_hztousec(tstamp_interval) < IOSRAM_TSWITCH_DELAY_US) {
mutex_exit(&iosram_mutex);
delay(drv_usectohz(IOSRAM_TSWITCH_DELAY_US) - tstamp_interval);
mutex_enter(&iosram_mutex);
}
/*
* The specified instance holds the tunnel. We need to move it to some
* other IOSRAM. Try out all possible IOSRAMs listed in
* iosram_instances. For now, we always search from the first entry.
* In future, it may be desirable to start where we left off.
*/
for (softp = iosram_instances; softp != NULL; softp = softp->next) {
if (iosram_tswitch_aborted) {
break;
}
/* we can't switch _to_ the instance we're switching _from_ */
if (softp->instance == instance) {
continue;
}
/* skip over instances being detached */
if (softp->state & IOSRAM_STATE_DETACH) {
continue;
}
/*
* Try to avoid reverting to the last instance we switched away
* from, as we expect that one to be detached eventually. Keep
* track of it, though, so we can go ahead and try switching to
* it if no other viable candidates are found.
*/
if (softp->instance == last_master_instance) {
last_master = softp;
continue;
}
/*
* Do the tunnel switch. If successful, record the instance of
* the master we just left behind so we can try to avoid
* reverting to it next time.
*/
if (iosram_switch_tunnel(softp) == 0) {
last_master_instance = instance;
break;
}
}
/*
* If we failed to switch the tunnel, but we skipped over an instance
* that had previously been switched out of because we expected it to be
* detached, go ahead and try it anyway (unless the tswitch was aborted
* or the instance we skipped is finally being detached).
*/
if ((softp == NULL) && (last_master != NULL) &&
!iosram_tswitch_aborted &&
!(last_master->state & IOSRAM_STATE_DETACH)) {
if (iosram_switch_tunnel(last_master) == 0) {
softp = last_master;
last_master_instance = instance;
}
}
if ((softp == NULL) || (iosram_tswitch_aborted)) {
error = EIO;
}
/*
* If there are additional tunnel switches queued up waiting for this
* one to complete, wake them up.
*/
if (iosram_tswitch_wakeup) {
iosram_tswitch_wakeup = 0;
cv_broadcast(&iosram_tswitch_wait);
}
iosram_tswitch_active = 0;
mutex_exit(&iosram_mutex);
return (error);
}
/*
* iosram_tunnel_capable(softp)
* Check if this IOSRAM instance is tunnel-capable by looing at
* "tunnel-capable" property.
*/
static int
iosram_tunnel_capable(struct iosramsoft *softp)
{
int proplen;
int tunnel_capable;
/*
* Look up IOSRAM_TUNNELOK_PROP property, if any.
*/
proplen = sizeof (tunnel_capable);
if (ddi_getlongprop_buf(DDI_DEV_T_ANY, softp->dip,
DDI_PROP_DONTPASS, IOSRAM_TUNNELOK_PROP, (caddr_t)&tunnel_capable,
&proplen) != DDI_PROP_SUCCESS) {
tunnel_capable = 0;
}
return (tunnel_capable);
}
static int
iosram_sbbc_setup_map(struct iosramsoft *softp)
{
int rv;
struct ddi_device_acc_attr attr;
dev_info_t *dip = softp->dip;
uint32_t sema_val;
attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
mutex_enter(&iosram_mutex);
mutex_enter(&softp->intr_mutex);
/*
* Map SBBC region in
*/
if ((rv = ddi_regs_map_setup(dip, IOSRAM_SBBC_MAP_INDEX,
(caddr_t *)&softp->sbbc_region,
IOSRAM_SBBC_MAP_OFFSET, sizeof (iosram_sbbc_region_t),
&attr, &softp->sbbc_handle)) != DDI_SUCCESS) {
DPRINTF(1, ("Failed to map SBBC region.\n"));
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
return (rv);
}
/*
* Disable SBBC interrupts. SBBC interrupts are enabled
* once the interrupt handler is registered.
*/
ddi_put32(softp->sbbc_handle,
&(softp->sbbc_region->int_enable.reg), 0x0);
/*
* Clear hardware semaphore value if appropriate.
* When the first SBBC is mapped in by the IOSRAM driver,
* the value of the semaphore should be initialized only
* if it is not held by SMS. For subsequent SBBC's, the
* semaphore will be always initialized.
*/
sema_val = IOSRAM_SEMA_RD(softp);
if (!iosram_master) {
/* the first SBBC is being mapped in */
if (!(IOSRAM_SEMA_IS_HELD(sema_val) &&
IOSRAM_SEMA_GET_IDX(sema_val) == IOSRAM_SEMA_SMS_IDX)) {
/* not held by SMS, we clear the semaphore */
IOSRAM_SEMA_WR(softp, 0);
}
} else {
/* not the first SBBC, we clear the semaphore */
IOSRAM_SEMA_WR(softp, 0);
}
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
return (0);
}
static int
iosram_setup_map(struct iosramsoft *softp)
{
int instance = softp->instance;
dev_info_t *dip = softp->dip;
int portid;
int proplen;
caddr_t propvalue;
struct ddi_device_acc_attr attr;
attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
/*
* Lookup IOSRAM_REG_PROP property to find out our IOSRAM length
*/
if (ddi_getlongprop(DDI_DEV_T_ANY, dip,
DDI_PROP_DONTPASS, IOSRAM_REG_PROP, (caddr_t)&propvalue,
&proplen) != DDI_PROP_SUCCESS) {
cmn_err(CE_WARN, "iosram(%d): can't find register property.\n",
instance);
return (DDI_FAILURE);
} else {
iosram_reg_t *regprop = (iosram_reg_t *)propvalue;
DPRINTF(1, ("SetupMap(%d): Got reg prop: %x %x %x\n",
instance, regprop->addr_hi,
regprop->addr_lo, regprop->size));
softp->iosramlen = regprop->size;
kmem_free(propvalue, proplen);
}
DPRINTF(1, ("SetupMap(%d): IOSRAM length: 0x%x\n", instance,
softp->iosramlen));
softp->handle = NULL;
/*
* To minimize boot time, we map the entire IOSRAM as opposed to
* mapping individual chunk via ddi_regs_map_setup() call.
*/
if (ddi_regs_map_setup(dip, 0, (caddr_t *)&softp->iosramp,
0x0, softp->iosramlen, &attr, &softp->handle) != DDI_SUCCESS) {
cmn_err(CE_WARN, "iosram(%d): failed to map IOSRAM len:%x\n",
instance, softp->iosramlen);
iosram_remove_map(softp);
return (DDI_FAILURE);
}
/*
* Lookup PORTID property on my parent hierarchy
*/
proplen = sizeof (portid);
if (ddi_getlongprop_buf(DDI_DEV_T_ANY, dip,
0, IOSRAM_PORTID_PROP, (caddr_t)&portid,
&proplen) != DDI_PROP_SUCCESS) {
cmn_err(CE_WARN, "iosram(%d): can't find portid property.\n",
instance);
iosram_remove_map(softp);
return (DDI_FAILURE);
}
softp->portid = portid;
if (iosram_sbbc_setup_map(softp) != DDI_SUCCESS) {
cmn_err(CE_WARN, "iosram(%d): can't map SBBC region.\n",
instance);
iosram_remove_map(softp);
return (DDI_FAILURE);
}
mutex_enter(&iosram_mutex);
softp->state |= IOSRAM_STATE_MAPPED;
mutex_exit(&iosram_mutex);
return (DDI_SUCCESS);
}
static void
iosram_remove_map(struct iosramsoft *softp)
{
mutex_enter(&iosram_mutex);
ASSERT((softp->state & IOSRAM_STATE_MASTER) == 0);
if (softp->handle) {
ddi_regs_map_free(&softp->handle);
softp->handle = NULL;
}
softp->iosramp = NULL;
/*
* Umap SBBC registers region. Shared with handler for SBBC
* interrupts, take intr_mutex.
*/
mutex_enter(&softp->intr_mutex);
if (softp->sbbc_region) {
ddi_regs_map_free(&softp->sbbc_handle);
softp->sbbc_region = NULL;
}
mutex_exit(&softp->intr_mutex);
softp->state &= ~IOSRAM_STATE_MAPPED;
mutex_exit(&iosram_mutex);
}
/*
* iosram_is_chosen(struct iosramsoft *softp)
*
* Looks up "chosen" node property to
* determine if it is the chosen IOSRAM.
*/
static int
iosram_is_chosen(struct iosramsoft *softp)
{
char chosen_iosram[MAXNAMELEN];
char pn[MAXNAMELEN];
int nodeid;
int chosen;
pnode_t dnode;
/*
* Get /chosen node info. prom interface will handle errors.
*/
dnode = prom_chosennode();
/*
* Look for the "iosram" property on the chosen node with a prom
* interface as ddi_find_devinfo() couldn't be used (calls
* ddi_walk_devs() that creates one extra lock on the device tree).
*/
if (prom_getprop(dnode, IOSRAM_CHOSEN_PROP, (caddr_t)&nodeid) <= 0) {
/*
* Can't find IOSRAM_CHOSEN_PROP property under chosen node
*/
cmn_err(CE_WARN,
"iosram(%d): can't find chosen iosram property\n",
softp->instance);
return (0);
}
DPRINTF(1, ("iosram(%d): Got '%x' for chosen '%s' property\n",
softp->instance, nodeid, IOSRAM_CHOSEN_PROP));
/*
* get the full OBP pathname of this node
*/
if (prom_phandle_to_path((phandle_t)nodeid, chosen_iosram,
sizeof (chosen_iosram)) < 0) {
cmn_err(CE_NOTE, "prom_phandle_to_path(%x) failed\n", nodeid);
return (0);
}
DPRINTF(1, ("iosram(%d): prom_phandle_to_path(%x) is '%s'\n",
softp->instance, nodeid, chosen_iosram));
(void) ddi_pathname(softp->dip, pn);
DPRINTF(1, ("iosram(%d): ddi_pathname(%p) is '%s'\n",
softp->instance, softp->dip, pn));
chosen = (strcmp(chosen_iosram, pn) == 0) ? 1 : 0;
DPRINTF(1, ("iosram(%d): ... %s\n", softp->instance,
chosen ? "MASTER" : "SLAVE"));
IOSRAMLOG(1, "iosram(%d): ... %s\n", softp->instance,
(chosen ? "MASTER" : "SLAVE"), NULL, NULL);
return (chosen);
}
/*
* iosram_set_master(struct iosramsoft *softp)
*
* Set master tunnel to the specified IOSRAM
* Must be called while holding iosram_mutex.
*/
static void
iosram_set_master(struct iosramsoft *softp)
{
ASSERT(mutex_owned(&iosram_mutex));
ASSERT(softp != NULL);
ASSERT(softp->state & IOSRAM_STATE_MAPPED);
ASSERT(IOSRAM_GET_HDRFIELD32(softp, status) == IOSRAM_VALID);
/*
* Clear MASTER flag on any previous IOSRAM master, if any
*/
if (iosram_master && (iosram_master != softp)) {
iosram_master->state &= ~IOSRAM_STATE_MASTER;
}
/*
* Setup new IOSRAM master
*/
iosram_update_addrs(softp);
iosram_handle = softp->handle;
softp->state |= IOSRAM_STATE_MASTER;
softp->tswitch_ok++;
iosram_master = softp;
IOSRAMLOG(1, "SETMASTER: softp:%p instance:%d\n", softp,
softp->instance, NULL, NULL);
}
/*
* iosram_read_toc()
*
* Read the TOC from an IOSRAM instance that has been mapped in.
* If the TOC is flawed or the IOSRAM isn't valid, return an error.
*/
static int
iosram_read_toc(struct iosramsoft *softp)
{
int i;
int instance = softp->instance;
uint8_t *toc_entryp;
iosram_flags_t *flagsp = NULL;
int new_nchunks;
iosram_chunk_t *new_chunks;
iosram_chunk_t *chunkp;
iosram_chunk_t *old_chunkp;
iosram_toc_entry_t index;
/*
* Never try to read the TOC out of an unmapped IOSRAM.
*/
ASSERT(softp->state & IOSRAM_STATE_MAPPED);
mutex_enter(&iosram_mutex);
/*
* Check to make sure this IOSRAM is marked valid. Return
* an error if it isn't.
*/
if (IOSRAM_GET_HDRFIELD32(softp, status) != IOSRAM_VALID) {
DPRINTF(1, ("iosram_read_toc(%d): IOSRAM not flagged valid\n",
instance));
mutex_exit(&iosram_mutex);
return (EINVAL);
}
/*
* Get the location of the TOC.
*/
toc_entryp = softp->iosramp + IOSRAM_GET_HDRFIELD32(softp, toc_offset);
/*
* Read the index entry from the TOC and make sure it looks correct.
*/
ddi_rep_get8(softp->handle, (uint8_t *)&index, toc_entryp,
sizeof (iosram_toc_entry_t), DDI_DEV_AUTOINCR);
if ((index.key != IOSRAM_INDEX_KEY) ||
(index.off != IOSRAM_INDEX_OFF)) {
cmn_err(CE_WARN, "iosram(%d): invalid TOC index.\n", instance);
mutex_exit(&iosram_mutex);
return (EINVAL);
}
/*
* Allocate storage for the new chunks array and initialize it with data
* from the TOC and callback data from the corresponding old chunk, if
* it exists.
*/
new_nchunks = index.len - 1;
new_chunks = (iosram_chunk_t *)kmem_zalloc(new_nchunks *
sizeof (iosram_chunk_t), KM_SLEEP);
for (i = 0, chunkp = new_chunks; i < new_nchunks; i++, chunkp++) {
toc_entryp += sizeof (iosram_toc_entry_t);
ddi_rep_get8(softp->handle, (uint8_t *)&(chunkp->toc_data),
toc_entryp, sizeof (iosram_toc_entry_t), DDI_DEV_AUTOINCR);
chunkp->hash = NULL;
if ((chunkp->toc_data.off < softp->iosramlen) &&
(chunkp->toc_data.len <= softp->iosramlen) &&
((chunkp->toc_data.off + chunkp->toc_data.len) <=
softp->iosramlen)) {
chunkp->basep = softp->iosramp + chunkp->toc_data.off;
DPRINTF(1,
("iosram_read_toc(%d): k:%x o:%x l:%x p:%x\n",
instance, chunkp->toc_data.key,
chunkp->toc_data.off, chunkp->toc_data.len,
chunkp->basep));
} else {
cmn_err(CE_WARN, "iosram(%d): TOC entry %d"
"out of range... off:%x len:%x\n",
instance, i + 1, chunkp->toc_data.off,
chunkp->toc_data.len);
kmem_free(new_chunks, new_nchunks *
sizeof (iosram_chunk_t));
mutex_exit(&iosram_mutex);
return (EINVAL);
}
/*
* Note the existence of the flags chunk, which is required in
* a correct TOC.
*/
if (chunkp->toc_data.key == IOSRAM_FLAGS_KEY) {
flagsp = (iosram_flags_t *)chunkp->basep;
}
/*
* If there was an entry for this chunk in the old list, copy
* the callback data from old to new storage.
*/
if ((nchunks > 0) &&
((old_chunkp = iosram_find_chunk(chunkp->toc_data.key)) !=
NULL)) {
bcopy(&(old_chunkp->cback), &(chunkp->cback),
sizeof (iosram_cback_t));
}
}
/*
* The TOC is malformed if there is no entry for the flags chunk.
*/
if (flagsp == NULL) {
kmem_free(new_chunks, new_nchunks * sizeof (iosram_chunk_t));
mutex_exit(&iosram_mutex);
return (EINVAL);
}
/*
* Free any memory that is no longer needed and install the new data
* as current data.
*/
if (chunks != NULL) {
kmem_free(chunks, nchunks * sizeof (iosram_chunk_t));
}
chunks = new_chunks;
nchunks = new_nchunks;
iosram_init_hashtab();
mutex_exit(&iosram_mutex);
return (0);
}
/*
* iosram_init_hashtab()
*
* Initialize the hash table and populate it with the IOSRAM
* chunks previously read from the TOC. The caller must hold the
* ioram_mutex lock.
*/
static void
iosram_init_hashtab(void)
{
int i, bucket;
iosram_chunk_t *chunkp;
ASSERT(mutex_owned(&iosram_mutex));
for (i = 0; i < IOSRAM_HASHSZ; i++) {
iosram_hashtab[i] = NULL;
}
if (chunks) {
for (i = 0, chunkp = chunks; i < nchunks; i++, chunkp++) {
/*
* Hide the flags chunk by leaving it out of the hash
* table.
*/
if (chunkp->toc_data.key == IOSRAM_FLAGS_KEY) {
continue;
}
/*
* Add the current chunk to the hash table.
*/
bucket = IOSRAM_HASH(chunkp->toc_data.key);
chunkp->hash = iosram_hashtab[bucket];
iosram_hashtab[bucket] = chunkp;
}
}
}
/*
* iosram_update_addrs()
*
* Process the chunk list, updating each chunk's basep, which is a pointer
* to the beginning of the chunk's memory in kvaddr space. Record the
* basep value of the flags chunk to speed up flag access. The caller
* must hold the iosram_mutex lock.
*/
static void
iosram_update_addrs(struct iosramsoft *softp)
{
int i;
iosram_flags_t *flagsp;
iosram_chunk_t *chunkp;
ASSERT(mutex_owned(&iosram_mutex));
/*
* First go through all of the chunks updating their base pointers and
* looking for the flags chunk.
*/
for (i = 0, chunkp = chunks; i < nchunks; i++, chunkp++) {
chunkp->basep = softp->iosramp + chunkp->toc_data.off;
if (chunkp->toc_data.key == IOSRAM_FLAGS_KEY) {
flagsp = (iosram_flags_t *)(chunkp->basep);
DPRINTF(1,
("iosram_update_addrs flags: o:0x%08x p:%p",
chunkp->toc_data.off, flagsp));
}
}
/*
* Now, go through and update each chunk's flags pointer. This can't be
* done in the first loop because we don't have the address of the flags
* chunk yet.
*/
for (i = 0, chunkp = chunks; i < nchunks; i++, chunkp++) {
chunkp->flagsp = flagsp++;
DPRINTF(1, ("iosram_update_addrs: k:0x%x f:%p\n",
chunkp->toc_data.key, chunkp->flagsp));
}
}
/*
* iosram_find_chunk(key)
*
* Return a pointer to iosram_chunk structure corresponding to the
* "key" IOSRAM chunk. The caller must hold the iosram_mutex lock.
*/
static iosram_chunk_t *
iosram_find_chunk(uint32_t key)
{
iosram_chunk_t *chunkp;
int index = IOSRAM_HASH(key);
ASSERT(mutex_owned(&iosram_mutex));
for (chunkp = iosram_hashtab[index]; chunkp; chunkp = chunkp->hash) {
if (chunkp->toc_data.key == key) {
break;
}
}
return (chunkp);
}
/*
* iosram_add_intr(iosramsoft_t *)
*/
static int
iosram_add_intr(iosramsoft_t *softp)
{
IOSRAMLOG(2, "ADDINTR: softp:%p instance:%d\n",
softp, softp->instance, NULL, NULL);
if (ddi_add_softintr(softp->dip, DDI_SOFTINT_MED,
&softp->softintr_id, &softp->soft_iblk, NULL,
iosram_softintr, (caddr_t)softp) != DDI_SUCCESS) {
cmn_err(CE_WARN,
"iosram(%d): Can't register softintr.\n",
softp->instance);
return (DDI_FAILURE);
}
if (ddi_add_intr(softp->dip, 0, &softp->real_iblk, NULL,
iosram_intr, (caddr_t)softp) != DDI_SUCCESS) {
cmn_err(CE_WARN,
"iosram(%d): Can't register intr"
" handler.\n", softp->instance);
ddi_remove_softintr(softp->softintr_id);
return (DDI_FAILURE);
}
/*
* Enable SBBC interrupts
*/
ddi_put32(softp->sbbc_handle, &(softp->sbbc_region->int_enable.reg),
IOSRAM_SBBC_INT0|IOSRAM_SBBC_INT1);
return (DDI_SUCCESS);
}
/*
* iosram_remove_intr(iosramsoft_t *)
*/
static int
iosram_remove_intr(iosramsoft_t *softp)
{
IOSRAMLOG(2, "REMINTR: softp:%p instance:%d\n",
softp, softp->instance, NULL, NULL);
/*
* Disable SBBC interrupts if SBBC is mapped in
*/
if (softp->sbbc_region) {
ddi_put32(softp->sbbc_handle,
&(softp->sbbc_region->int_enable.reg), 0);
}
/*
* Remove SBBC interrupt handler
*/
ddi_remove_intr(softp->dip, 0, softp->real_iblk);
/*
* Remove soft interrupt handler
*/
mutex_enter(&iosram_mutex);
if (softp->softintr_id != NULL) {
ddi_remove_softintr(softp->softintr_id);
softp->softintr_id = NULL;
}
mutex_exit(&iosram_mutex);
return (0);
}
/*
* iosram_add_instance(iosramsoft_t *)
* Must be called while holding iosram_mutex
*/
static void
iosram_add_instance(iosramsoft_t *new_softp)
{
#ifdef DEBUG
int instance = new_softp->instance;
iosramsoft_t *softp;
#endif
ASSERT(mutex_owned(&iosram_mutex));
#if defined(DEBUG)
/* Verify that this instance is not in the list */
for (softp = iosram_instances; softp != NULL; softp = softp->next) {
ASSERT(softp->instance != instance);
}
#endif
/*
* Add this instance to the list
*/
if (iosram_instances != NULL) {
iosram_instances->prev = new_softp;
}
new_softp->next = iosram_instances;
new_softp->prev = NULL;
iosram_instances = new_softp;
}
/*
* iosram_remove_instance(int instance)
* Must be called while holding iosram_mutex
*/
static void
iosram_remove_instance(int instance)
{
iosramsoft_t *softp;
/*
* Remove specified instance from the iosram_instances list so that
* it can't be chosen for tunnel in future.
*/
ASSERT(mutex_owned(&iosram_mutex));
for (softp = iosram_instances; softp != NULL; softp = softp->next) {
if (softp->instance == instance) {
if (softp->next != NULL) {
softp->next->prev = softp->prev;
}
if (softp->prev != NULL) {
softp->prev->next = softp->next;
}
if (iosram_instances == softp) {
iosram_instances = softp->next;
}
return;
}
}
}
/*
* iosram_sema_acquire: Acquire hardware semaphore.
* Return 0 if the semaphore could be acquired, or one of the following
* possible values:
* EAGAIN: there is a tunnel switch in progress
* EBUSY: the semaphore was already "held"
* ENXIO: an IO error occured (e.g. SBBC not mapped)
* If old_value is not NULL, the location it points to will be updated
* with the semaphore value read when attempting to acquire it.
*/
int
iosram_sema_acquire(uint32_t *old_value)
{
struct iosramsoft *softp;
int rv;
uint32_t sema_val;
DPRINTF(2, ("IOSRAM: in iosram_sema_acquire\n"));
mutex_enter(&iosram_mutex);
/*
* Disallow access if there is a tunnel switch in progress.
*/
if (iosram_tswitch_active) {
mutex_exit(&iosram_mutex);
return (EAGAIN);
}
/*
* Use current master IOSRAM for operation, fail if none is
* currently active.
*/
if ((softp = iosram_master) == NULL) {
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM: iosram_sema_acquire: no master\n"));
return (ENXIO);
}
mutex_enter(&softp->intr_mutex);
/*
* Fail if SBBC region has not been mapped. This shouldn't
* happen if we have a master IOSRAM, but we double-check.
*/
if (softp->sbbc_region == NULL) {
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM(%d): iosram_sema_acquire: "
"SBBC not mapped\n", softp->instance));
return (ENXIO);
}
/* read semaphore value */
sema_val = IOSRAM_SEMA_RD(softp);
if (old_value != NULL)
*old_value = sema_val;
if (IOSRAM_SEMA_IS_HELD(sema_val)) {
/* semaphore was held by someone else */
rv = EBUSY;
} else {
/* semaphore was not held, we just acquired it */
rv = 0;
}
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM(%d): iosram_sema_acquire: "
"old value=0x%x rv=%d\n", softp->instance, sema_val, rv));
return (rv);
}
/*
* iosram_sema_release: Release hardware semaphore.
* This function will "release" the hardware semaphore, and return 0 on
* success. If an error occured, one of the following values will be
* returned:
* EAGAIN: there is a tunnel switch in progress
* ENXIO: an IO error occured (e.g. SBBC not mapped)
*/
int
iosram_sema_release(void)
{
struct iosramsoft *softp;
DPRINTF(2, ("IOSRAM: in iosram_sema_release\n"));
mutex_enter(&iosram_mutex);
/*
* Disallow access if there is a tunnel switch in progress.
*/
if (iosram_tswitch_active) {
mutex_exit(&iosram_mutex);
return (EAGAIN);
}
/*
* Use current master IOSRAM for operation, fail if none is
* currently active.
*/
if ((softp = iosram_master) == NULL) {
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM: iosram_sema_release: no master\n"));
return (ENXIO);
}
mutex_enter(&softp->intr_mutex);
/*
* Fail if SBBC region has not been mapped in. This shouldn't
* happen if we have a master IOSRAM, but we double-check.
*/
if (softp->sbbc_region == NULL) {
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM(%d): iosram_sema_release: "
"SBBC not mapped\n", softp->instance));
return (ENXIO);
}
/* Release semaphore by clearing our semaphore register */
IOSRAM_SEMA_WR(softp, 0);
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
DPRINTF(1, ("IOSRAM(%d): iosram_sema_release: success\n",
softp->instance));
return (0);
}
#if defined(IOSRAM_LOG)
void
iosram_log(caddr_t fmt, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
{
uint32_t seq;
iosram_log_t *logp;
mutex_enter(&iosram_log_mutex);
seq = iosram_logseq++;
logp = &iosram_logbuf[seq % IOSRAM_MAXLOG];
logp->seq = seq;
logp->tstamp = ddi_get_lbolt();
logp->fmt = fmt;
logp->arg1 = a1;
logp->arg2 = a2;
logp->arg3 = a3;
logp->arg4 = a4;
mutex_exit(&iosram_log_mutex);
if (iosram_log_print) {
cmn_err(CE_CONT, "#%x @%lx ", logp->seq, logp->tstamp);
if (logp->fmt) {
cmn_err(CE_CONT, logp->fmt, logp->arg1, logp->arg2,
logp->arg3, logp->arg4);
if (logp->fmt[strlen(logp->fmt)-1] != '\n') {
cmn_err(CE_CONT, "\n");
}
} else {
cmn_err(CE_CONT, "fmt:%p args: %lx %lx %lx %lx\n",
logp->fmt, logp->arg1, logp->arg2, logp->arg3,
logp->arg4);
}
}
}
#endif /* IOSRAM_LOG */
#if defined(DEBUG)
/*
* iosram_get_keys(buf, len)
* Return IOSRAM TOC in the specified buffer
*/
static int
iosram_get_keys(iosram_toc_entry_t *bufp, uint32_t *len)
{
struct iosram_chunk *chunkp;
int error = 0;
int i;
int cnt = (*len) / sizeof (iosram_toc_entry_t);
IOSRAMLOG(2, "iosram_get_keys(bufp:%p *len:%x)\n", bufp, *len, NULL,
NULL);
/*
* Copy data while holding the lock to prevent any data
* corruption or invalid pointer dereferencing.
*/
mutex_enter(&iosram_mutex);
if (iosram_master == NULL) {
error = EIO;
} else {
for (i = 0, chunkp = chunks; i < nchunks && i < cnt;
i++, chunkp++) {
bufp[i].key = chunkp->toc_data.key;
bufp[i].off = chunkp->toc_data.off;
bufp[i].len = chunkp->toc_data.len;
bufp[i].unused = chunkp->toc_data.unused;
}
*len = i * sizeof (iosram_toc_entry_t);
}
mutex_exit(&iosram_mutex);
return (error);
}
/*
* iosram_print_state(instance)
*/
static void
iosram_print_state(int instance)
{
struct iosramsoft *softp;
char pn[MAXNAMELEN];
if (instance < 0) {
softp = iosram_master;
} else {
softp = ddi_get_soft_state(iosramsoft_statep, instance);
}
if (softp == NULL) {
cmn_err(CE_CONT, "iosram_print_state: Can't find instance %d\n",
instance);
return;
}
instance = softp->instance;
mutex_enter(&iosram_mutex);
mutex_enter(&softp->intr_mutex);
cmn_err(CE_CONT, "iosram_print_state(%d): ... %s\n", instance,
((softp == iosram_master) ? "MASTER" : "SLAVE"));
(void) ddi_pathname(softp->dip, pn);
cmn_err(CE_CONT, " pathname:%s\n", pn);
cmn_err(CE_CONT, " instance:%d portid:%d iosramlen:0x%x\n",
softp->instance, softp->portid, softp->iosramlen);
cmn_err(CE_CONT, " softp:%p handle:%p iosramp:%p\n", softp,
softp->handle, softp->iosramp);
cmn_err(CE_CONT, " state:0x%x tswitch_ok:%x tswitch_fail:%x\n",
softp->state, softp->tswitch_ok, softp->tswitch_fail);
cmn_err(CE_CONT, " softintr_id:%p intr_busy:%x intr_pending:%x\n",
softp->softintr_id, softp->intr_busy, softp->intr_pending);
mutex_exit(&softp->intr_mutex);
mutex_exit(&iosram_mutex);
}
/*
* iosram_print_stats()
*/
static void
iosram_print_stats()
{
uint32_t calls;
cmn_err(CE_CONT, "iosram_stats:\n");
calls = iosram_stats.read;
cmn_err(CE_CONT, " read ... calls:%x bytes:%lx avg_sz:%x\n",
calls, iosram_stats.bread,
(uint32_t)((calls != 0) ? (iosram_stats.bread/calls) : 0));
calls = iosram_stats.write;
cmn_err(CE_CONT, " write ... calls:%x bytes:%lx avg_sz:%x\n",
calls, iosram_stats.bwrite,
(uint32_t)((calls != 0) ? (iosram_stats.bwrite/calls) : 0));
cmn_err(CE_CONT, " intr recv (real:%x soft:%x) sent:%x cback:%x\n",
iosram_stats.intr_recv, iosram_stats.sintr_recv,
iosram_stats.intr_send, iosram_stats.callbacks);
cmn_err(CE_CONT, " tswitch: %x getflag:%x setflag:%x\n",
iosram_stats.tswitch, iosram_stats.getflag,
iosram_stats.setflag);
cmn_err(CE_CONT, " iosram_rw_active_max: %x\n", iosram_rw_active_max);
}
static void
iosram_print_cback()
{
iosram_chunk_t *chunkp;
int i;
/*
* Print callback handlers
*/
mutex_enter(&iosram_mutex);
cmn_err(CE_CONT, "IOSRAM callbacks:\n");
for (i = 0, chunkp = chunks; i < nchunks; i++, chunkp++) {
if (chunkp->cback.handler) {
cmn_err(CE_CONT, " %2d: key:0x%x hdlr:%p arg:%p "
"busy:%d unreg:%d\n", i, chunkp->toc_data.key,
chunkp->cback.handler, chunkp->cback.arg,
chunkp->cback.busy, chunkp->cback.unregister);
}
}
mutex_exit(&iosram_mutex);
}
static void
iosram_print_flags()
{
int i;
uint32_t *keys;
iosram_flags_t *flags;
mutex_enter(&iosram_mutex);
if (iosram_master == NULL) {
mutex_exit(&iosram_mutex);
cmn_err(CE_CONT, "IOSRAM Flags: not accessible\n");
return;
}
keys = kmem_alloc(nchunks * sizeof (uint32_t), KM_SLEEP);
flags = kmem_alloc(nchunks * sizeof (iosram_flags_t), KM_SLEEP);
for (i = 0; i < nchunks; i++) {
keys[i] = chunks[i].toc_data.key;
ddi_rep_get8(iosram_handle, (uint8_t *)&(flags[i]),
(uint8_t *)(chunks[i].flagsp), sizeof (iosram_flags_t),
DDI_DEV_AUTOINCR);
}
mutex_exit(&iosram_mutex);
cmn_err(CE_CONT, "IOSRAM Flags:\n");
for (i = 0; i < nchunks; i++) {
cmn_err(CE_CONT,
" %2d: key: 0x%x data_valid:%x int_pending:%x\n",
i, keys[i], flags[i].data_valid, flags[i].int_pending);
}
kmem_free(keys, nchunks * sizeof (uint32_t));
kmem_free(flags, nchunks * sizeof (iosram_flags_t));
}
/*PRINTFLIKE1*/
static void
iosram_dprintf(const char *fmt, ...)
{
char msg_buf[256];
va_list adx;
va_start(adx, fmt);
vsprintf(msg_buf, fmt, adx);
va_end(adx);
cmn_err(CE_CONT, "%s", msg_buf);
}
#endif /* DEBUG */
#if IOSRAM_LOG
/*
* iosram_print_log(int cnt)
* Print last few entries of the IOSRAM log in reverse order
*/
static void
iosram_print_log(int cnt)
{
int i;
if (cnt <= 0) {
cnt = 20;
} else if (cnt > IOSRAM_MAXLOG) {
cnt = IOSRAM_MAXLOG;
}
cmn_err(CE_CONT,
"\niosram_logseq: 0x%x lbolt: %lx iosram_log_level:%x\n",
iosram_logseq, ddi_get_lbolt(), iosram_log_level);
cmn_err(CE_CONT, "iosram_logbuf: %p max entries:0x%x\n",
iosram_logbuf, IOSRAM_MAXLOG);
for (i = iosram_logseq; --i >= 0 && --cnt >= 0; ) {
iosram_log_t *logp;
mutex_enter(&iosram_log_mutex);
logp = &iosram_logbuf[i %IOSRAM_MAXLOG];
cmn_err(CE_CONT, "#%x @%lx ", logp->seq, logp->tstamp);
if (logp->fmt) {
cmn_err(CE_CONT, logp->fmt, logp->arg1, logp->arg2,
logp->arg3, logp->arg4);
if (logp->fmt[strlen(logp->fmt)-1] != '\n') {
cmn_err(CE_CONT, "\n");
}
} else {
cmn_err(CE_CONT, "fmt:%p args: %lx %lx %lx %lx\n",
logp->fmt, logp->arg1, logp->arg2,
logp->arg3, logp->arg4);
}
mutex_exit(&iosram_log_mutex);
}
}
#endif /* IOSRAM_LOG */
|