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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
* Copyright (c) 2016 by Delphix. All rights reserved.
*/
/*
* sun4 specific DDI implementation
*/
#include <sys/cpuvar.h>
#include <sys/ddi_subrdefs.h>
#include <sys/machsystm.h>
#include <sys/sunndi.h>
#include <sys/sysmacros.h>
#include <sys/ontrap.h>
#include <vm/seg_kmem.h>
#include <sys/membar.h>
#include <sys/dditypes.h>
#include <sys/ndifm.h>
#include <sys/fm/io/ddi.h>
#include <sys/ivintr.h>
#include <sys/bootconf.h>
#include <sys/conf.h>
#include <sys/ethernet.h>
#include <sys/idprom.h>
#include <sys/promif.h>
#include <sys/prom_plat.h>
#include <sys/systeminfo.h>
#include <sys/fpu/fpusystm.h>
#include <sys/vm.h>
#include <sys/ddi_isa.h>
#include <sys/modctl.h>
dev_info_t *get_intr_parent(dev_info_t *, dev_info_t *,
ddi_intr_handle_impl_t *);
#pragma weak get_intr_parent
int process_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t,
ddi_intr_handle_impl_t *, void *);
#pragma weak process_intr_ops
void cells_1275_copy(prop_1275_cell_t *, prop_1275_cell_t *, int32_t);
prop_1275_cell_t *cells_1275_cmp(prop_1275_cell_t *, prop_1275_cell_t *,
int32_t len);
#pragma weak cells_1275_copy
/*
* Wrapper for ddi_prop_lookup_int_array().
* This is handy because it returns the prop length in
* bytes which is what most of the callers require.
*/
static int
get_prop_int_array(dev_info_t *di, char *pname, int **pval, uint_t *plen)
{
int ret;
if ((ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, di,
DDI_PROP_DONTPASS, pname, pval, plen)) == DDI_PROP_SUCCESS) {
*plen = (*plen) * (uint_t)sizeof (int);
}
return (ret);
}
/*
* SECTION: DDI Node Configuration
*/
/*
* init_regspec_64:
*
* If the parent #size-cells is 2, convert the upa-style or
* safari-style reg property from 2-size cells to 1 size cell
* format, ignoring the size_hi, which must be zero for devices.
* (It won't be zero in the memory list properties in the memory
* nodes, but that doesn't matter here.)
*/
struct ddi_parent_private_data *
init_regspec_64(dev_info_t *dip)
{
struct ddi_parent_private_data *pd;
dev_info_t *parent;
int size_cells;
/*
* If there are no "reg"s in the child node, return.
*/
pd = ddi_get_parent_data(dip);
if ((pd == NULL) || (pd->par_nreg == 0)) {
return (pd);
}
parent = ddi_get_parent(dip);
size_cells = ddi_prop_get_int(DDI_DEV_T_ANY, parent,
DDI_PROP_DONTPASS, "#size-cells", 1);
if (size_cells != 1) {
int n, j;
struct regspec *irp;
struct reg_64 {
uint_t addr_hi, addr_lo, size_hi, size_lo;
};
struct reg_64 *r64_rp;
struct regspec *rp;
uint_t len = 0;
int *reg_prop;
ASSERT(size_cells == 2);
/*
* We already looked the property up once before if
* pd is non-NULL.
*/
(void) ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
DDI_PROP_DONTPASS, OBP_REG, ®_prop, &len);
ASSERT(len != 0);
n = sizeof (struct reg_64) / sizeof (int);
n = len / n;
/*
* We're allocating a buffer the size of the PROM's property,
* but we're only using a smaller portion when we assign it
* to a regspec. We do this so that in the
* impl_ddi_sunbus_removechild function, we will
* always free the right amount of memory.
*/
irp = rp = (struct regspec *)reg_prop;
r64_rp = (struct reg_64 *)pd->par_reg;
for (j = 0; j < n; ++j, ++rp, ++r64_rp) {
ASSERT(r64_rp->size_hi == 0);
rp->regspec_bustype = r64_rp->addr_hi;
rp->regspec_addr = r64_rp->addr_lo;
rp->regspec_size = r64_rp->size_lo;
}
ddi_prop_free((void *)pd->par_reg);
pd->par_nreg = n;
pd->par_reg = irp;
}
return (pd);
}
/*
* Create a ddi_parent_private_data structure from the ddi properties of
* the dev_info node.
*
* The "reg" is required if the driver wishes to create mappings on behalf
* of the device. The "reg" property is assumed to be a list of at least
* one triplet
*
* <bustype, address, size>*1
*
* The "interrupt" property is no longer part of parent private data on
* sun4u. The interrupt parent is may not be the device tree parent.
*
* The "ranges" property describes the mapping of child addresses to parent
* addresses.
*
* N.B. struct rangespec is defined for the following default values:
* parent child
* #address-cells 2 2
* #size-cells 1 1
* This function doesn't deal with non-default cells and will not create
* ranges in such cases.
*/
void
make_ddi_ppd(dev_info_t *child, struct ddi_parent_private_data **ppd)
{
struct ddi_parent_private_data *pdptr;
int *reg_prop, *rng_prop;
uint_t reg_len = 0, rng_len = 0;
dev_info_t *parent;
int parent_addr_cells, parent_size_cells;
int child_addr_cells, child_size_cells;
*ppd = pdptr = kmem_zalloc(sizeof (*pdptr), KM_SLEEP);
/*
* root node has no parent private data, so *ppd should
* be initialized for naming to work properly.
*/
if ((parent = ddi_get_parent(child)) == NULL)
return;
/*
* Set reg field of parent data from "reg" property
*/
if ((get_prop_int_array(child, OBP_REG, ®_prop, ®_len)
== DDI_PROP_SUCCESS) && (reg_len != 0)) {
pdptr->par_nreg = (int)(reg_len / sizeof (struct regspec));
pdptr->par_reg = (struct regspec *)reg_prop;
}
/*
* "ranges" property ...
*
* This function does not handle cases where #address-cells != 2
* and * min(parent, child) #size-cells != 1 (see bugid 4211124).
*
* Nexus drivers with such exceptions (e.g. pci ranges)
* should either create a separate function for handling
* ranges or not use parent private data to store ranges.
*/
/* root node has no ranges */
if ((parent = ddi_get_parent(child)) == NULL)
return;
child_addr_cells = ddi_prop_get_int(DDI_DEV_T_ANY, child,
DDI_PROP_DONTPASS, "#address-cells", 2);
child_size_cells = ddi_prop_get_int(DDI_DEV_T_ANY, child,
DDI_PROP_DONTPASS, "#size-cells", 1);
parent_addr_cells = ddi_prop_get_int(DDI_DEV_T_ANY, parent,
DDI_PROP_DONTPASS, "#address-cells", 2);
parent_size_cells = ddi_prop_get_int(DDI_DEV_T_ANY, parent,
DDI_PROP_DONTPASS, "#size-cells", 1);
if (child_addr_cells != 2 || parent_addr_cells != 2 ||
(child_size_cells != 1 && parent_size_cells != 1)) {
NDI_CONFIG_DEBUG((CE_NOTE, "!ranges not made in parent data; "
"#address-cells or #size-cells have non-default value"));
return;
}
if (get_prop_int_array(child, OBP_RANGES, &rng_prop, &rng_len)
== DDI_PROP_SUCCESS) {
pdptr->par_nrng = rng_len / (int)(sizeof (struct rangespec));
pdptr->par_rng = (struct rangespec *)rng_prop;
}
}
/*
* Free ddi_parent_private_data structure
*/
void
impl_free_ddi_ppd(dev_info_t *dip)
{
struct ddi_parent_private_data *pdptr = ddi_get_parent_data(dip);
if (pdptr == NULL)
return;
if (pdptr->par_nrng != 0)
ddi_prop_free((void *)pdptr->par_rng);
if (pdptr->par_nreg != 0)
ddi_prop_free((void *)pdptr->par_reg);
kmem_free(pdptr, sizeof (*pdptr));
ddi_set_parent_data(dip, NULL);
}
/*
* Name a child of sun busses based on the reg spec.
* Handles the following properties:
*
* Property value
* Name type
*
* reg register spec
* interrupts new (bus-oriented) interrupt spec
* ranges range spec
*
* This may be called multiple times, independent of
* initchild calls.
*/
static int
impl_sunbus_name_child(dev_info_t *child, char *name, int namelen)
{
struct ddi_parent_private_data *pdptr;
struct regspec *rp;
/*
* Fill in parent-private data and this function returns to us
* an indication if it used "registers" to fill in the data.
*/
if (ddi_get_parent_data(child) == NULL) {
make_ddi_ppd(child, &pdptr);
ddi_set_parent_data(child, pdptr);
}
/*
* No reg property, return null string as address
* (e.g. root node)
*/
name[0] = '\0';
if (sparc_pd_getnreg(child) == 0) {
return (DDI_SUCCESS);
}
rp = sparc_pd_getreg(child, 0);
(void) snprintf(name, namelen, "%x,%x",
rp->regspec_bustype, rp->regspec_addr);
return (DDI_SUCCESS);
}
/*
* Called from the bus_ctl op of some drivers.
* to implement the DDI_CTLOPS_INITCHILD operation.
*
* NEW drivers should NOT use this function, but should declare
* there own initchild/uninitchild handlers. (This function assumes
* the layout of the parent private data and the format of "reg",
* "ranges", "interrupts" properties and that #address-cells and
* #size-cells of the parent bus are defined to be default values.)
*/
int
impl_ddi_sunbus_initchild(dev_info_t *child)
{
char name[MAXNAMELEN];
(void) impl_sunbus_name_child(child, name, MAXNAMELEN);
ddi_set_name_addr(child, name);
/*
* Try to merge .conf node. If successful, return failure to
* remove this child.
*/
if ((ndi_dev_is_persistent_node(child) == 0) &&
(ndi_merge_node(child, impl_sunbus_name_child) == DDI_SUCCESS)) {
impl_ddi_sunbus_removechild(child);
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* A better name for this function would be impl_ddi_sunbus_uninitchild()
* It does not remove the child, it uninitializes it, reclaiming the
* resources taken by impl_ddi_sunbus_initchild.
*/
void
impl_ddi_sunbus_removechild(dev_info_t *dip)
{
impl_free_ddi_ppd(dip);
ddi_set_name_addr(dip, NULL);
/*
* Strip the node to properly convert it back to prototype form
*/
impl_rem_dev_props(dip);
}
/*
* SECTION: DDI Interrupt
*/
void
cells_1275_copy(prop_1275_cell_t *from, prop_1275_cell_t *to, int32_t len)
{
int i;
for (i = 0; i < len; i++)
*to = *from;
}
prop_1275_cell_t *
cells_1275_cmp(prop_1275_cell_t *cell1, prop_1275_cell_t *cell2, int32_t len)
{
prop_1275_cell_t *match_cell = 0;
int32_t i;
for (i = 0; i < len; i++)
if (cell1[i] != cell2[i]) {
match_cell = &cell1[i];
break;
}
return (match_cell);
}
/*
* get_intr_parent() is a generic routine that process a 1275 interrupt
* map (imap) property. This function returns a dev_info_t structure
* which claims ownership of the interrupt domain.
* It also returns the new interrupt translation within this new domain.
* If an interrupt-parent or interrupt-map property are not found,
* then we fallback to using the device tree's parent.
*
* imap entry format:
* <reg>,<interrupt>,<phandle>,<translated interrupt>
* reg - The register specification in the interrupts domain
* interrupt - The interrupt specification
* phandle - PROM handle of the device that owns the xlated interrupt domain
* translated interrupt - interrupt specifier in the parents domain
* note: <reg>,<interrupt> - The reg and interrupt can be combined to create
* a unique entry called a unit interrupt specifier.
*
* Here's the processing steps:
* step1 - If the interrupt-parent property exists, create the ispec and
* return the dip of the interrupt parent.
* step2 - Extract the interrupt-map property and the interrupt-map-mask
* If these don't exist, just return the device tree parent.
* step3 - build up the unit interrupt specifier to match against the
* interrupt map property
* step4 - Scan the interrupt-map property until a match is found
* step4a - Extract the interrupt parent
* step4b - Compare the unit interrupt specifier
*/
dev_info_t *
get_intr_parent(dev_info_t *pdip, dev_info_t *dip, ddi_intr_handle_impl_t *hdlp)
{
prop_1275_cell_t *imap, *imap_mask, *scan, *reg_p, *match_req;
int32_t imap_sz, imap_cells, imap_scan_cells, imap_mask_sz,
addr_cells, intr_cells, reg_len, i, j;
int32_t match_found = 0;
dev_info_t *intr_parent_dip = NULL;
uint32_t *intr = &hdlp->ih_vector;
uint32_t nodeid;
#ifdef DEBUG
static int debug = 0;
#endif
/*
* step1
* If we have an interrupt-parent property, this property represents
* the nodeid of our interrupt parent.
*/
if ((nodeid = ddi_getprop(DDI_DEV_T_ANY, dip, 0,
"interrupt-parent", -1)) != -1) {
intr_parent_dip = e_ddi_nodeid_to_dip(nodeid);
ASSERT(intr_parent_dip);
/*
* Attach the interrupt parent.
*
* N.B. e_ddi_nodeid_to_dip() isn't safe under DR.
* Also, interrupt parent isn't held. This needs
* to be revisited if DR-capable platforms implement
* interrupt redirection.
*/
if (i_ddi_attach_node_hierarchy(intr_parent_dip)
!= DDI_SUCCESS) {
ndi_rele_devi(intr_parent_dip);
return (NULL);
}
return (intr_parent_dip);
}
/*
* step2
* Get interrupt map structure from PROM property
*/
if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, DDI_PROP_DONTPASS,
"interrupt-map", (caddr_t)&imap, &imap_sz)
!= DDI_PROP_SUCCESS) {
/*
* If we don't have an imap property, default to using the
* device tree.
*/
ndi_hold_devi(pdip);
return (pdip);
}
/* Get the interrupt mask property */
if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, DDI_PROP_DONTPASS,
"interrupt-map-mask", (caddr_t)&imap_mask, &imap_mask_sz)
!= DDI_PROP_SUCCESS) {
/*
* If we don't find this property, we have to fail the request
* because the 1275 imap property wasn't defined correctly.
*/
ASSERT(intr_parent_dip == NULL);
goto exit2;
}
/* Get the address cell size */
addr_cells = ddi_getprop(DDI_DEV_T_ANY, pdip, 0,
"#address-cells", 2);
/* Get the interrupts cell size */
intr_cells = ddi_getprop(DDI_DEV_T_ANY, pdip, 0,
"#interrupt-cells", 1);
/*
* step3
* Now lets build up the unit interrupt specifier e.g. reg,intr
* and apply the imap mask. match_req will hold this when we're
* through.
*/
if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "reg",
(caddr_t)®_p, ®_len) != DDI_SUCCESS) {
ASSERT(intr_parent_dip == NULL);
goto exit3;
}
match_req = kmem_alloc(CELLS_1275_TO_BYTES(addr_cells) +
CELLS_1275_TO_BYTES(intr_cells), KM_SLEEP);
for (i = 0; i < addr_cells; i++)
match_req[i] = (reg_p[i] & imap_mask[i]);
for (j = 0; j < intr_cells; i++, j++)
match_req[i] = (intr[j] & imap_mask[i]);
/* Calculate the imap size in cells */
imap_cells = BYTES_TO_1275_CELLS(imap_sz);
#ifdef DEBUG
if (debug)
prom_printf("reg cell size 0x%x, intr cell size 0x%x, "
"match_request 0x%p, imap 0x%p\n", addr_cells, intr_cells,
(void *)match_req, (void *)imap);
#endif
/*
* Scan the imap property looking for a match of the interrupt unit
* specifier. This loop is rather complex since the data within the
* imap property may vary in size.
*/
for (scan = imap, imap_scan_cells = i = 0;
imap_scan_cells < imap_cells; scan += i, imap_scan_cells += i) {
int new_intr_cells;
/* Set the index to the nodeid field */
i = addr_cells + intr_cells;
/*
* step4a
* Translate the nodeid field to a dip
*/
ASSERT(intr_parent_dip == NULL);
intr_parent_dip = e_ddi_nodeid_to_dip((uint_t)scan[i++]);
ASSERT(intr_parent_dip != 0);
#ifdef DEBUG
if (debug)
prom_printf("scan 0x%p\n", (void *)scan);
#endif
/*
* The tmp_dip describes the new domain, get it's interrupt
* cell size
*/
new_intr_cells = ddi_getprop(DDI_DEV_T_ANY, intr_parent_dip, 0,
"#interrupts-cells", 1);
/*
* step4b
* See if we have a match on the interrupt unit specifier
*/
if (cells_1275_cmp(match_req, scan, addr_cells + intr_cells)
== 0) {
uint32_t *intr;
match_found = 1;
/*
* If we have an imap parent whose not in our device
* tree path, we need to hold and install that driver.
*/
if (i_ddi_attach_node_hierarchy(intr_parent_dip)
!= DDI_SUCCESS) {
ndi_rele_devi(intr_parent_dip);
intr_parent_dip = (dev_info_t *)NULL;
goto exit4;
}
/*
* We need to handcraft an ispec along with a bus
* interrupt value, so we can dup it into our
* standard ispec structure.
*/
/* Extract the translated interrupt information */
intr = kmem_alloc(
CELLS_1275_TO_BYTES(new_intr_cells), KM_SLEEP);
for (j = 0; j < new_intr_cells; j++, i++)
intr[j] = scan[i];
cells_1275_copy(intr, &hdlp->ih_vector, new_intr_cells);
kmem_free(intr, CELLS_1275_TO_BYTES(new_intr_cells));
#ifdef DEBUG
if (debug)
prom_printf("dip 0x%p\n",
(void *)intr_parent_dip);
#endif
break;
} else {
#ifdef DEBUG
if (debug)
prom_printf("dip 0x%p\n",
(void *)intr_parent_dip);
#endif
ndi_rele_devi(intr_parent_dip);
intr_parent_dip = NULL;
i += new_intr_cells;
}
}
/*
* If we haven't found our interrupt parent at this point, fallback
* to using the device tree.
*/
if (!match_found) {
ndi_hold_devi(pdip);
ASSERT(intr_parent_dip == NULL);
intr_parent_dip = pdip;
}
ASSERT(intr_parent_dip != NULL);
exit4:
kmem_free(reg_p, reg_len);
kmem_free(match_req, CELLS_1275_TO_BYTES(addr_cells) +
CELLS_1275_TO_BYTES(intr_cells));
exit3:
kmem_free(imap_mask, imap_mask_sz);
exit2:
kmem_free(imap, imap_sz);
return (intr_parent_dip);
}
/*
* process_intr_ops:
*
* Process the interrupt op via the interrupt parent.
*/
int
process_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t op,
ddi_intr_handle_impl_t *hdlp, void *result)
{
int ret = DDI_FAILURE;
if (NEXUS_HAS_INTR_OP(pdip)) {
ret = (*(DEVI(pdip)->devi_ops->devo_bus_ops->
bus_intr_op)) (pdip, rdip, op, hdlp, result);
} else {
cmn_err(CE_WARN, "Failed to process interrupt "
"for %s%d due to down-rev nexus driver %s%d",
ddi_get_name(rdip), ddi_get_instance(rdip),
ddi_get_name(pdip), ddi_get_instance(pdip));
}
return (ret);
}
/*ARGSUSED*/
uint_t
softlevel1(caddr_t arg)
{
softint();
return (1);
}
/*
* indirection table, to save us some large switch statements
* NOTE: This must agree with "INTLEVEL_foo" constants in
* <sys/avintr.h>
*/
struct autovec *const vectorlist[] = { 0 };
/*
* This value is exported here for the functions in avintr.c
*/
const uint_t maxautovec = (sizeof (vectorlist) / sizeof (vectorlist[0]));
/*
* Check for machine specific interrupt levels which cannot be reassigned by
* settrap(), sun4u version.
*
* sun4u does not support V8 SPARC "fast trap" handlers.
*/
/*ARGSUSED*/
int
exclude_settrap(int lvl)
{
return (1);
}
/*
* Check for machine specific interrupt levels which cannot have interrupt
* handlers added. We allow levels 1 through 15; level 0 is nonsense.
*/
/*ARGSUSED*/
int
exclude_level(int lvl)
{
return ((lvl < 1) || (lvl > 15));
}
/*
* Wrapper functions used by New DDI interrupt framework.
*/
/*
* i_ddi_intr_ops:
*/
int
i_ddi_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op,
ddi_intr_handle_impl_t *hdlp, void *result)
{
dev_info_t *pdip = ddi_get_parent(dip);
int ret = DDI_FAILURE;
/*
* The following check is required to address
* one of the test case of ADDI test suite.
*/
if (pdip == NULL)
return (DDI_FAILURE);
if (hdlp->ih_type != DDI_INTR_TYPE_FIXED)
return (process_intr_ops(pdip, rdip, op, hdlp, result));
if (hdlp->ih_vector == 0)
hdlp->ih_vector = i_ddi_get_inum(rdip, hdlp->ih_inum);
if (hdlp->ih_pri == 0)
hdlp->ih_pri = i_ddi_get_intr_pri(rdip, hdlp->ih_inum);
switch (op) {
case DDI_INTROP_ADDISR:
case DDI_INTROP_REMISR:
case DDI_INTROP_GETTARGET:
case DDI_INTROP_SETTARGET:
case DDI_INTROP_ENABLE:
case DDI_INTROP_DISABLE:
case DDI_INTROP_BLOCKENABLE:
case DDI_INTROP_BLOCKDISABLE:
/*
* Try and determine our parent and possibly an interrupt
* translation. intr parent dip returned held
*/
if ((pdip = get_intr_parent(pdip, dip, hdlp)) == NULL)
goto done;
}
ret = process_intr_ops(pdip, rdip, op, hdlp, result);
done:
switch (op) {
case DDI_INTROP_ADDISR:
case DDI_INTROP_REMISR:
case DDI_INTROP_ENABLE:
case DDI_INTROP_DISABLE:
case DDI_INTROP_BLOCKENABLE:
case DDI_INTROP_BLOCKDISABLE:
/* Release hold acquired in get_intr_parent() */
if (pdip)
ndi_rele_devi(pdip);
}
hdlp->ih_vector = 0;
return (ret);
}
/*
* i_ddi_add_ivintr:
*/
/*ARGSUSED*/
int
i_ddi_add_ivintr(ddi_intr_handle_impl_t *hdlp)
{
/*
* If the PIL was set and is valid use it, otherwise
* default it to 1
*/
if ((hdlp->ih_pri < 1) || (hdlp->ih_pri > PIL_MAX))
hdlp->ih_pri = 1;
VERIFY(add_ivintr(hdlp->ih_vector, hdlp->ih_pri,
(intrfunc)hdlp->ih_cb_func, hdlp->ih_cb_arg1,
hdlp->ih_cb_arg2, NULL) == 0);
return (DDI_SUCCESS);
}
/*
* i_ddi_rem_ivintr:
*/
/*ARGSUSED*/
void
i_ddi_rem_ivintr(ddi_intr_handle_impl_t *hdlp)
{
VERIFY(rem_ivintr(hdlp->ih_vector, hdlp->ih_pri) == 0);
}
/*
* i_ddi_get_inum - Get the interrupt number property from the
* specified device. Note that this function is called only for
* the FIXED interrupt type.
*/
uint32_t
i_ddi_get_inum(dev_info_t *dip, uint_t inumber)
{
int32_t intrlen, intr_cells, max_intrs;
prop_1275_cell_t *ip, intr_sz;
uint32_t intr = 0;
if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS |
DDI_PROP_CANSLEEP,
"interrupts", (caddr_t)&ip, &intrlen) == DDI_SUCCESS) {
intr_cells = ddi_getprop(DDI_DEV_T_ANY, dip, 0,
"#interrupt-cells", 1);
/* adjust for number of bytes */
intr_sz = CELLS_1275_TO_BYTES(intr_cells);
/* Calculate the number of interrupts */
max_intrs = intrlen / intr_sz;
if (inumber < max_intrs) {
prop_1275_cell_t *intrp = ip;
/* Index into interrupt property */
intrp += (inumber * intr_cells);
cells_1275_copy(intrp, &intr, intr_cells);
}
kmem_free(ip, intrlen);
}
return (intr);
}
/*
* i_ddi_get_intr_pri - Get the interrupt-priorities property from
* the specified device. Note that this function is called only for
* the FIXED interrupt type.
*/
uint32_t
i_ddi_get_intr_pri(dev_info_t *dip, uint_t inumber)
{
uint32_t *intr_prio_p;
uint32_t pri = 0;
int32_t i;
/*
* Use the "interrupt-priorities" property to determine the
* the pil/ipl for the interrupt handler.
*/
if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
"interrupt-priorities", (caddr_t)&intr_prio_p,
&i) == DDI_SUCCESS) {
if (inumber < (i / sizeof (int32_t)))
pri = intr_prio_p[inumber];
kmem_free(intr_prio_p, i);
}
return (pri);
}
int
i_ddi_get_intx_nintrs(dev_info_t *dip)
{
int32_t intrlen;
prop_1275_cell_t intr_sz;
prop_1275_cell_t *ip;
int32_t ret = 0;
if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS |
DDI_PROP_CANSLEEP,
"interrupts", (caddr_t)&ip, &intrlen) == DDI_SUCCESS) {
intr_sz = ddi_getprop(DDI_DEV_T_ANY, dip, 0,
"#interrupt-cells", 1);
/* adjust for number of bytes */
intr_sz = CELLS_1275_TO_BYTES(intr_sz);
ret = intrlen / intr_sz;
kmem_free(ip, intrlen);
}
return (ret);
}
/*
* i_ddi_add_softint - allocate and add a software interrupt.
*
* NOTE: All software interrupts that are registered through DDI
* should be triggered only on a single target or CPU.
*/
int
i_ddi_add_softint(ddi_softint_hdl_impl_t *hdlp)
{
if ((hdlp->ih_private = (void *)add_softintr(hdlp->ih_pri,
hdlp->ih_cb_func, hdlp->ih_cb_arg1, SOFTINT_ST)) == NULL)
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
/*
* i_ddi_remove_softint - remove and free a software interrupt.
*/
void
i_ddi_remove_softint(ddi_softint_hdl_impl_t *hdlp)
{
ASSERT(hdlp->ih_private != NULL);
if (rem_softintr((uint64_t)hdlp->ih_private) == 0)
hdlp->ih_private = NULL;
}
/*
* i_ddi_trigger_softint - trigger a software interrupt.
*/
int
i_ddi_trigger_softint(ddi_softint_hdl_impl_t *hdlp, void *arg2)
{
int ret;
ASSERT(hdlp->ih_private != NULL);
/* Update the second argument for the software interrupt */
if ((ret = update_softint_arg2((uint64_t)hdlp->ih_private, arg2)) == 0)
setsoftint((uint64_t)hdlp->ih_private);
return (ret ? DDI_EPENDING : DDI_SUCCESS);
}
/*
* i_ddi_set_softint_pri - change software interrupt priority.
*/
/* ARGSUSED */
int
i_ddi_set_softint_pri(ddi_softint_hdl_impl_t *hdlp, uint_t old_pri)
{
int ret;
ASSERT(hdlp->ih_private != NULL);
/* Update the interrupt priority for the software interrupt */
ret = update_softint_pri((uint64_t)hdlp->ih_private, hdlp->ih_pri);
return (ret ? DDI_FAILURE : DDI_SUCCESS);
}
/*ARGSUSED*/
void
i_ddi_alloc_intr_phdl(ddi_intr_handle_impl_t *hdlp)
{
}
/*ARGSUSED*/
void
i_ddi_free_intr_phdl(ddi_intr_handle_impl_t *hdlp)
{
}
/*
* SECTION: DDI Memory/DMA
*/
/* set HAT endianess attributes from ddi_device_acc_attr */
void
i_ddi_devacc_to_hatacc(ddi_device_acc_attr_t *devaccp, uint_t *hataccp)
{
if (devaccp != NULL) {
if (devaccp->devacc_attr_endian_flags == DDI_STRUCTURE_LE_ACC) {
*hataccp &= ~HAT_ENDIAN_MASK;
*hataccp |= HAT_STRUCTURE_LE;
}
}
}
/*
* Check if the specified cache attribute is supported on the platform.
* This function must be called before i_ddi_cacheattr_to_hatacc().
*/
boolean_t
i_ddi_check_cache_attr(uint_t flags)
{
/*
* The cache attributes are mutually exclusive. Any combination of
* the attributes leads to a failure.
*/
uint_t cache_attr = IOMEM_CACHE_ATTR(flags);
if ((cache_attr != 0) && !ISP2(cache_attr))
return (B_FALSE);
/*
* On the sparc architecture, only IOMEM_DATA_CACHED is meaningful,
* but others lead to a failure.
*/
if (cache_attr & IOMEM_DATA_CACHED)
return (B_TRUE);
else
return (B_FALSE);
}
/* set HAT cache attributes from the cache attributes */
void
i_ddi_cacheattr_to_hatacc(uint_t flags, uint_t *hataccp)
{
uint_t cache_attr = IOMEM_CACHE_ATTR(flags);
static char *fname = "i_ddi_cacheattr_to_hatacc";
#if defined(lint)
*hataccp = *hataccp;
#endif
/*
* set HAT attrs according to the cache attrs.
*/
switch (cache_attr) {
/*
* The cache coherency is always maintained on SPARC, and
* nothing is required.
*/
case IOMEM_DATA_CACHED:
break;
/*
* Both IOMEM_DATA_UC_WRITE_COMBINED and IOMEM_DATA_UNCACHED are
* not supported on SPARC -- this case must not occur because the
* cache attribute is scrutinized before this function is called.
*/
case IOMEM_DATA_UNCACHED:
case IOMEM_DATA_UC_WR_COMBINE:
default:
cmn_err(CE_WARN, "%s: cache_attr=0x%x is ignored.",
fname, cache_attr);
}
}
static vmem_t *little_endian_arena;
static vmem_t *big_endian_arena;
static void *
segkmem_alloc_le(vmem_t *vmp, size_t size, int flag)
{
return (segkmem_xalloc(vmp, NULL, size, flag, HAT_STRUCTURE_LE,
segkmem_page_create, NULL));
}
static void *
segkmem_alloc_be(vmem_t *vmp, size_t size, int flag)
{
return (segkmem_xalloc(vmp, NULL, size, flag, HAT_STRUCTURE_BE,
segkmem_page_create, NULL));
}
void
ka_init(void)
{
little_endian_arena = vmem_create("little_endian", NULL, 0, 1,
segkmem_alloc_le, segkmem_free, heap_arena, 0, VM_SLEEP);
big_endian_arena = vmem_create("big_endian", NULL, 0, 1,
segkmem_alloc_be, segkmem_free, heap_arena, 0, VM_SLEEP);
}
/*
* Allocate from the system, aligned on a specific boundary.
* The alignment, if non-zero, must be a power of 2.
*/
static void *
kalloca(size_t size, size_t align, int cansleep, uint_t endian_flags)
{
size_t *addr, *raddr, rsize;
size_t hdrsize = 4 * sizeof (size_t); /* must be power of 2 */
align = MAX(align, hdrsize);
ASSERT((align & (align - 1)) == 0);
/*
* We need to allocate
* rsize = size + hdrsize + align - MIN(hdrsize, buffer_alignment)
* bytes to be sure we have enough freedom to satisfy the request.
* Since the buffer alignment depends on the request size, this is
* not straightforward to use directly.
*
* kmem guarantees that any allocation of a 64-byte multiple will be
* 64-byte aligned. Since rounding up the request could add more
* than we save, we compute the size with and without alignment, and
* use the smaller of the two.
*/
rsize = size + hdrsize + align;
if (endian_flags == DDI_STRUCTURE_LE_ACC) {
raddr = vmem_alloc(little_endian_arena, rsize,
cansleep ? VM_SLEEP : VM_NOSLEEP);
} else {
raddr = vmem_alloc(big_endian_arena, rsize,
cansleep ? VM_SLEEP : VM_NOSLEEP);
}
if (raddr == NULL)
return (NULL);
addr = (size_t *)P2ROUNDUP((uintptr_t)raddr + hdrsize, align);
ASSERT((uintptr_t)addr + size - (uintptr_t)raddr <= rsize);
addr[-3] = (size_t)endian_flags;
addr[-2] = (size_t)raddr;
addr[-1] = rsize;
return (addr);
}
static void
kfreea(void *addr)
{
size_t *saddr = addr;
if (saddr[-3] == DDI_STRUCTURE_LE_ACC)
vmem_free(little_endian_arena, (void *)saddr[-2], saddr[-1]);
else
vmem_free(big_endian_arena, (void *)saddr[-2], saddr[-1]);
}
/*
* This used to be ddi_iomin, but we were the only remaining caller, so
* we've made it private and moved it here.
*/
static int
i_ddi_iomin(dev_info_t *a, int i, int stream)
{
int r;
/*
* Make sure that the initial value is sane
*/
if (!ISP2(i))
return (0);
if (i == 0)
i = (stream) ? 4 : 1;
r = ddi_ctlops(a, a,
DDI_CTLOPS_IOMIN, (void *)(uintptr_t)stream, (void *)&i);
if (r != DDI_SUCCESS || !ISP2(i))
return (0);
return (i);
}
int
i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attr,
size_t length, int cansleep, int flags,
ddi_device_acc_attr_t *accattrp,
caddr_t *kaddrp, size_t *real_length, ddi_acc_hdl_t *handlep)
{
caddr_t a;
int iomin, align, streaming;
uint_t endian_flags = DDI_NEVERSWAP_ACC;
#if defined(lint)
*handlep = *handlep;
#endif
/*
* Check legality of arguments
*/
if (length == 0 || kaddrp == NULL || attr == NULL) {
return (DDI_FAILURE);
}
if (attr->dma_attr_minxfer == 0 || attr->dma_attr_align == 0 ||
!ISP2(attr->dma_attr_align) || !ISP2(attr->dma_attr_minxfer)) {
return (DDI_FAILURE);
}
/*
* check if a streaming sequential xfer is requested.
*/
streaming = (flags & DDI_DMA_STREAMING) ? 1 : 0;
/*
* Drivers for 64-bit capable SBus devices will encode
* the burtsizes for 64-bit xfers in the upper 16-bits.
* For DMA alignment, we use the most restrictive
* alignment of 32-bit and 64-bit xfers.
*/
iomin = (attr->dma_attr_burstsizes & 0xffff) |
((attr->dma_attr_burstsizes >> 16) & 0xffff);
/*
* If a driver set burtsizes to 0, we give it byte alignment.
* Otherwise align at the burtsizes boundary.
*/
if (iomin == 0)
iomin = 1;
else
iomin = 1 << (ddi_fls(iomin) - 1);
iomin = maxbit(iomin, attr->dma_attr_minxfer);
iomin = maxbit(iomin, attr->dma_attr_align);
iomin = i_ddi_iomin(dip, iomin, streaming);
if (iomin == 0)
return (DDI_FAILURE);
ASSERT((iomin & (iomin - 1)) == 0);
ASSERT(iomin >= attr->dma_attr_minxfer);
ASSERT(iomin >= attr->dma_attr_align);
length = P2ROUNDUP(length, iomin);
align = iomin;
if (accattrp != NULL)
endian_flags = accattrp->devacc_attr_endian_flags;
a = kalloca(length, align, cansleep, endian_flags);
if ((*kaddrp = a) == 0) {
return (DDI_FAILURE);
} else {
if (real_length) {
*real_length = length;
}
if (handlep) {
/*
* assign handle information
*/
impl_acc_hdl_init(handlep);
}
return (DDI_SUCCESS);
}
}
/* ARGSUSED */
void
i_ddi_mem_free(caddr_t kaddr, ddi_acc_hdl_t *ap)
{
kfreea(kaddr);
}
/*
* SECTION: DDI Data Access
*/
static uintptr_t impl_acc_hdl_id = 0;
/*
* access handle allocator
*/
ddi_acc_hdl_t *
impl_acc_hdl_get(ddi_acc_handle_t hdl)
{
/*
* Extract the access handle address from the DDI implemented
* access handle
*/
return (&((ddi_acc_impl_t *)hdl)->ahi_common);
}
ddi_acc_handle_t
impl_acc_hdl_alloc(int (*waitfp)(caddr_t), caddr_t arg)
{
ddi_acc_impl_t *hp;
on_trap_data_t *otp;
int sleepflag;
sleepflag = ((waitfp == (int (*)())KM_SLEEP) ? KM_SLEEP : KM_NOSLEEP);
/*
* Allocate and initialize the data access handle and error status.
*/
if ((hp = kmem_zalloc(sizeof (ddi_acc_impl_t), sleepflag)) == NULL)
goto fail;
if ((hp->ahi_err = (ndi_err_t *)kmem_zalloc(
sizeof (ndi_err_t), sleepflag)) == NULL) {
kmem_free(hp, sizeof (ddi_acc_impl_t));
goto fail;
}
if ((otp = (on_trap_data_t *)kmem_zalloc(
sizeof (on_trap_data_t), sleepflag)) == NULL) {
kmem_free(hp->ahi_err, sizeof (ndi_err_t));
kmem_free(hp, sizeof (ddi_acc_impl_t));
goto fail;
}
hp->ahi_err->err_ontrap = otp;
hp->ahi_common.ah_platform_private = (void *)hp;
return ((ddi_acc_handle_t)hp);
fail:
if ((waitfp != (int (*)())KM_SLEEP) &&
(waitfp != (int (*)())KM_NOSLEEP))
ddi_set_callback(waitfp, arg, &impl_acc_hdl_id);
return (NULL);
}
void
impl_acc_hdl_free(ddi_acc_handle_t handle)
{
ddi_acc_impl_t *hp;
/*
* The supplied (ddi_acc_handle_t) is actually a (ddi_acc_impl_t *),
* because that's what we allocated in impl_acc_hdl_alloc() above.
*/
hp = (ddi_acc_impl_t *)handle;
if (hp) {
kmem_free(hp->ahi_err->err_ontrap, sizeof (on_trap_data_t));
kmem_free(hp->ahi_err, sizeof (ndi_err_t));
kmem_free(hp, sizeof (ddi_acc_impl_t));
if (impl_acc_hdl_id)
ddi_run_callback(&impl_acc_hdl_id);
}
}
#define PCI_GET_MP_PFN(mp, page_no) ((mp)->dmai_ndvmapages == 1 ? \
(pfn_t)(mp)->dmai_iopte:(((pfn_t *)(mp)->dmai_iopte)[page_no]))
/*
* Function called after a dma fault occurred to find out whether the
* fault address is associated with a driver that is able to handle faults
* and recover from faults.
*/
/* ARGSUSED */
int
impl_dma_check(dev_info_t *dip, const void *handle, const void *addr,
const void *not_used)
{
ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
pfn_t fault_pfn = mmu_btop(*(uint64_t *)addr);
pfn_t comp_pfn;
/*
* The driver has to set DDI_DMA_FLAGERR to recover from dma faults.
*/
int page;
ASSERT(mp);
for (page = 0; page < mp->dmai_ndvmapages; page++) {
comp_pfn = PCI_GET_MP_PFN(mp, page);
if (fault_pfn == comp_pfn)
return (DDI_FM_NONFATAL);
}
return (DDI_FM_UNKNOWN);
}
/*
* Function used to check if a given access handle owns the failing address.
* Called by ndi_fmc_error, when we detect a PIO error.
*/
/* ARGSUSED */
static int
impl_acc_check(dev_info_t *dip, const void *handle, const void *addr,
const void *not_used)
{
pfn_t pfn, fault_pfn;
ddi_acc_hdl_t *hp;
hp = impl_acc_hdl_get((ddi_acc_handle_t)handle);
ASSERT(hp);
if (addr != NULL) {
pfn = hp->ah_pfn;
fault_pfn = mmu_btop(*(uint64_t *)addr);
if (fault_pfn >= pfn && fault_pfn < (pfn + hp->ah_pnum))
return (DDI_FM_NONFATAL);
}
return (DDI_FM_UNKNOWN);
}
void
impl_acc_err_init(ddi_acc_hdl_t *handlep)
{
int fmcap;
ndi_err_t *errp;
on_trap_data_t *otp;
ddi_acc_impl_t *hp = (ddi_acc_impl_t *)handlep;
fmcap = ddi_fm_capable(handlep->ah_dip);
if (handlep->ah_acc.devacc_attr_version < DDI_DEVICE_ATTR_V1 ||
!DDI_FM_ACC_ERR_CAP(fmcap)) {
handlep->ah_acc.devacc_attr_access = DDI_DEFAULT_ACC;
} else if (DDI_FM_ACC_ERR_CAP(fmcap)) {
if (handlep->ah_acc.devacc_attr_access == DDI_DEFAULT_ACC) {
if (handlep->ah_xfermodes)
return;
i_ddi_drv_ereport_post(handlep->ah_dip, DVR_EFMCAP,
NULL, DDI_NOSLEEP);
} else {
errp = hp->ahi_err;
otp = (on_trap_data_t *)errp->err_ontrap;
otp->ot_handle = (void *)(hp);
otp->ot_prot = OT_DATA_ACCESS;
if (handlep->ah_acc.devacc_attr_access ==
DDI_CAUTIOUS_ACC)
otp->ot_trampoline =
(uintptr_t)&i_ddi_caut_trampoline;
else
otp->ot_trampoline =
(uintptr_t)&i_ddi_prot_trampoline;
errp->err_status = DDI_FM_OK;
errp->err_expected = DDI_FM_ERR_UNEXPECTED;
errp->err_cf = impl_acc_check;
}
}
}
void
impl_acc_hdl_init(ddi_acc_hdl_t *handlep)
{
ddi_acc_impl_t *hp;
ASSERT(handlep);
hp = (ddi_acc_impl_t *)handlep;
/*
* check for SW byte-swapping
*/
hp->ahi_get8 = i_ddi_get8;
hp->ahi_put8 = i_ddi_put8;
hp->ahi_rep_get8 = i_ddi_rep_get8;
hp->ahi_rep_put8 = i_ddi_rep_put8;
if (handlep->ah_acc.devacc_attr_endian_flags & DDI_STRUCTURE_LE_ACC) {
hp->ahi_get16 = i_ddi_swap_get16;
hp->ahi_get32 = i_ddi_swap_get32;
hp->ahi_get64 = i_ddi_swap_get64;
hp->ahi_put16 = i_ddi_swap_put16;
hp->ahi_put32 = i_ddi_swap_put32;
hp->ahi_put64 = i_ddi_swap_put64;
hp->ahi_rep_get16 = i_ddi_swap_rep_get16;
hp->ahi_rep_get32 = i_ddi_swap_rep_get32;
hp->ahi_rep_get64 = i_ddi_swap_rep_get64;
hp->ahi_rep_put16 = i_ddi_swap_rep_put16;
hp->ahi_rep_put32 = i_ddi_swap_rep_put32;
hp->ahi_rep_put64 = i_ddi_swap_rep_put64;
} else {
hp->ahi_get16 = i_ddi_get16;
hp->ahi_get32 = i_ddi_get32;
hp->ahi_get64 = i_ddi_get64;
hp->ahi_put16 = i_ddi_put16;
hp->ahi_put32 = i_ddi_put32;
hp->ahi_put64 = i_ddi_put64;
hp->ahi_rep_get16 = i_ddi_rep_get16;
hp->ahi_rep_get32 = i_ddi_rep_get32;
hp->ahi_rep_get64 = i_ddi_rep_get64;
hp->ahi_rep_put16 = i_ddi_rep_put16;
hp->ahi_rep_put32 = i_ddi_rep_put32;
hp->ahi_rep_put64 = i_ddi_rep_put64;
}
/* Legacy fault flags and support */
hp->ahi_fault_check = i_ddi_acc_fault_check;
hp->ahi_fault_notify = i_ddi_acc_fault_notify;
hp->ahi_fault = 0;
impl_acc_err_init(handlep);
}
void
i_ddi_acc_set_fault(ddi_acc_handle_t handle)
{
ddi_acc_impl_t *hp = (ddi_acc_impl_t *)handle;
if (!hp->ahi_fault) {
hp->ahi_fault = 1;
(*hp->ahi_fault_notify)(hp);
}
}
void
i_ddi_acc_clr_fault(ddi_acc_handle_t handle)
{
ddi_acc_impl_t *hp = (ddi_acc_impl_t *)handle;
if (hp->ahi_fault) {
hp->ahi_fault = 0;
(*hp->ahi_fault_notify)(hp);
}
}
/* ARGSUSED */
void
i_ddi_acc_fault_notify(ddi_acc_impl_t *hp)
{
/* Default version, does nothing */
}
/*
* SECTION: Misc functions
*/
/*
* instance wrappers
*/
/*ARGSUSED*/
uint_t
impl_assign_instance(dev_info_t *dip)
{
return ((uint_t)-1);
}
/*ARGSUSED*/
int
impl_keep_instance(dev_info_t *dip)
{
return (DDI_FAILURE);
}
/*ARGSUSED*/
int
impl_free_instance(dev_info_t *dip)
{
return (DDI_FAILURE);
}
/*ARGSUSED*/
int
impl_check_cpu(dev_info_t *devi)
{
return (DDI_SUCCESS);
}
static const char *nocopydevs[] = {
"SUNW,ffb",
"SUNW,afb",
NULL
};
/*
* Perform a copy from a memory mapped device (whose devinfo pointer is devi)
* separately mapped at devaddr in the kernel to a kernel buffer at kaddr.
*/
/*ARGSUSED*/
int
e_ddi_copyfromdev(dev_info_t *devi,
off_t off, const void *devaddr, void *kaddr, size_t len)
{
const char **argv;
for (argv = nocopydevs; *argv; argv++)
if (strcmp(ddi_binding_name(devi), *argv) == 0) {
bzero(kaddr, len);
return (0);
}
bcopy(devaddr, kaddr, len);
return (0);
}
/*
* Perform a copy to a memory mapped device (whose devinfo pointer is devi)
* separately mapped at devaddr in the kernel from a kernel buffer at kaddr.
*/
/*ARGSUSED*/
int
e_ddi_copytodev(dev_info_t *devi,
off_t off, const void *kaddr, void *devaddr, size_t len)
{
const char **argv;
for (argv = nocopydevs; *argv; argv++)
if (strcmp(ddi_binding_name(devi), *argv) == 0)
return (1);
bcopy(kaddr, devaddr, len);
return (0);
}
/*
* Boot Configuration
*/
idprom_t idprom;
/*
* Configure the hardware on the system.
* Called before the rootfs is mounted
*/
void
configure(void)
{
extern void i_ddi_init_root();
/* We better have released boot by this time! */
ASSERT(!bootops);
/*
* Determine whether or not to use the fpu, V9 SPARC cpus
* always have one. Could check for existence of a fp queue,
* Ultra I, II and IIa do not have a fp queue.
*/
if (fpu_exists)
fpu_probe();
else
cmn_err(CE_CONT, "FPU not in use\n");
#if 0 /* XXXQ - not necessary for sun4u */
/*
* This following line fixes bugid 1041296; we need to do a
* prom_nextnode(0) because this call ALSO patches the DMA+
* bug in Campus-B and Phoenix. The prom uncaches the traptable
* page as a side-effect of devr_next(0) (which prom_nextnode calls),
* so this *must* be executed early on. (XXX This is untrue for sun4u)
*/
(void) prom_nextnode((pnode_t)0);
#endif
/*
* Initialize devices on the machine.
* Uses configuration tree built by the PROMs to determine what
* is present, and builds a tree of prototype dev_info nodes
* corresponding to the hardware which identified itself.
*/
i_ddi_init_root();
#ifdef DDI_PROP_DEBUG
(void) ddi_prop_debug(1); /* Enable property debugging */
#endif /* DDI_PROP_DEBUG */
}
/*
* The "status" property indicates the operational status of a device.
* If this property is present, the value is a string indicating the
* status of the device as follows:
*
* "okay" operational.
* "disabled" not operational, but might become operational.
* "fail" not operational because a fault has been detected,
* and it is unlikely that the device will become
* operational without repair. no additional details
* are available.
* "fail-xxx" not operational because a fault has been detected,
* and it is unlikely that the device will become
* operational without repair. "xxx" is additional
* human-readable information about the particular
* fault condition that was detected.
*
* The absence of this property means that the operational status is
* unknown or okay.
*
* This routine checks the status property of the specified device node
* and returns 0 if the operational status indicates failure, and 1 otherwise.
*
* The property may exist on plug-in cards the existed before IEEE 1275-1994.
* And, in that case, the property may not even be a string. So we carefully
* check for the value "fail", in the beginning of the string, noting
* the property length.
*/
int
status_okay(int id, char *buf, int buflen)
{
char status_buf[OBP_MAXPROPNAME];
char *bufp = buf;
int len = buflen;
int proplen;
static const char *status = "status";
static const char *fail = "fail";
size_t fail_len = strlen(fail);
/*
* Get the proplen ... if it's smaller than "fail",
* or doesn't exist ... then we don't care, since
* the value can't begin with the char string "fail".
*
* NB: proplen, if it's a string, includes the NULL in the
* the size of the property, and fail_len does not.
*/
proplen = prom_getproplen((pnode_t)id, (caddr_t)status);
if (proplen <= fail_len) /* nonexistent or uninteresting len */
return (1);
/*
* if a buffer was provided, use it
*/
if ((buf == (char *)NULL) || (buflen <= 0)) {
bufp = status_buf;
len = sizeof (status_buf);
}
*bufp = (char)0;
/*
* Get the property into the buffer, to the extent of the buffer,
* and in case the buffer is smaller than the property size,
* NULL terminate the buffer. (This handles the case where
* a buffer was passed in and the caller wants to print the
* value, but the buffer was too small).
*/
(void) prom_bounded_getprop((pnode_t)id, (caddr_t)status,
(caddr_t)bufp, len);
*(bufp + len - 1) = (char)0;
/*
* If the value begins with the char string "fail",
* then it means the node is failed. We don't care
* about any other values. We assume the node is ok
* although it might be 'disabled'.
*/
if (strncmp(bufp, fail, fail_len) == 0)
return (0);
return (1);
}
/*
* We set the cpu type from the idprom, if we can.
* Note that we just read out the contents of it, for the most part.
*/
void
setcputype(void)
{
/*
* We cache the idprom info early on so that we don't
* rummage through the NVRAM unnecessarily later.
*/
(void) prom_getidprom((caddr_t)&idprom, sizeof (idprom));
}
/*
* Here is where we actually infer meanings to the members of idprom_t
*/
void
parse_idprom(void)
{
if (idprom.id_format == IDFORM_1) {
(void) localetheraddr((struct ether_addr *)idprom.id_ether,
(struct ether_addr *)NULL);
(void) snprintf(hw_serial, HW_HOSTID_LEN, "%u",
(idprom.id_machine << 24) + idprom.id_serial);
} else
prom_printf("Invalid format code in IDprom.\n");
}
/*
* Allow for implementation specific correction of PROM property values.
*/
/*ARGSUSED*/
void
impl_fix_props(dev_info_t *dip, dev_info_t *ch_dip, char *name, int len,
caddr_t buffer)
{
/*
* There are no adjustments needed in this implementation.
*/
}
/*
* The following functions ready a cautious request to go up to the nexus
* driver. It is up to the nexus driver to decide how to process the request.
* It may choose to call i_ddi_do_caut_get/put in this file, or do it
* differently.
*/
static void
i_ddi_caut_getput_ctlops(
ddi_acc_impl_t *hp, uint64_t host_addr, uint64_t dev_addr, size_t size,
size_t repcount, uint_t flags, ddi_ctl_enum_t cmd)
{
peekpoke_ctlops_t cautacc_ctlops_arg;
cautacc_ctlops_arg.size = size;
cautacc_ctlops_arg.dev_addr = dev_addr;
cautacc_ctlops_arg.host_addr = host_addr;
cautacc_ctlops_arg.handle = (ddi_acc_handle_t)hp;
cautacc_ctlops_arg.repcount = repcount;
cautacc_ctlops_arg.flags = flags;
(void) ddi_ctlops(hp->ahi_common.ah_dip, hp->ahi_common.ah_dip, cmd,
&cautacc_ctlops_arg, NULL);
}
uint8_t
i_ddi_caut_get8(ddi_acc_impl_t *hp, uint8_t *addr)
{
uint8_t value;
i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr,
sizeof (uint8_t), 1, 0, DDI_CTLOPS_PEEK);
return (value);
}
uint16_t
i_ddi_caut_get16(ddi_acc_impl_t *hp, uint16_t *addr)
{
uint16_t value;
i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr,
sizeof (uint16_t), 1, 0, DDI_CTLOPS_PEEK);
return (value);
}
uint32_t
i_ddi_caut_get32(ddi_acc_impl_t *hp, uint32_t *addr)
{
uint32_t value;
i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr,
sizeof (uint32_t), 1, 0, DDI_CTLOPS_PEEK);
return (value);
}
uint64_t
i_ddi_caut_get64(ddi_acc_impl_t *hp, uint64_t *addr)
{
uint64_t value;
i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr,
sizeof (uint64_t), 1, 0, DDI_CTLOPS_PEEK);
return (value);
}
void
i_ddi_caut_put8(ddi_acc_impl_t *hp, uint8_t *addr, uint8_t value)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr,
sizeof (uint8_t), 1, 0, DDI_CTLOPS_POKE);
}
void
i_ddi_caut_put16(ddi_acc_impl_t *hp, uint16_t *addr, uint16_t value)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr,
sizeof (uint16_t), 1, 0, DDI_CTLOPS_POKE);
}
void
i_ddi_caut_put32(ddi_acc_impl_t *hp, uint32_t *addr, uint32_t value)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr,
sizeof (uint32_t), 1, 0, DDI_CTLOPS_POKE);
}
void
i_ddi_caut_put64(ddi_acc_impl_t *hp, uint64_t *addr, uint64_t value)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr,
sizeof (uint64_t), 1, 0, DDI_CTLOPS_POKE);
}
void
i_ddi_caut_rep_get8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr,
size_t repcount, uint_t flags)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr,
sizeof (uint8_t), repcount, flags, DDI_CTLOPS_PEEK);
}
void
i_ddi_caut_rep_get16(ddi_acc_impl_t *hp, uint16_t *host_addr,
uint16_t *dev_addr, size_t repcount, uint_t flags)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr,
sizeof (uint16_t), repcount, flags, DDI_CTLOPS_PEEK);
}
void
i_ddi_caut_rep_get32(ddi_acc_impl_t *hp, uint32_t *host_addr,
uint32_t *dev_addr, size_t repcount, uint_t flags)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr,
sizeof (uint32_t), repcount, flags, DDI_CTLOPS_PEEK);
}
void
i_ddi_caut_rep_get64(ddi_acc_impl_t *hp, uint64_t *host_addr,
uint64_t *dev_addr, size_t repcount, uint_t flags)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr,
sizeof (uint64_t), repcount, flags, DDI_CTLOPS_PEEK);
}
void
i_ddi_caut_rep_put8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr,
size_t repcount, uint_t flags)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr,
sizeof (uint8_t), repcount, flags, DDI_CTLOPS_POKE);
}
void
i_ddi_caut_rep_put16(ddi_acc_impl_t *hp, uint16_t *host_addr,
uint16_t *dev_addr, size_t repcount, uint_t flags)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr,
sizeof (uint16_t), repcount, flags, DDI_CTLOPS_POKE);
}
void
i_ddi_caut_rep_put32(ddi_acc_impl_t *hp, uint32_t *host_addr,
uint32_t *dev_addr, size_t repcount, uint_t flags)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr,
sizeof (uint32_t), repcount, flags, DDI_CTLOPS_POKE);
}
void
i_ddi_caut_rep_put64(ddi_acc_impl_t *hp, uint64_t *host_addr,
uint64_t *dev_addr, size_t repcount, uint_t flags)
{
i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr,
sizeof (uint64_t), repcount, flags, DDI_CTLOPS_POKE);
}
/*
* This is called only to process peek/poke when the DIP is NULL.
* Assume that this is for memory, as nexi take care of device safe accesses.
*/
int
peekpoke_mem(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args)
{
int err = DDI_SUCCESS;
on_trap_data_t otd;
/* Set up protected environment. */
if (!on_trap(&otd, OT_DATA_ACCESS)) {
uintptr_t tramp = otd.ot_trampoline;
if (cmd == DDI_CTLOPS_POKE) {
otd.ot_trampoline = (uintptr_t)&poke_fault;
err = do_poke(in_args->size, (void *)in_args->dev_addr,
(void *)in_args->host_addr);
} else {
otd.ot_trampoline = (uintptr_t)&peek_fault;
err = do_peek(in_args->size, (void *)in_args->dev_addr,
(void *)in_args->host_addr);
}
otd.ot_trampoline = tramp;
} else
err = DDI_FAILURE;
/* Take down protected environment. */
no_trap();
return (err);
}
|