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
|
/* $OpenBSD: dino.c,v 1.30 2011/01/01 15:20:19 kettenis Exp $ */
/*
* Copyright (c) 2003-2005 Michael Shalayeff
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "cardbus.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/reboot.h>
#include <sys/malloc.h>
#include <sys/extent.h>
#include <machine/iomod.h>
#include <machine/autoconf.h>
#include <hppa/dev/cpudevs.h>
#if NCARDBUS > 0
#include <dev/cardbus/rbus.h>
#endif
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
#include <machine/pdc.h>
#include <dev/cons.h>
#define DINO_MEM_CHUNK 0x800000
#define DINO_MEM_WINDOW (2 * DINO_MEM_CHUNK)
struct dino_regs {
u_int32_t pad0; /* 0x000 */
u_int32_t iar0; /* 0x004 rw intr addr reg 0 */
u_int32_t iodc; /* 0x008 rw iodc data/addr */
u_int32_t irr0; /* 0x00c r intr req reg 0 */
u_int32_t iar1; /* 0x010 rw intr addr reg 1 */
u_int32_t irr1; /* 0x014 r intr req reg 1 */
u_int32_t imr; /* 0x018 rw intr mask reg */
u_int32_t ipr; /* 0x01c rw intr pending reg */
u_int32_t toc_addr; /* 0x020 rw TOC addr reg */
u_int32_t icr; /* 0x024 rw intr control reg */
u_int32_t ilr; /* 0x028 r intr level reg */
u_int32_t pad1; /* 0x02c */
u_int32_t io_command; /* 0x030 w command register */
u_int32_t io_status; /* 0x034 r status register */
u_int32_t io_control; /* 0x038 rw control register */
u_int32_t pad2; /* 0x03c AUX registers follow */
u_int32_t io_gsc_err_addr;/* 0x040 GSC error address */
u_int32_t io_err_info; /* 0x044 error info register */
u_int32_t io_pci_err_addr;/* 0x048 PCI error address */
u_int32_t pad3[4]; /* 0x04c */
u_int32_t io_fbb_en; /* 0x05c fast back2back enable reg */
u_int32_t io_addr_en; /* 0x060 address enable reg */
u_int32_t pci_addr; /* 0x064 PCI conf/io/mem addr reg */
u_int32_t pci_conf_data; /* 0x068 PCI conf data reg */
u_int32_t pci_io_data; /* 0x06c PCI io data reg */
u_int32_t pci_mem_data; /* 0x070 PCI memory data reg */
u_int32_t pad4[0x740/4]; /* 0x074 */
u_int32_t gsc2x_config; /* 0x7b4 GSC2X config reg */
u_int32_t pad5[0x48/4]; /* 0x7b8: BSRS registers follow */
u_int32_t gmask; /* 0x800 GSC arbitration mask */
u_int32_t pamr; /* 0x804 PCI arbitration mask */
u_int32_t papr; /* 0x808 PCI arbitration priority */
u_int32_t damode; /* 0x80c PCI arbitration mode */
u_int32_t pcicmd; /* 0x810 PCI command register */
u_int32_t pcists; /* 0x814 PCI status register */
u_int32_t pad6; /* 0x818 */
u_int32_t mltim; /* 0x81c PCI master latency timer */
u_int32_t brdg_feat; /* 0x820 PCI bridge feature enable */
u_int32_t pciror; /* 0x824 PCI read optimization reg */
u_int32_t pciwor; /* 0x828 PCI write optimization reg */
u_int32_t pad7; /* 0x82c */
u_int32_t tltim; /* 0x830 PCI target latency reg */
};
struct dino_softc {
struct device sc_dv;
int sc_ver;
void *sc_ih;
u_int32_t sc_imr;
bus_space_tag_t sc_bt;
bus_space_handle_t sc_bh;
bus_dma_tag_t sc_dmat;
volatile struct dino_regs *sc_regs;
struct hppa_pci_chipset_tag sc_pc;
struct hppa_bus_space_tag sc_iot;
char sc_ioexname[20];
struct extent *sc_ioex;
struct hppa_bus_space_tag sc_memt;
char sc_memexname[20];
struct extent *sc_memex;
struct hppa_bus_dma_tag sc_dmatag;
u_int32_t io_shadow;
};
int dinomatch(struct device *, void *, void *);
void dinoattach(struct device *, struct device *, void *);
int dino_intr(void *);
struct cfattach dino_ca = {
sizeof(struct dino_softc), dinomatch, dinoattach
};
struct cfdriver dino_cd = {
NULL, "dino", DV_DULL
};
int
dinomatch(parent, cfdata, aux)
struct device *parent;
void *cfdata;
void *aux;
{
struct confargs *ca = aux;
/* struct cfdata *cf = cfdata; */
/* there will be only one */
if (ca->ca_type.iodc_type != HPPA_TYPE_BRIDGE ||
ca->ca_type.iodc_sv_model != HPPA_BRIDGE_DINO)
return (0);
/* do not match on the elroy family */
if (ca->ca_type.iodc_model == 0x78)
return (0);
return (1);
}
void dino_attach_hook(struct device *, struct device *,
struct pcibus_attach_args *);
int dino_maxdevs(void *, int);
pcitag_t dino_make_tag(void *, int, int, int);
void dino_decompose_tag(void *, pcitag_t, int *, int *, int *);
int dino_conf_size(void *, pcitag_t);
pcireg_t dino_conf_read(void *, pcitag_t, int);
void dino_conf_write(void *, pcitag_t, int, pcireg_t);
int dino_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
const char *dino_intr_string(void *, pci_intr_handle_t);
void * dino_intr_establish(void *, pci_intr_handle_t, int, int (*)(void *),
void *, const char *);
void dino_intr_disestablish(void *, void *);
int dino_iomap(void *, bus_addr_t, bus_size_t, int, bus_space_handle_t *);
int dino_memmap(void *, bus_addr_t, bus_size_t, int, bus_space_handle_t *);
int dino_subregion(void *, bus_space_handle_t, bus_size_t, bus_size_t,
bus_space_handle_t *);
int dino_ioalloc(void *, bus_addr_t, bus_addr_t, bus_size_t, bus_size_t,
bus_size_t, int, bus_addr_t *, bus_space_handle_t *);
int dino_memalloc(void *, bus_addr_t, bus_addr_t, bus_size_t, bus_size_t,
bus_size_t, int, bus_addr_t *, bus_space_handle_t *);
void dino_unmap(void *, bus_space_handle_t, bus_size_t);
void dino_free(void *, bus_space_handle_t, bus_size_t);
void dino_barrier(void *, bus_space_handle_t, bus_size_t, bus_size_t, int);
void * dino_alloc_parent(struct device *, struct pci_attach_args *, int);
void * dino_vaddr(void *, bus_space_handle_t);
u_int8_t dino_r1(void *, bus_space_handle_t, bus_size_t);
u_int16_t dino_r2(void *, bus_space_handle_t, bus_size_t);
u_int32_t dino_r4(void *, bus_space_handle_t, bus_size_t);
u_int64_t dino_r8(void *, bus_space_handle_t, bus_size_t);
void dino_w1(void *, bus_space_handle_t, bus_size_t, u_int8_t);
void dino_w2(void *, bus_space_handle_t, bus_size_t, u_int16_t);
void dino_w4(void *, bus_space_handle_t, bus_size_t, u_int32_t);
void dino_w8(void *, bus_space_handle_t, bus_size_t, u_int64_t);
void dino_rm_1(void *, bus_space_handle_t, bus_size_t, u_int8_t *,
bus_size_t);
void dino_rm_2(void *, bus_space_handle_t, bus_size_t, u_int16_t *,
bus_size_t);
void dino_rm_4(void *, bus_space_handle_t, bus_size_t, u_int32_t *,
bus_size_t);
void dino_rm_8(void *, bus_space_handle_t, bus_size_t, u_int64_t *,
bus_size_t);
void dino_wm_1(void *, bus_space_handle_t, bus_size_t, const u_int8_t *,
bus_size_t);
void dino_wm_2(void *, bus_space_handle_t, bus_size_t, const u_int16_t *,
bus_size_t);
void dino_wm_4(void *, bus_space_handle_t, bus_size_t, const u_int32_t *,
bus_size_t);
void dino_wm_8(void *, bus_space_handle_t, bus_size_t, const u_int64_t *,
bus_size_t);
void dino_sm_1(void *, bus_space_handle_t, bus_size_t, u_int8_t, bus_size_t);
void dino_sm_2(void *, bus_space_handle_t, bus_size_t, u_int16_t,
bus_size_t);
void dino_sm_4(void *, bus_space_handle_t, bus_size_t, u_int32_t,
bus_size_t);
void dino_sm_8(void *, bus_space_handle_t, bus_size_t, u_int64_t,
bus_size_t);
void dino_rrm_2(void *, bus_space_handle_t, bus_size_t, u_int8_t *,
bus_size_t);
void dino_rrm_4(void *, bus_space_handle_t, bus_size_t, u_int8_t *,
bus_size_t);
void dino_rrm_8(void *, bus_space_handle_t, bus_size_t, u_int8_t *,
bus_size_t);
void dino_wrm_2(void *, bus_space_handle_t, bus_size_t, const u_int8_t *,
bus_size_t);
void dino_wrm_4(void *, bus_space_handle_t, bus_size_t, const u_int8_t *,
bus_size_t);
void dino_wrm_8(void *, bus_space_handle_t, bus_size_t, const u_int8_t *,
bus_size_t);
void dino_rr_1(void *, bus_space_handle_t, bus_size_t, u_int8_t *,
bus_size_t);
void dino_rr_2(void *, bus_space_handle_t, bus_size_t, u_int16_t *,
bus_size_t);
void dino_rr_4(void *, bus_space_handle_t, bus_size_t, u_int32_t *,
bus_size_t);
void dino_rr_8(void *, bus_space_handle_t, bus_size_t, u_int64_t *,
bus_size_t);
void dino_wr_1(void *, bus_space_handle_t, bus_size_t, const u_int8_t *,
bus_size_t);
void dino_wr_2(void *, bus_space_handle_t, bus_size_t, const u_int16_t *,
bus_size_t);
void dino_wr_4(void *, bus_space_handle_t, bus_size_t, const u_int32_t *,
bus_size_t);
void dino_wr_8(void *, bus_space_handle_t, bus_size_t, const u_int64_t *,
bus_size_t);
void dino_rrr_2(void *, bus_space_handle_t, bus_size_t, u_int8_t *,
bus_size_t);
void dino_rrr_4(void *, bus_space_handle_t, bus_size_t, u_int8_t *,
bus_size_t);
void dino_rrr_8(void *, bus_space_handle_t, bus_size_t, u_int8_t *,
bus_size_t);
void dino_wrr_2(void *, bus_space_handle_t, bus_size_t, const u_int8_t *,
bus_size_t);
void dino_wrr_4(void *, bus_space_handle_t, bus_size_t, const u_int8_t *,
bus_size_t);
void dino_wrr_8(void *, bus_space_handle_t, bus_size_t, const u_int8_t *,
bus_size_t);
void dino_sr_1(void *, bus_space_handle_t, bus_size_t, u_int8_t, bus_size_t);
void dino_sr_2(void *, bus_space_handle_t, bus_size_t, u_int16_t,
bus_size_t);
void dino_sr_4(void *, bus_space_handle_t, bus_size_t, u_int32_t,
bus_size_t);
void dino_sr_8(void *, bus_space_handle_t, bus_size_t, u_int64_t,
bus_size_t);
void dino_cp_1(void *, bus_space_handle_t, bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void dino_cp_2(void *, bus_space_handle_t, bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void dino_cp_4(void *, bus_space_handle_t, bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
void dino_cp_8(void *, bus_space_handle_t, bus_size_t, bus_space_handle_t,
bus_size_t, bus_size_t);
int dino_dmamap_create(void *, bus_size_t, int, bus_size_t, bus_size_t, int,
bus_dmamap_t *);
void dino_dmamap_destroy(void *, bus_dmamap_t);
int dino_dmamap_load(void *, bus_dmamap_t, void *, bus_size_t,
struct proc *, int);
int dino_dmamap_load_mbuf(void *, bus_dmamap_t, struct mbuf *, int);
int dino_dmamap_load_uio(void *, bus_dmamap_t, struct uio *, int);
int dino_dmamap_load_raw(void *, bus_dmamap_t, bus_dma_segment_t *, int,
bus_size_t, int);
void dino_dmamap_unload(void *, bus_dmamap_t);
void dino_dmamap_sync(void *, bus_dmamap_t, bus_addr_t, bus_size_t, int);
int dino_dmamem_alloc(void *, bus_size_t, bus_size_t, bus_size_t,
bus_dma_segment_t *, int, int *, int);
void dino_dmamem_free(void *, bus_dma_segment_t *, int);
int dino_dmamem_map(void *, bus_dma_segment_t *, int, size_t, caddr_t *,
int);
void dino_dmamem_unmap(void *, caddr_t, size_t);
paddr_t dino_dmamem_mmap(void *, bus_dma_segment_t *, int, off_t, int, int);
int dinoprint(void *, const char *);
void dino_clear_pdc_mappings(void *);
void
dino_attach_hook(struct device *parent, struct device *self,
struct pcibus_attach_args *pba)
{
}
int
dino_maxdevs(void *v, int bus)
{
return (32);
}
pcitag_t
dino_make_tag(void *v, int bus, int dev, int func)
{
if (bus > 255 || dev > 31 || func > 7)
panic("dino_make_tag: bad request");
return ((bus << 16) | (dev << 11) | (func << 8));
}
void
dino_decompose_tag(void *v, pcitag_t tag, int *bus, int *dev, int *func)
{
if (bus)
*bus = (tag >> 16) & 0xff;
if (dev)
*dev = (tag >> 11) & 0x1f;
if (func)
*func= (tag >> 8) & 0x07;
}
int
dino_conf_size(void *v, pcitag_t tag)
{
return PCI_CONFIG_SPACE_SIZE;
}
pcireg_t
dino_conf_read(void *v, pcitag_t tag, int reg)
{
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
pcireg_t data;
u_int32_t pamr;
/* fix arbitration errata by disabling all pci devs on config read */
pamr = r->pamr;
r->pamr = 0;
r->pci_addr = tag | reg;
data = r->pci_conf_data;
/* restore arbitration */
r->pamr = pamr;
return (letoh32(data));
}
void
dino_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
{
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
pcireg_t data1;
u_int32_t pamr;
/* fix arbitration errata by disabling all pci devs on config read */
pamr = r->pamr;
r->pamr = 0;
r->pci_addr = tag | reg;
r->pci_conf_data = htole32(data);
/* fix coalescing config and io writes by interleaving w/ a read */
r->pci_addr = tag | PCI_ID_REG;
data1 = r->pci_conf_data;
/* restore arbitration */
r->pamr = pamr;
}
int
dino_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
{
/* struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs; */
pci_chipset_tag_t pc = pa->pa_pc;
pcitag_t tag = pa->pa_tag;
pcireg_t reg;
reg = pci_conf_read(pc, tag, PCI_INTERRUPT_REG);
if (PCI_INTERRUPT_LINE(reg) == 0xff)
return (1);
*ihp = PCI_INTERRUPT_LINE(reg) + 1;
return (0);
}
const char *
dino_intr_string(void *v, pci_intr_handle_t ih)
{
static char buf[32];
snprintf(buf, 32, "irq %ld", ih);
return (buf);
}
void *
dino_intr_establish(void *v, pci_intr_handle_t ih,
int pri, int (*handler)(void *), void *arg, const char *name)
{
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
void *iv;
/* no mapping or bogus */
if (ih <= 0 || ih > 11)
return (NULL);
if ((iv = cpu_intr_map(sc->sc_ih, pri, ih - 1, handler, arg, name))) {
if (cold)
sc->sc_imr |= (1 << (ih - 1));
else
r->imr = sc->sc_imr |= (1 << (ih - 1));
}
return (iv);
}
void
dino_intr_disestablish(void *v, void *cookie)
{
#if 0
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->imr &= ~(1 << (ih - 1));
TODO cpu_intr_unmap(sc->sc_ih, cookie);
#endif
}
int
dino_iomap(void *v, bus_addr_t bpa, bus_size_t size,
int flags, bus_space_handle_t *bshp)
{
struct dino_softc *sc = v;
int error;
if ((error = extent_alloc_region(sc->sc_ioex, bpa, size, EX_NOWAIT)))
return (error);
if (bshp)
*bshp = bpa;
return (0);
}
int
dino_memmap(void *v, bus_addr_t bpa, bus_size_t size,
int flags, bus_space_handle_t *bshp)
{
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
bus_addr_t sbpa;
bus_space_handle_t bush;
u_int32_t reg;
int first = 1;
int error;
while (size != 0) {
sbpa = bpa & 0xff800000;
reg = sc->io_shadow;
reg |= 1 << ((bpa >> 23) & 0x1f);
if (reg & 0x80000001) {
#ifdef DEBUG
panic("mapping outside the mem extent range");
#endif
return (EINVAL);
}
/* map into the upper bus space, if not yet mapped this 8M */
if (reg != sc->io_shadow) {
if ((error = bus_space_map(sc->sc_bt, sbpa,
DINO_MEM_CHUNK, flags, &bush))) {
return (error);
}
r->io_addr_en |= reg;
sc->io_shadow = reg;
if (first) {
if (bshp)
*bshp = bush + (bpa - sbpa);
}
} else {
if (first) {
if (bshp)
*bshp = bpa;
}
}
if (first) {
size += (bpa - sbpa);
first = 0;
}
if (size < DINO_MEM_CHUNK)
size = 0;
else {
size -= DINO_MEM_CHUNK;
bpa = sbpa + DINO_MEM_CHUNK;
}
}
return (0);
}
int
dino_subregion(void *v, bus_space_handle_t bsh, bus_size_t offset,
bus_size_t size, bus_space_handle_t *nbshp)
{
*nbshp = bsh + offset;
return (0);
}
int
dino_ioalloc(void *v, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
bus_size_t align, bus_size_t boundary, int flags, bus_addr_t *addrp,
bus_space_handle_t *bshp)
{
struct dino_softc *sc = v;
struct extent *ex = sc->sc_ioex;
bus_addr_t bpa;
int error;
if (rstart < ex->ex_start || rend > ex->ex_end)
panic("dino_ioalloc: bad region start/end");
if ((error = extent_alloc_subregion(ex, rstart, rend, size,
align, 0, boundary, EX_NOWAIT, &bpa)))
return (error);
if (addrp)
*addrp = bpa;
if (bshp)
*bshp = bpa;
return (0);
}
int
dino_memalloc(void *v, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
bus_size_t align, bus_size_t boundary, int flags, bus_addr_t *addrp,
bus_space_handle_t *bshp)
{
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
u_int32_t reg;
if (bus_space_alloc(sc->sc_bt, rstart, rend, size,
align, boundary, flags, addrp, bshp))
return (ENOMEM);
reg = sc->io_shadow;
reg |= 1 << ((*addrp >> 23) & 0x1f);
if (reg & 0x80000001) {
#ifdef DEBUG
panic("mapping outside the mem extent range");
#endif
return (EINVAL);
}
r->io_addr_en |= reg;
sc->io_shadow = reg;
return (0);
}
void
dino_unmap(void *v, bus_space_handle_t bsh, bus_size_t size)
{
struct dino_softc *sc = v;
struct extent *ex;
bus_addr_t bpa;
bpa = bsh;
if (bsh & 0xf0000000) {
/* TODO dino_unmap mem */
/* TODO unmap from the upper bus if the last use in this 8M */
return;
} else
ex = sc->sc_ioex;
if (extent_free(ex, bpa, size, EX_NOWAIT))
printf("dino_unmap: ps 0x%lx, size 0x%lx\n"
"dino_unmap: can't free region\n", bpa, size);
}
void
dino_free(void *v, bus_space_handle_t bh, bus_size_t size)
{
/* should be enough */
dino_unmap(v, bh, size);
}
void
dino_barrier(void *v, bus_space_handle_t h, bus_size_t o, bus_size_t l, int op)
{
sync_caches();
}
#if NCARDBUS > 0
void *
dino_alloc_parent(struct device *self, struct pci_attach_args *pa, int io)
{
struct dino_softc *sc = pa->pa_pc->_cookie;
struct extent *ex;
bus_space_tag_t tag;
bus_addr_t start;
bus_size_t size;
if (io) {
ex = sc->sc_ioex;
tag = pa->pa_iot;
start = 0xa000;
size = 0x1000;
} else {
if (!sc->sc_memex) {
bus_space_handle_t memh;
bus_addr_t mem_start;
if (dino_memalloc(sc, 0xf0800000, 0xff7fffff,
DINO_MEM_WINDOW, DINO_MEM_WINDOW, EX_NOBOUNDARY,
0, &mem_start, &memh))
return (NULL);
snprintf(sc->sc_memexname, sizeof(sc->sc_memexname),
"%s_mem", sc->sc_dv.dv_xname);
if ((sc->sc_memex = extent_create(sc->sc_memexname,
mem_start, mem_start + DINO_MEM_WINDOW, M_DEVBUF,
NULL, 0, EX_NOWAIT | EX_MALLOCOK)) == NULL) {
extent_destroy(sc->sc_ioex);
bus_space_free(sc->sc_bt, memh,
DINO_MEM_WINDOW);
return (NULL);
}
}
ex = sc->sc_memex;
tag = pa->pa_memt;
start = ex->ex_start;
size = DINO_MEM_CHUNK;
}
if (extent_alloc_subregion(ex, start, ex->ex_end, size, size, 0,
EX_NOBOUNDARY, EX_NOWAIT, &start))
return (NULL);
extent_free(ex, start, size, EX_NOWAIT);
return rbus_new_root_share(tag, ex, start, size);
}
#endif
void *
dino_vaddr(void *v, bus_space_handle_t h)
{
if (h & 0xf0000000)
return ((void *)h);
else
return (NULL);
}
u_int8_t
dino_r1(void *v, bus_space_handle_t h, bus_size_t o)
{
h += o;
if (h & 0xf0000000)
return *(volatile u_int8_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
u_int8_t data;
r->pci_addr = h;
data = *((volatile u_int8_t *)&r->pci_io_data + (h & 3));
return (data);
}
}
u_int16_t
dino_r2(void *v, bus_space_handle_t h, bus_size_t o)
{
volatile u_int16_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int16_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
}
return (letoh16(*p));
}
u_int32_t
dino_r4(void *v, bus_space_handle_t h, bus_size_t o)
{
u_int32_t data;
h += o;
if (h & 0xf0000000)
data = *(volatile u_int32_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
data = r->pci_io_data;
}
return (letoh32(data));
}
u_int64_t
dino_r8(void *v, bus_space_handle_t h, bus_size_t o)
{
u_int64_t data;
h += o;
if (h & 0xf0000000)
data = *(volatile u_int64_t *)h;
else
panic("dino_r8: not implemented");
return (letoh64(data));
}
void
dino_w1(void *v, bus_space_handle_t h, bus_size_t o, u_int8_t vv)
{
h += o;
if (h & 0xf0000000)
*(volatile u_int8_t *)h = vv;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
*((volatile u_int8_t *)&r->pci_io_data + (h & 3)) = vv;
}
}
void
dino_w2(void *v, bus_space_handle_t h, bus_size_t o, u_int16_t vv)
{
volatile u_int16_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int16_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
}
*p = htole16(vv);
}
void
dino_w4(void *v, bus_space_handle_t h, bus_size_t o, u_int32_t vv)
{
h += o;
vv = htole32(vv);
if (h & 0xf0000000)
*(volatile u_int32_t *)h = vv;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
r->pci_io_data = vv;
}
}
void
dino_w8(void *v, bus_space_handle_t h, bus_size_t o, u_int64_t vv)
{
h += o;
if (h & 0xf0000000)
*(volatile u_int64_t *)h = htole64(vv);
else
panic("dino_w8: not implemented");
}
void
dino_rm_1(void *v, bus_space_handle_t h, bus_size_t o, u_int8_t *a, bus_size_t c)
{
volatile u_int8_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int8_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int8_t *)&r->pci_io_data + (h & 3);
}
while (c--)
*a++ = *p;
}
void
dino_rm_2(void *v, bus_space_handle_t h, bus_size_t o, u_int16_t *a, bus_size_t c)
{
volatile u_int16_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int16_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
}
while (c--)
*a++ = letoh16(*p);
}
void
dino_rm_4(void *v, bus_space_handle_t h, bus_size_t o, u_int32_t *a, bus_size_t c)
{
volatile u_int32_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int32_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int32_t *)&r->pci_io_data;
}
while (c--)
*a++ = letoh32(*p);
}
void
dino_rm_8(void *v, bus_space_handle_t h, bus_size_t o, u_int64_t *a, bus_size_t c)
{
panic("dino_rm_8: not implemented");
}
void
dino_wm_1(void *v, bus_space_handle_t h, bus_size_t o, const u_int8_t *a, bus_size_t c)
{
volatile u_int8_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int8_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int8_t *)&r->pci_io_data + (h & 3);
}
while (c--)
*p = *a++;
}
void
dino_wm_2(void *v, bus_space_handle_t h, bus_size_t o, const u_int16_t *a, bus_size_t c)
{
volatile u_int16_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int16_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
}
while (c--)
*p = htole16(*a++);
}
void
dino_wm_4(void *v, bus_space_handle_t h, bus_size_t o, const u_int32_t *a, bus_size_t c)
{
volatile u_int32_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int32_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int32_t *)&r->pci_io_data;
}
while (c--)
*p = htole32(*a++);
}
void
dino_wm_8(void *v, bus_space_handle_t h, bus_size_t o, const u_int64_t *a, bus_size_t c)
{
panic("dino_wm_8: not implemented");
}
void
dino_sm_1(void *v, bus_space_handle_t h, bus_size_t o, u_int8_t vv, bus_size_t c)
{
volatile u_int8_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int8_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int8_t *)&r->pci_io_data + (h & 3);
}
while (c--)
*p = vv;
}
void
dino_sm_2(void *v, bus_space_handle_t h, bus_size_t o, u_int16_t vv, bus_size_t c)
{
volatile u_int16_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int16_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
}
vv = htole16(vv);
while (c--)
*p = vv;
}
void
dino_sm_4(void *v, bus_space_handle_t h, bus_size_t o, u_int32_t vv, bus_size_t c)
{
volatile u_int32_t *p;
h += o;
if (h & 0xf0000000)
p = (volatile u_int32_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int32_t *)&r->pci_io_data;
}
vv = htole32(vv);
while (c--)
*p = vv;
}
void
dino_sm_8(void *v, bus_space_handle_t h, bus_size_t o, u_int64_t vv, bus_size_t c)
{
panic("dino_sm_8: not implemented");
}
void
dino_rrm_2(void *v, bus_space_handle_t h, bus_size_t o,
u_int8_t *a, bus_size_t c)
{
volatile u_int16_t *p, *q = (u_int16_t *)a;
h += o;
if (h & 0xf0000000)
p = (volatile u_int16_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
}
c /= 2;
while (c--)
*q++ = *p;
}
void
dino_rrm_4(void *v, bus_space_handle_t h, bus_size_t o,
u_int8_t *a, bus_size_t c)
{
volatile u_int32_t *p, *q = (u_int32_t *)a;
h += o;
if (h & 0xf0000000)
p = (volatile u_int32_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int32_t *)&r->pci_io_data;
}
c /= 4;
while (c--)
*q++ = *p;
}
void
dino_rrm_8(void *v, bus_space_handle_t h, bus_size_t o,
u_int8_t *a, bus_size_t c)
{
panic("dino_rrm_8: not implemented");
}
void
dino_wrm_2(void *v, bus_space_handle_t h, bus_size_t o,
const u_int8_t *a, bus_size_t c)
{
volatile u_int16_t *p;
const u_int16_t *q = (const u_int16_t *)a;
h += o;
if (h & 0xf0000000)
p = (volatile u_int16_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
}
c /= 2;
while (c--)
*p = *q++;
}
void
dino_wrm_4(void *v, bus_space_handle_t h, bus_size_t o,
const u_int8_t *a, bus_size_t c)
{
volatile u_int32_t *p;
const u_int32_t *q = (const u_int32_t *)a;
h += o;
if (h & 0xf0000000)
p = (volatile u_int32_t *)h;
else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
r->pci_addr = h;
p = (volatile u_int32_t *)&r->pci_io_data;
}
c /= 4;
while (c--)
*p = *q++;
}
void
dino_wrm_8(void *v, bus_space_handle_t h, bus_size_t o,
const u_int8_t *a, bus_size_t c)
{
panic("dino_wrm_8: not implemented");
}
void
dino_rr_1(void *v, bus_space_handle_t h, bus_size_t o, u_int8_t *a, bus_size_t c)
{
volatile u_int8_t *p;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int8_t *)h;
while (c--)
*a++ = *p++;
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h++) {
r->pci_addr = h;
p = (volatile u_int8_t *)&r->pci_io_data + (h & 3);
*a++ = *p;
}
}
}
void
dino_rr_2(void *v, bus_space_handle_t h, bus_size_t o, u_int16_t *a, bus_size_t c)
{
volatile u_int16_t *p, data;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int16_t *)h;
while (c--) {
data = *p++;
*a++ = letoh16(data);
}
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 2) {
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
data = *p;
*a++ = letoh16(data);
}
}
}
void
dino_rr_4(void *v, bus_space_handle_t h, bus_size_t o, u_int32_t *a, bus_size_t c)
{
volatile u_int32_t *p, data;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int32_t *)h;
while (c--) {
data = *p++;
*a++ = letoh32(data);
}
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 4) {
r->pci_addr = h;
data = r->pci_io_data;
*a++ = letoh32(data);
}
}
}
void
dino_rr_8(void *v, bus_space_handle_t h, bus_size_t o, u_int64_t *a, bus_size_t c)
{
panic("dino_rr_8: not implemented");
}
void
dino_wr_1(void *v, bus_space_handle_t h, bus_size_t o, const u_int8_t *a, bus_size_t c)
{
volatile u_int8_t *p;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int8_t *)h;
while (c--)
*p++ = *a++;
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h++) {
r->pci_addr = h;
p = (volatile u_int8_t *)&r->pci_io_data + (h & 3);
*p = *a++;
}
}
}
void
dino_wr_2(void *v, bus_space_handle_t h, bus_size_t o, const u_int16_t *a, bus_size_t c)
{
volatile u_int16_t *p, data;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int16_t *)h;
while (c--) {
data = *a++;
*p++ = htole16(data);
}
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 2) {
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
data = *a++;
*p = htole16(data);
}
}
}
void
dino_wr_4(void *v, bus_space_handle_t h, bus_size_t o, const u_int32_t *a, bus_size_t c)
{
volatile u_int32_t *p, data;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int32_t *)h;
while (c--) {
data = *a++;
*p++ = htole32(data);
}
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 4) {
r->pci_addr = h;
data = *a++;
r->pci_io_data = htole32(data);
}
}
}
void
dino_wr_8(void *v, bus_space_handle_t h, bus_size_t o, const u_int64_t *a, bus_size_t c)
{
panic("dino_wr_8: not implemented");
}
void
dino_rrr_2(void *v, bus_space_handle_t h, bus_size_t o,
u_int8_t *a, bus_size_t c)
{
volatile u_int16_t *p, *q = (u_int16_t *)a;
c /= 2;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int16_t *)h;
while (c--)
*q++ = *p++;
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 2) {
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
*q++ = *p;
}
}
}
void
dino_rrr_4(void *v, bus_space_handle_t h, bus_size_t o,
u_int8_t *a, bus_size_t c)
{
volatile u_int32_t *p, *q = (u_int32_t *)a;
c /= 4;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int32_t *)h;
while (c--)
*q++ = *p++;
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 4) {
r->pci_addr = h;
*q++ = r->pci_io_data;
}
}
}
void
dino_rrr_8(void *v, bus_space_handle_t h, bus_size_t o,
u_int8_t *a, bus_size_t c)
{
panic("dino_rrr_8: not implemented");
}
void
dino_wrr_2(void *v, bus_space_handle_t h, bus_size_t o,
const u_int8_t *a, bus_size_t c)
{
volatile u_int16_t *p;
const u_int16_t *q = (u_int16_t *)a;
c /= 2;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int16_t *)h;
while (c--)
*p++ = *q++;
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 2) {
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
*p = *q++;
}
}
}
void
dino_wrr_4(void *v, bus_space_handle_t h, bus_size_t o,
const u_int8_t *a, bus_size_t c)
{
volatile u_int32_t *p;
const u_int32_t *q = (u_int32_t *)a;
c /= 4;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int32_t *)h;
while (c--)
*p++ = *q++;
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 4) {
r->pci_addr = h;
r->pci_io_data = *q++;
}
}
}
void
dino_wrr_8(void *v, bus_space_handle_t h, bus_size_t o,
const u_int8_t *a, bus_size_t c)
{
panic("dino_wrr_8: not implemented");
}
void
dino_sr_1(void *v, bus_space_handle_t h, bus_size_t o, u_int8_t vv, bus_size_t c)
{
volatile u_int8_t *p;
h += o;
if (h & 0xf0000000) {
p = (volatile u_int8_t *)h;
while (c--)
*p++ = vv;
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h++) {
r->pci_addr = h;
p = (volatile u_int8_t *)&r->pci_io_data + (h & 3);
*p = vv;
}
}
}
void
dino_sr_2(void *v, bus_space_handle_t h, bus_size_t o, u_int16_t vv, bus_size_t c)
{
volatile u_int16_t *p;
h += o;
vv = htole16(vv);
if (h & 0xf0000000) {
p = (volatile u_int16_t *)h;
while (c--)
*p++ = vv;
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 2) {
r->pci_addr = h;
p = (volatile u_int16_t *)&r->pci_io_data;
if (h & 2)
p++;
*p = vv;
}
}
}
void
dino_sr_4(void *v, bus_space_handle_t h, bus_size_t o, u_int32_t vv, bus_size_t c)
{
volatile u_int32_t *p;
h += o;
vv = htole32(vv);
if (h & 0xf0000000) {
p = (volatile u_int32_t *)h;
while (c--)
*p++ = vv;
} else {
struct dino_softc *sc = v;
volatile struct dino_regs *r = sc->sc_regs;
for (; c--; h += 4) {
r->pci_addr = h;
r->pci_io_data = vv;
}
}
}
void
dino_sr_8(void *v, bus_space_handle_t h, bus_size_t o, u_int64_t vv, bus_size_t c)
{
panic("dino_sr_8: not implemented");
}
void
dino_cp_1(void *v, bus_space_handle_t h1, bus_size_t o1,
bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
{
while (c--)
dino_w1(v, h1, o1++, dino_r1(v, h2, o2++));
}
void
dino_cp_2(void *v, bus_space_handle_t h1, bus_size_t o1,
bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
{
while (c--) {
dino_w2(v, h1, o1, dino_r2(v, h2, o2));
o1 += 2;
o2 += 2;
}
}
void
dino_cp_4(void *v, bus_space_handle_t h1, bus_size_t o1,
bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
{
while (c--) {
dino_w4(v, h1, o1, dino_r4(v, h2, o2));
o1 += 4;
o2 += 4;
}
}
void
dino_cp_8(void *v, bus_space_handle_t h1, bus_size_t o1,
bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
{
while (c--) {
dino_w8(v, h1, o1, dino_r8(v, h2, o2));
o1 += 8;
o2 += 8;
}
}
const struct hppa_bus_space_tag dino_iomemt = {
NULL,
NULL, dino_unmap, dino_subregion, NULL, dino_free,
dino_barrier, dino_vaddr,
dino_r1, dino_r2, dino_r4, dino_r8,
dino_w1, dino_w2, dino_w4, dino_w8,
dino_rm_1, dino_rm_2, dino_rm_4, dino_rm_8,
dino_wm_1, dino_wm_2, dino_wm_4, dino_wm_8,
dino_sm_1, dino_sm_2, dino_sm_4, dino_sm_8,
dino_rrm_2, dino_rrm_4, dino_rrm_8,
dino_wrm_2, dino_wrm_4, dino_wrm_8,
dino_rr_1, dino_rr_2, dino_rr_4, dino_rr_8,
dino_wr_1, dino_wr_2, dino_wr_4, dino_wr_8,
dino_rrr_2, dino_rrr_4, dino_rrr_8,
dino_wrr_2, dino_wrr_4, dino_wrr_8,
dino_sr_1, dino_sr_2, dino_sr_4, dino_sr_8,
dino_cp_1, dino_cp_2, dino_cp_4, dino_cp_8
};
int
dino_dmamap_create(void *v, bus_size_t size, int nsegments,
bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp)
{
struct dino_softc *sc = v;
/* TODO check the addresses, boundary, enable dma */
return (bus_dmamap_create(sc->sc_dmat, size, nsegments,
maxsegsz, boundary, flags, dmamp));
}
void
dino_dmamap_destroy(void *v, bus_dmamap_t map)
{
struct dino_softc *sc = v;
bus_dmamap_destroy(sc->sc_dmat, map);
}
int
dino_dmamap_load(void *v, bus_dmamap_t map, void *addr, bus_size_t size,
struct proc *p, int flags)
{
struct dino_softc *sc = v;
return (bus_dmamap_load(sc->sc_dmat, map, addr, size, p, flags));
}
int
dino_dmamap_load_mbuf(void *v, bus_dmamap_t map, struct mbuf *m, int flags)
{
struct dino_softc *sc = v;
return (bus_dmamap_load_mbuf(sc->sc_dmat, map, m, flags));
}
int
dino_dmamap_load_uio(void *v, bus_dmamap_t map, struct uio *uio, int flags)
{
struct dino_softc *sc = v;
return (bus_dmamap_load_uio(sc->sc_dmat, map, uio, flags));
}
int
dino_dmamap_load_raw(void *v, bus_dmamap_t map, bus_dma_segment_t *segs,
int nsegs, bus_size_t size, int flags)
{
struct dino_softc *sc = v;
return (bus_dmamap_load_raw(sc->sc_dmat, map, segs, nsegs, size, flags));
}
void
dino_dmamap_unload(void *v, bus_dmamap_t map)
{
struct dino_softc *sc = v;
bus_dmamap_unload(sc->sc_dmat, map);
}
void
dino_dmamap_sync(void *v, bus_dmamap_t map, bus_addr_t off,
bus_size_t len, int ops)
{
struct dino_softc *sc = v;
return (bus_dmamap_sync(sc->sc_dmat, map, off, len, ops));
}
int
dino_dmamem_alloc(void *v, bus_size_t size, bus_size_t alignment,
bus_size_t boundary, bus_dma_segment_t *segs,
int nsegs, int *rsegs, int flags)
{
struct dino_softc *sc = v;
return (bus_dmamem_alloc(sc->sc_dmat, size, alignment, boundary,
segs, nsegs, rsegs, flags));
}
void
dino_dmamem_free(void *v, bus_dma_segment_t *segs, int nsegs)
{
struct dino_softc *sc = v;
bus_dmamem_free(sc->sc_dmat, segs, nsegs);
}
int
dino_dmamem_map(void *v, bus_dma_segment_t *segs, int nsegs, size_t size,
caddr_t *kvap, int flags)
{
struct dino_softc *sc = v;
return (bus_dmamem_map(sc->sc_dmat, segs, nsegs, size, kvap, flags));
}
void
dino_dmamem_unmap(void *v, caddr_t kva, size_t size)
{
struct dino_softc *sc = v;
bus_dmamem_unmap(sc->sc_dmat, kva, size);
}
paddr_t
dino_dmamem_mmap(void *v, bus_dma_segment_t *segs, int nsegs, off_t off,
int prot, int flags)
{
struct dino_softc *sc = v;
return (bus_dmamem_mmap(sc->sc_dmat, segs, nsegs, off, prot, flags));
}
const struct hppa_bus_dma_tag dino_dmat = {
NULL,
dino_dmamap_create, dino_dmamap_destroy,
dino_dmamap_load, dino_dmamap_load_mbuf,
dino_dmamap_load_uio, dino_dmamap_load_raw,
dino_dmamap_unload, dino_dmamap_sync,
dino_dmamem_alloc, dino_dmamem_free, dino_dmamem_map,
dino_dmamem_unmap, dino_dmamem_mmap
};
const struct hppa_pci_chipset_tag dino_pc = {
NULL,
dino_attach_hook, dino_maxdevs, dino_make_tag, dino_decompose_tag,
dino_conf_size, dino_conf_read, dino_conf_write,
dino_intr_map, dino_intr_string,
dino_intr_establish, dino_intr_disestablish,
#if NCARDBUS > 0
dino_alloc_parent
#else
NULL
#endif
};
int
dinoprint(void *aux, const char *pnp)
{
struct pcibus_attach_args *pba = aux;
if (pnp)
printf("%s at %s\n", pba->pba_busname, pnp);
return (UNCONF);
}
void
dinoattach(parent, self, aux)
struct device *parent;
struct device *self;
void *aux;
{
struct dino_softc *sc = (struct dino_softc *)self;
struct confargs *ca = (struct confargs *)aux;
struct pcibus_attach_args pba;
volatile struct dino_regs *r;
const char *p = NULL;
u_int data;
int s;
sc->sc_bt = ca->ca_iot;
sc->sc_dmat = ca->ca_dmatag;
if (bus_space_map(sc->sc_bt, ca->ca_hpa, PAGE_SIZE, 0, &sc->sc_bh)) {
printf(": can't map space\n");
return;
}
sc->sc_regs = r = (volatile struct dino_regs *)sc->sc_bh;
r->pciror = 0;
r->pciwor = 0;
/*
* Do not reset enabled io mappings mask if we are still running
* with PDC console - we'll do it after autoconf.
*/
if (cn_tab->cn_putc != pdccnputc)
r->io_addr_en = 0;
sc->io_shadow = 0;
r->gmask &= ~1; /* allow GSC bus req */
r->brdg_feat &= ~0xf00;
r->brdg_feat |= 3;
#ifdef notyet_card_mode
r->io_control = 0x80;
r->pamr = 0;
r->papr = 0;
r->io_fbb_en |= 1;
r->damode = 0;
r->brdg_feat = 0xc0000000 XXX;
r->mltim = 0x40; /* 64 clocks */
r->tltim = 0x8c; /* 12 clocks */
/* PCI reset */
r->pcicmd = 0x6f;
DELAY(10000); /* 10ms for reset to settle */
#endif
snprintf(sc->sc_ioexname, sizeof(sc->sc_ioexname),
"%s_io", sc->sc_dv.dv_xname);
if ((sc->sc_ioex = extent_create(sc->sc_ioexname, 0, 0xffff,
M_DEVBUF, NULL, 0, EX_NOWAIT | EX_MALLOCOK)) == NULL) {
printf(": cannot allocate I/O extent map\n");
bus_space_unmap(sc->sc_bt, sc->sc_bh, PAGE_SIZE);
return;
}
/* TODO reserve dino's pci space ? */
s = splhigh();
r->imr = ~0;
data = r->irr0;
data = r->irr1;
r->imr = 0;
__asm __volatile ("" ::: "memory");
r->icr = 0;
r->iar0 = cpu_gethpa(0) | (31 - ca->ca_irq);
splx(s);
sc->sc_ih = cpu_intr_establish(IPL_NESTED, ca->ca_irq,
dino_intr, (void *)sc->sc_regs, sc->sc_dv.dv_xname);
/* TODO establish the bus error interrupt */
sc->sc_ver = ca->ca_type.iodc_revision;
switch ((ca->ca_type.iodc_model << 4) |
(ca->ca_type.iodc_revision >> 4)) {
case 0x05d: /* j2240 */
p = "Dino(card)";
case 0x680:
if (!p)
p = "Dino";
switch (ca->ca_type.iodc_revision & 0xf) {
case 0: sc->sc_ver = 0x20; break;
case 1: sc->sc_ver = 0x21; break;
case 2: sc->sc_ver = 0x30; break;
case 3: sc->sc_ver = 0x31; break;
}
break;
case 0x682:
p = "Cujo";
switch (ca->ca_type.iodc_revision & 0xf) {
case 0: sc->sc_ver = 0x10; break;
case 1: sc->sc_ver = 0x20; break;
}
break;
default:
p = "Mojo";
break;
}
printf(": %s V%d.%d\n", p, sc->sc_ver >> 4, sc->sc_ver & 0xf);
sc->sc_iot = dino_iomemt;
sc->sc_iot.hbt_cookie = sc;
sc->sc_iot.hbt_map = dino_iomap;
sc->sc_iot.hbt_alloc = dino_ioalloc;
sc->sc_memt = dino_iomemt;
sc->sc_memt.hbt_cookie = sc;
sc->sc_memt.hbt_map = dino_memmap;
sc->sc_memt.hbt_alloc = dino_memalloc;
sc->sc_pc = dino_pc;
sc->sc_pc._cookie = sc;
sc->sc_dmatag = dino_dmat;
sc->sc_dmatag._cookie = sc;
/* scan for ps2 kbd/ms, serial, and flying toasters */
ca->ca_hpamask = -1;
pdc_scanbus(self, ca, MAXMODBUS, 0, 0);
bzero(&pba, sizeof(pba));
pba.pba_busname = "pci";
pba.pba_iot = &sc->sc_iot;
pba.pba_memt = &sc->sc_memt;
pba.pba_dmat = &sc->sc_dmatag;
pba.pba_pc = &sc->sc_pc;
pba.pba_domain = pci_ndomains++;
pba.pba_bus = 0;
config_found(self, &pba, dinoprint);
/* postpone cleanup if necessary */
if (r->io_addr_en != sc->io_shadow)
startuphook_establish(dino_clear_pdc_mappings, sc);
/* enable interrupts now that all the devices are there */
r->imr = sc->sc_imr;
}
void
dino_clear_pdc_mappings(void *v)
{
struct dino_softc *sc = (struct dino_softc *)v;
volatile struct dino_regs *r;
if (cn_tab->cn_putc == pdccnputc) {
/* damn! */
return;
}
r = sc->sc_regs;
r->io_addr_en = sc->io_shadow;
}
|