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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* PCI nexus driver interface
*/
/*
* Copyright 2019 Peter Tribble.
*/
#include <sys/types.h>
#include <sys/conf.h> /* nulldev */
#include <sys/stat.h> /* devctl */
#include <sys/kmem.h>
#include <sys/async.h> /* ecc_flt for pci_ecc.h */
#include <sys/sunddi.h>
#include <sys/sunndi.h>
#include <sys/ndifm.h>
#include <sys/ontrap.h>
#include <sys/ddi_impldefs.h>
#include <sys/ddi_subrdefs.h>
#include <sys/epm.h>
#include <sys/hotplug/pci/pcihp.h>
#include <sys/pci/pci_tools_ext.h>
#include <sys/spl.h>
#include <sys/pci/pci_obj.h>
/*LINTLIBRARY*/
/*
* function prototype for hotplug routine:
*/
static void
pci_init_hotplug(struct pci *);
/*
* function prototypes for dev ops routines:
*/
static int pci_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
static int pci_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
static int pci_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
void *arg, void **result);
static int pci_ctlops_poke(pci_t *pci_p, peekpoke_ctlops_t *in_args);
static int pci_ctlops_peek(pci_t *pci_p, peekpoke_ctlops_t *in_args,
void *result);
static off_t get_reg_set_size(dev_info_t *child, int rnumber);
/*
* bus ops and dev ops structures:
*/
static struct bus_ops pci_bus_ops = {
BUSO_REV,
pci_map,
0,
0,
0,
i_ddi_map_fault,
pci_dma_setup,
pci_dma_allochdl,
pci_dma_freehdl,
pci_dma_bindhdl,
pci_dma_unbindhdl,
pci_dma_sync,
pci_dma_win,
pci_dma_ctlops,
pci_ctlops,
ddi_bus_prop_op,
ndi_busop_get_eventcookie, /* (*bus_get_eventcookie)(); */
ndi_busop_add_eventcall, /* (*bus_add_eventcall)(); */
ndi_busop_remove_eventcall, /* (*bus_remove_eventcall)(); */
ndi_post_event, /* (*bus_post_event)(); */
NULL, /* (*bus_intr_ctl)(); */
NULL, /* (*bus_config)(); */
NULL, /* (*bus_unconfig)(); */
pci_fm_init_child, /* (*bus_fm_init)(); */
NULL, /* (*bus_fm_fini)(); */
pci_bus_enter, /* (*bus_fm_access_enter)(); */
pci_bus_exit, /* (*bus_fm_access_fini)(); */
NULL, /* (*bus_power)(); */
pci_intr_ops /* (*bus_intr_op)(); */
};
extern struct cb_ops pci_cb_ops;
static struct dev_ops pci_ops = {
DEVO_REV,
0,
pci_info,
nulldev,
0,
pci_attach,
pci_detach,
nodev,
&pci_cb_ops,
&pci_bus_ops,
0,
ddi_quiesce_not_supported, /* devo_quiesce */
};
/*
* module definitions:
*/
#include <sys/modctl.h>
extern struct mod_ops mod_driverops;
static struct modldrv modldrv = {
&mod_driverops, /* Type of module - driver */
"Sun4u Host to PCI nexus driver", /* Name of module. */
&pci_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
MODREV_1, (void *)&modldrv, NULL
};
/*
* driver global data:
*/
void *per_pci_state; /* per-pbm soft state pointer */
void *per_pci_common_state; /* per-psycho soft state pointer */
kmutex_t pci_global_mutex; /* attach/detach common struct lock */
errorq_t *pci_ecc_queue = NULL; /* per-system ecc handling queue */
extern errorq_t *pci_target_queue;
struct cb_ops *pcihp_ops = NULL; /* hotplug module cb ops */
extern void pci_child_cfg_save(dev_info_t *dip);
extern void pci_child_cfg_restore(dev_info_t *dip);
int
_init(void)
{
int e;
/*
* Initialize per-pci bus soft state pointer.
*/
e = ddi_soft_state_init(&per_pci_state, sizeof (pci_t), 1);
if (e != 0)
return (e);
/*
* Initialize per-psycho soft state pointer.
*/
e = ddi_soft_state_init(&per_pci_common_state,
sizeof (pci_common_t), 1);
if (e != 0) {
ddi_soft_state_fini(&per_pci_state);
return (e);
}
/*
* Initialize global mutexes.
*/
mutex_init(&pci_global_mutex, NULL, MUTEX_DRIVER, NULL);
pci_reloc_init();
/*
* Create the performance kstats.
*/
pci_kstat_init();
/*
* Install the module.
*/
e = mod_install(&modlinkage);
if (e != 0) {
ddi_soft_state_fini(&per_pci_state);
ddi_soft_state_fini(&per_pci_common_state);
mutex_destroy(&pci_global_mutex);
}
return (e);
}
int
_fini(void)
{
int e;
/*
* Remove the module.
*/
e = mod_remove(&modlinkage);
if (e != 0)
return (e);
/*
* Destroy pci_ecc_queue, and set it to NULL.
*/
if (pci_ecc_queue)
errorq_destroy(pci_ecc_queue);
pci_ecc_queue = NULL;
/*
* Destroy pci_target_queue, and set it to NULL.
*/
if (pci_target_queue)
errorq_destroy(pci_target_queue);
pci_target_queue = NULL;
/*
* Destroy the performance kstats.
*/
pci_kstat_fini();
/*
* Free the per-pci and per-psycho soft state info and destroy
* mutex for per-psycho soft state.
*/
ddi_soft_state_fini(&per_pci_state);
ddi_soft_state_fini(&per_pci_common_state);
mutex_destroy(&pci_global_mutex);
pci_reloc_fini();
return (e);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
/*ARGSUSED*/
static int
pci_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
{
int instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(getminor((dev_t)arg));
pci_t *pci_p = get_pci_soft_state(instance);
/* allow hotplug to deal with ones it manages */
if (pci_p && (pci_p->hotplug_capable == B_TRUE))
return (pcihp_info(dip, infocmd, arg, result));
/* non-hotplug or not attached */
switch (infocmd) {
case DDI_INFO_DEVT2INSTANCE:
*result = (void *)(uintptr_t)instance;
return (DDI_SUCCESS);
case DDI_INFO_DEVT2DEVINFO:
if (pci_p == NULL)
return (DDI_FAILURE);
*result = (void *)pci_p->pci_dip;
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
/* device driver entry points */
/*
* attach entry point:
*/
static int
pci_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
pci_t *pci_p; /* per bus state pointer */
int instance = ddi_get_instance(dip);
switch (cmd) {
case DDI_ATTACH:
DEBUG0(DBG_ATTACH, dip, "DDI_ATTACH\n");
/*
* Allocate and get the per-pci soft state structure.
*/
if (alloc_pci_soft_state(instance) != DDI_SUCCESS) {
cmn_err(CE_WARN, "%s%d: can't allocate pci state",
ddi_driver_name(dip), instance);
goto err_bad_pci_softstate;
}
pci_p = get_pci_soft_state(instance);
pci_p->pci_dip = dip;
mutex_init(&pci_p->pci_mutex, NULL, MUTEX_DRIVER, NULL);
pci_p->pci_soft_state = PCI_SOFT_STATE_CLOSED;
/*
* Get key properties of the pci bridge node and
* determine it's type (psycho, schizo, etc ...).
*/
if (get_pci_properties(pci_p, dip) == DDI_FAILURE)
goto err_bad_pci_prop;
/*
* Map in the registers.
*/
if (map_pci_registers(pci_p, dip) == DDI_FAILURE)
goto err_bad_reg_prop;
if (pci_obj_setup(pci_p) != DDI_SUCCESS)
goto err_bad_objs;
/*
* If this PCI leaf has hotplug and this platform
* loads hotplug modules then initialize the
* hotplug framework.
*/
pci_init_hotplug(pci_p);
/*
* Create the "devctl" node for hotplug support.
* For non-hotplug bus, we still need ":devctl" to
* support DEVCTL_DEVICE_* and DEVCTL_BUS_* ioctls.
*/
if (pci_p->hotplug_capable == B_FALSE) {
if (ddi_create_minor_node(dip, "devctl", S_IFCHR,
PCIHP_AP_MINOR_NUM(instance, PCIHP_DEVCTL_MINOR),
DDI_NT_NEXUS, 0) != DDI_SUCCESS)
goto err_bad_devctl_node;
}
/*
* Create pcitool nodes for register access and interrupt
* routing.
*/
if (pcitool_init(dip) != DDI_SUCCESS) {
goto err_bad_pcitool_nodes;
}
ddi_report_dev(dip);
pci_p->pci_state = PCI_ATTACHED;
DEBUG0(DBG_ATTACH, dip, "attach success\n");
break;
err_bad_pcitool_nodes:
if (pci_p->hotplug_capable == B_FALSE)
ddi_remove_minor_node(dip, "devctl");
else
(void) pcihp_uninit(dip);
err_bad_devctl_node:
pci_obj_destroy(pci_p);
err_bad_objs:
unmap_pci_registers(pci_p);
err_bad_reg_prop:
free_pci_properties(pci_p);
err_bad_pci_prop:
mutex_destroy(&pci_p->pci_mutex);
free_pci_soft_state(instance);
err_bad_pci_softstate:
return (DDI_FAILURE);
case DDI_RESUME:
DEBUG0(DBG_ATTACH, dip, "DDI_RESUME\n");
/*
* Make sure the Psycho control registers and IOMMU
* are configured properly.
*/
pci_p = get_pci_soft_state(instance);
mutex_enter(&pci_p->pci_mutex);
/*
* Make sure this instance has been suspended.
*/
if (pci_p->pci_state != PCI_SUSPENDED) {
DEBUG0(DBG_ATTACH, dip, "instance NOT suspended\n");
mutex_exit(&pci_p->pci_mutex);
return (DDI_FAILURE);
}
pci_obj_resume(pci_p);
pci_p->pci_state = PCI_ATTACHED;
pci_child_cfg_restore(dip);
mutex_exit(&pci_p->pci_mutex);
break;
default:
DEBUG0(DBG_ATTACH, dip, "unsupported attach op\n");
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* detach entry point:
*/
static int
pci_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
{
int instance = ddi_get_instance(dip);
pci_t *pci_p = get_pci_soft_state(instance);
/*
* Make sure we are currently attached
*/
if (pci_p->pci_state != PCI_ATTACHED) {
DEBUG0(DBG_ATTACH, dip, "failed - instance not attached\n");
return (DDI_FAILURE);
}
mutex_enter(&pci_p->pci_mutex);
switch (cmd) {
case DDI_DETACH:
DEBUG0(DBG_DETACH, dip, "DDI_DETACH\n");
if (pci_p->hotplug_capable == B_TRUE)
if (pcihp_uninit(dip) == DDI_FAILURE) {
mutex_exit(&pci_p->pci_mutex);
return (DDI_FAILURE);
}
pcitool_uninit(dip);
pci_obj_destroy(pci_p);
/*
* Free the pci soft state structure and the rest of the
* resources it's using.
*/
free_pci_properties(pci_p);
unmap_pci_registers(pci_p);
mutex_exit(&pci_p->pci_mutex);
mutex_destroy(&pci_p->pci_mutex);
free_pci_soft_state(instance);
/* Free the interrupt-priorities prop if we created it. */
{
int len;
if (ddi_getproplen(DDI_DEV_T_ANY, dip,
DDI_PROP_NOTPROM | DDI_PROP_DONTPASS,
"interrupt-priorities", &len) == DDI_PROP_SUCCESS)
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip,
"interrupt-priorities");
}
return (DDI_SUCCESS);
case DDI_SUSPEND:
pci_child_cfg_save(dip);
pci_obj_suspend(pci_p);
pci_p->pci_state = PCI_SUSPENDED;
mutex_exit(&pci_p->pci_mutex);
return (DDI_SUCCESS);
default:
DEBUG0(DBG_DETACH, dip, "unsupported detach op\n");
mutex_exit(&pci_p->pci_mutex);
return (DDI_FAILURE);
}
}
/* bus driver entry points */
/*
* bus map entry point:
*
* if map request is for an rnumber
* get the corresponding regspec from device node
* build a new regspec in our parent's format
* build a new map_req with the new regspec
* call up the tree to complete the mapping
*/
int
pci_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
off_t off, off_t len, caddr_t *addrp)
{
pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
struct regspec p_regspec;
ddi_map_req_t p_mapreq;
int reglen, rval, r_no;
pci_regspec_t reloc_reg, *rp = &reloc_reg;
DEBUG2(DBG_MAP, dip, "rdip=%s%d:",
ddi_driver_name(rdip), ddi_get_instance(rdip));
if (mp->map_flags & DDI_MF_USER_MAPPING)
return (DDI_ME_UNIMPLEMENTED);
switch (mp->map_type) {
case DDI_MT_REGSPEC:
reloc_reg = *(pci_regspec_t *)mp->map_obj.rp; /* dup whole */
break;
case DDI_MT_RNUMBER:
r_no = mp->map_obj.rnumber;
DEBUG1(DBG_MAP | DBG_CONT, dip, " r#=%x", r_no);
if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
"reg", (caddr_t)&rp, ®len) != DDI_SUCCESS)
return (DDI_ME_RNUMBER_RANGE);
if (r_no < 0 || r_no >= reglen / sizeof (pci_regspec_t)) {
kmem_free(rp, reglen);
return (DDI_ME_RNUMBER_RANGE);
}
rp += r_no;
break;
default:
return (DDI_ME_INVAL);
}
DEBUG0(DBG_MAP | DBG_CONT, dip, "\n");
/* use "assigned-addresses" to relocate regspec within pci space */
if (rval = pci_reloc_reg(dip, rdip, pci_p, rp))
goto done;
if (len) /* adjust regspec according to mapping request */
rp->pci_size_low = len;
rp->pci_phys_low += off;
/* use "ranges" to translate relocated pci regspec into parent space */
if (rval = pci_xlate_reg(pci_p, rp, &p_regspec))
goto done;
p_mapreq = *mp; /* dup the whole structure */
p_mapreq.map_type = DDI_MT_REGSPEC;
p_mapreq.map_obj.rp = &p_regspec;
rval = ddi_map(dip, &p_mapreq, 0, 0, addrp);
if (rval == DDI_SUCCESS) {
/*
* Set-up access functions for FM access error capable drivers.
*/
if (DDI_FM_ACC_ERR_CAP(pci_p->pci_fm_cap) &&
DDI_FM_ACC_ERR_CAP(ddi_fm_capable(rdip)) &&
mp->map_handlep->ah_acc.devacc_attr_access !=
DDI_DEFAULT_ACC)
pci_fm_acc_setup(mp, rdip);
}
done:
if (mp->map_type == DDI_MT_RNUMBER)
kmem_free(rp - r_no, reglen);
return (rval);
}
/*
* bus dma map entry point
* return value:
* DDI_DMA_PARTIAL_MAP 1
* DDI_DMA_MAPOK 0
* DDI_DMA_MAPPED 0
* DDI_DMA_NORESOURCES -1
* DDI_DMA_NOMAPPING -2
* DDI_DMA_TOOBIG -3
*/
int
pci_dma_setup(dev_info_t *dip, dev_info_t *rdip, ddi_dma_req_t *dmareq,
ddi_dma_handle_t *handlep)
{
pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
iommu_t *iommu_p = pci_p->pci_iommu_p;
ddi_dma_impl_t *mp;
int ret;
DEBUG3(DBG_DMA_MAP, dip, "mapping - rdip=%s%d type=%s\n",
ddi_driver_name(rdip), ddi_get_instance(rdip),
handlep ? "alloc" : "advisory");
if (!(mp = pci_dma_lmts2hdl(dip, rdip, iommu_p, dmareq)))
return (DDI_DMA_NORESOURCES);
if (mp == (ddi_dma_impl_t *)DDI_DMA_NOMAPPING)
return (DDI_DMA_NOMAPPING);
if (ret = pci_dma_type(pci_p, dmareq, mp))
goto freehandle;
if (ret = pci_dma_pfn(pci_p, dmareq, mp))
goto freehandle;
switch (PCI_DMA_TYPE(mp)) {
case DMAI_FLAGS_DVMA: /* LINTED E_EQUALITY_NOT_ASSIGNMENT */
if ((ret = pci_dvma_win(pci_p, dmareq, mp)) || !handlep)
goto freehandle;
if (!PCI_DMA_CANCACHE(mp)) { /* try fast track */
if (PCI_DMA_CANFAST(mp)) {
if (!pci_dvma_map_fast(iommu_p, mp))
break;
/* LINTED E_NOP_ELSE_STMT */
} else {
PCI_DVMA_FASTTRAK_PROF(mp);
}
}
if (ret = pci_dvma_map(mp, dmareq, iommu_p))
goto freehandle;
break;
case DMAI_FLAGS_PEER_TO_PEER: /* LINTED E_EQUALITY_NOT_ASSIGNMENT */
if ((ret = pci_dma_physwin(pci_p, dmareq, mp)) || !handlep)
goto freehandle;
break;
case DMAI_FLAGS_BYPASS:
default:
panic("%s%d: pci_dma_setup: bad dma type 0x%x",
ddi_driver_name(rdip), ddi_get_instance(rdip),
PCI_DMA_TYPE(mp));
/*NOTREACHED*/
}
*handlep = (ddi_dma_handle_t)mp;
mp->dmai_flags |= (DMAI_FLAGS_INUSE | DMAI_FLAGS_MAPPED);
dump_dma_handle(DBG_DMA_MAP, dip, mp);
return ((mp->dmai_nwin == 1) ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP);
freehandle:
if (ret == DDI_DMA_NORESOURCES)
pci_dma_freemp(mp); /* don't run_callback() */
else
(void) pci_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp);
return (ret);
}
/*
* bus dma alloc handle entry point:
*/
int
pci_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attrp,
int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep)
{
pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
ddi_dma_impl_t *mp;
int rval;
DEBUG2(DBG_DMA_ALLOCH, dip, "rdip=%s%d\n",
ddi_driver_name(rdip), ddi_get_instance(rdip));
if (attrp->dma_attr_version != DMA_ATTR_V0)
return (DDI_DMA_BADATTR);
if (!(mp = pci_dma_allocmp(dip, rdip, waitfp, arg)))
return (DDI_DMA_NORESOURCES);
/*
* Save requestor's information
*/
mp->dmai_attr = *attrp; /* whole object - augmented later */
*DEV_ATTR(mp) = *attrp; /* whole object - device orig attr */
DEBUG1(DBG_DMA_ALLOCH, dip, "mp=%p\n", mp);
/* check and convert dma attributes to handle parameters */
if (rval = pci_dma_attr2hdl(pci_p, mp)) {
pci_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp);
*handlep = NULL;
return (rval);
}
*handlep = (ddi_dma_handle_t)mp;
return (DDI_SUCCESS);
}
/*
* bus dma free handle entry point:
*/
/*ARGSUSED*/
int
pci_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle)
{
DEBUG3(DBG_DMA_FREEH, dip, "rdip=%s%d mp=%p\n",
ddi_driver_name(rdip), ddi_get_instance(rdip), handle);
pci_dma_freemp((ddi_dma_impl_t *)handle);
if (pci_kmem_clid) {
DEBUG0(DBG_DMA_FREEH, dip, "run handle callback\n");
ddi_run_callback(&pci_kmem_clid);
}
return (DDI_SUCCESS);
}
/*
* bus dma bind handle entry point:
*/
int
pci_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, ddi_dma_req_t *dmareq,
ddi_dma_cookie_t *cookiep, uint_t *ccountp)
{
pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
iommu_t *iommu_p = pci_p->pci_iommu_p;
ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
int ret;
DEBUG4(DBG_DMA_BINDH, dip, "rdip=%s%d mp=%p dmareq=%p\n",
ddi_driver_name(rdip), ddi_get_instance(rdip), mp, dmareq);
if (mp->dmai_flags & DMAI_FLAGS_INUSE)
return (DDI_DMA_INUSE);
ASSERT((mp->dmai_flags & ~DMAI_FLAGS_PRESERVE) == 0);
mp->dmai_flags |= DMAI_FLAGS_INUSE;
if (ret = pci_dma_type(pci_p, dmareq, mp))
goto err;
if (ret = pci_dma_pfn(pci_p, dmareq, mp))
goto err;
switch (PCI_DMA_TYPE(mp)) {
case DMAI_FLAGS_DVMA:
if (ret = pci_dvma_win(pci_p, dmareq, mp))
goto map_err;
if (!PCI_DMA_CANCACHE(mp)) { /* try fast track */
if (PCI_DMA_CANFAST(mp)) {
if (!pci_dvma_map_fast(iommu_p, mp))
goto mapped; /*LINTED E_NOP_ELSE_STMT*/
} else {
PCI_DVMA_FASTTRAK_PROF(mp);
}
}
if (ret = pci_dvma_map(mp, dmareq, iommu_p))
goto map_err;
mapped:
*ccountp = 1;
MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping, mp->dmai_size);
mp->dmai_ncookies = 1;
mp->dmai_curcookie = 1;
break;
case DMAI_FLAGS_BYPASS:
case DMAI_FLAGS_PEER_TO_PEER:
if (ret = pci_dma_physwin(pci_p, dmareq, mp))
goto map_err;
*ccountp = WINLST(mp)->win_ncookies;
*cookiep = *(ddi_dma_cookie_t *)(WINLST(mp) + 1); /* wholeobj */
/*
* mp->dmai_ncookies and mp->dmai_curcookie are set by
* pci_dma_physwin().
*/
break;
default:
panic("%s%d: pci_dma_bindhdl(%p): bad dma type",
ddi_driver_name(rdip), ddi_get_instance(rdip), mp);
/*NOTREACHED*/
}
DEBUG2(DBG_DMA_BINDH, dip, "cookie %x+%x\n", cookiep->dmac_address,
cookiep->dmac_size);
dump_dma_handle(DBG_DMA_MAP, dip, mp);
if (mp->dmai_attr.dma_attr_flags & DDI_DMA_FLAGERR)
mp->dmai_error.err_cf = impl_dma_check;
mp->dmai_flags |= DMAI_FLAGS_MAPPED;
return (mp->dmai_nwin == 1 ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP);
map_err:
pci_dvma_unregister_callbacks(pci_p, mp);
pci_dma_freepfn(mp);
err:
mp->dmai_flags &= DMAI_FLAGS_PRESERVE;
return (ret);
}
/*
* bus dma unbind handle entry point:
*/
/*ARGSUSED*/
int
pci_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle)
{
ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
iommu_t *iommu_p = pci_p->pci_iommu_p;
DEBUG3(DBG_DMA_UNBINDH, dip, "rdip=%s%d, mp=%p\n",
ddi_driver_name(rdip), ddi_get_instance(rdip), handle);
if ((mp->dmai_flags & DMAI_FLAGS_INUSE) == 0) {
DEBUG0(DBG_DMA_UNBINDH, dip, "handle not in use\n");
return (DDI_FAILURE);
}
mp->dmai_flags &= ~DMAI_FLAGS_MAPPED;
switch (PCI_DMA_TYPE(mp)) {
case DMAI_FLAGS_DVMA:
pci_dvma_unregister_callbacks(pci_p, mp);
pci_dma_sync_unmap(dip, rdip, mp);
pci_dvma_unmap(iommu_p, mp);
pci_dma_freepfn(mp);
break;
case DMAI_FLAGS_BYPASS:
case DMAI_FLAGS_PEER_TO_PEER:
pci_dma_freewin(mp);
break;
default:
panic("%s%d: pci_dma_unbindhdl:bad dma type %p",
ddi_driver_name(rdip), ddi_get_instance(rdip), mp);
/*NOTREACHED*/
}
if (iommu_p->iommu_dvma_clid != 0) {
DEBUG0(DBG_DMA_UNBINDH, dip, "run dvma callback\n");
ddi_run_callback(&iommu_p->iommu_dvma_clid);
}
if (pci_kmem_clid) {
DEBUG0(DBG_DMA_UNBINDH, dip, "run handle callback\n");
ddi_run_callback(&pci_kmem_clid);
}
mp->dmai_flags &= DMAI_FLAGS_PRESERVE;
SYNC_BUF_PA(mp) = 0;
mp->dmai_error.err_cf = NULL;
mp->dmai_ncookies = 0;
mp->dmai_curcookie = 0;
return (DDI_SUCCESS);
}
/*
* bus dma win entry point:
*/
int
pci_dma_win(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, uint_t win, off_t *offp,
size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp)
{
ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
DEBUG2(DBG_DMA_WIN, dip, "rdip=%s%d\n",
ddi_driver_name(rdip), ddi_get_instance(rdip));
dump_dma_handle(DBG_DMA_WIN, dip, mp);
if (win >= mp->dmai_nwin) {
DEBUG1(DBG_DMA_WIN, dip, "%x out of range\n", win);
return (DDI_FAILURE);
}
switch (PCI_DMA_TYPE(mp)) {
case DMAI_FLAGS_DVMA:
if (win != PCI_DMA_CURWIN(mp)) {
pci_t *pci_p =
get_pci_soft_state(ddi_get_instance(dip));
pci_dma_sync_unmap(dip, rdip, mp);
/* map_window sets dmai_mapping/size/offset */
iommu_map_window(pci_p->pci_iommu_p, mp, win);
}
if (cookiep)
MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping,
mp->dmai_size);
if (ccountp)
*ccountp = 1;
mp->dmai_ncookies = 1;
mp->dmai_curcookie = 1;
break;
case DMAI_FLAGS_PEER_TO_PEER:
case DMAI_FLAGS_BYPASS: {
int i;
ddi_dma_cookie_t *ck_p;
pci_dma_win_t *win_p = mp->dmai_winlst;
for (i = 0; i < win; win_p = win_p->win_next, i++)
;
ck_p = (ddi_dma_cookie_t *)(win_p + 1);
*cookiep = *ck_p;
mp->dmai_offset = win_p->win_offset;
mp->dmai_size = win_p->win_size;
mp->dmai_mapping = ck_p->dmac_laddress;
mp->dmai_cookie = ck_p + 1;
win_p->win_curseg = 0;
if (ccountp)
*ccountp = win_p->win_ncookies;
mp->dmai_ncookies = win_p->win_ncookies;
mp->dmai_curcookie = 1;
}
break;
default:
cmn_err(CE_WARN, "%s%d: pci_dma_win:bad dma type 0x%x",
ddi_driver_name(rdip), ddi_get_instance(rdip),
PCI_DMA_TYPE(mp));
return (DDI_FAILURE);
}
if (cookiep)
DEBUG2(DBG_DMA_WIN, dip,
"cookie - dmac_address=%x dmac_size=%x\n",
cookiep->dmac_address, cookiep->dmac_size);
if (offp)
*offp = (off_t)mp->dmai_offset;
if (lenp)
*lenp = mp->dmai_size;
return (DDI_SUCCESS);
}
#ifdef DEBUG
static char *pci_dmactl_str[] = {
"DDI_DMA_FREE",
"DDI_DMA_SYNC",
"DDI_DMA_HTOC",
"DDI_DMA_KVADDR",
"DDI_DMA_MOVWIN",
"DDI_DMA_REPWIN",
"DDI_DMA_GETERR",
"DDI_DMA_COFF",
"DDI_DMA_NEXTWIN",
"DDI_DMA_NEXTSEG",
"DDI_DMA_SEGTOC",
"DDI_DMA_RESERVE",
"DDI_DMA_RELEASE",
"DDI_DMA_RESETH",
"DDI_DMA_CKSYNC",
"DDI_DMA_IOPB_ALLOC",
"DDI_DMA_IOPB_FREE",
"DDI_DMA_SMEM_ALLOC",
"DDI_DMA_SMEM_FREE",
"DDI_DMA_SET_SBUS64",
"DDI_DMA_REMAP"
};
#endif
/*
* bus dma control entry point:
*/
int
pci_dma_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle,
enum ddi_dma_ctlops cmd, off_t *offp, size_t *lenp, caddr_t *objp,
uint_t cache_flags)
{
ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
DEBUG3(DBG_DMA_CTL, dip, "%s: rdip=%s%d\n", pci_dmactl_str[cmd],
ddi_driver_name(rdip), ddi_get_instance(rdip));
switch (cmd) {
case DDI_DMA_FREE:
(void) pci_dma_unbindhdl(dip, rdip, handle);
(void) pci_dma_freehdl(dip, rdip, handle);
return (DDI_SUCCESS);
case DDI_DMA_RESERVE: {
pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
return (pci_fdvma_reserve(dip, rdip, pci_p,
(ddi_dma_req_t *)offp, (ddi_dma_handle_t *)objp));
}
case DDI_DMA_RELEASE: {
pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
return (pci_fdvma_release(dip, pci_p, mp));
}
default:
break;
}
switch (PCI_DMA_TYPE(mp)) {
case DMAI_FLAGS_DVMA:
return (pci_dvma_ctl(dip, rdip, mp, cmd, offp, lenp, objp,
cache_flags));
case DMAI_FLAGS_PEER_TO_PEER:
case DMAI_FLAGS_BYPASS:
return (pci_dma_ctl(dip, rdip, mp, cmd, offp, lenp, objp,
cache_flags));
default:
panic("%s%d: pci_dma_ctlops(%x):bad dma type %x",
ddi_driver_name(rdip), ddi_get_instance(rdip), cmd,
mp->dmai_flags);
/*NOTREACHED*/
}
}
#ifdef DEBUG
int pci_peekfault_cnt = 0;
int pci_pokefault_cnt = 0;
#endif /* DEBUG */
static int
pci_do_poke(pci_t *pci_p, peekpoke_ctlops_t *in_args)
{
pbm_t *pbm_p = pci_p->pci_pbm_p;
int err = DDI_SUCCESS;
on_trap_data_t otd;
mutex_enter(&pbm_p->pbm_pokefault_mutex);
pbm_p->pbm_ontrap_data = &otd;
/* Set up protected environment. */
if (!on_trap(&otd, OT_DATA_ACCESS)) {
uintptr_t tramp = otd.ot_trampoline;
otd.ot_trampoline = (uintptr_t)&poke_fault;
err = do_poke(in_args->size, (void *)in_args->dev_addr,
(void *)in_args->host_addr);
otd.ot_trampoline = tramp;
} else
err = DDI_FAILURE;
/*
* Read the async fault register for the PBM to see it sees
* a master-abort.
*/
pbm_clear_error(pbm_p);
if (otd.ot_trap & OT_DATA_ACCESS)
err = DDI_FAILURE;
/* Take down protected environment. */
no_trap();
pbm_p->pbm_ontrap_data = NULL;
mutex_exit(&pbm_p->pbm_pokefault_mutex);
#ifdef DEBUG
if (err == DDI_FAILURE)
pci_pokefault_cnt++;
#endif
return (err);
}
static int
pci_do_caut_put(pci_t *pci_p, peekpoke_ctlops_t *cautacc_ctlops_arg)
{
size_t size = cautacc_ctlops_arg->size;
uintptr_t dev_addr = cautacc_ctlops_arg->dev_addr;
uintptr_t host_addr = cautacc_ctlops_arg->host_addr;
ddi_acc_impl_t *hp = (ddi_acc_impl_t *)cautacc_ctlops_arg->handle;
size_t repcount = cautacc_ctlops_arg->repcount;
uint_t flags = cautacc_ctlops_arg->flags;
hp->ahi_err->err_expected = DDI_FM_ERR_EXPECTED;
/*
* Note that i_ndi_busop_access_enter ends up grabbing the pokefault
* mutex.
*/
i_ndi_busop_access_enter(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp);
if (!i_ddi_ontrap((ddi_acc_handle_t)hp)) {
for (; repcount; repcount--) {
switch (size) {
case sizeof (uint8_t):
i_ddi_put8(hp, (uint8_t *)dev_addr,
*(uint8_t *)host_addr);
break;
case sizeof (uint16_t):
i_ddi_put16(hp, (uint16_t *)dev_addr,
*(uint16_t *)host_addr);
break;
case sizeof (uint32_t):
i_ddi_put32(hp, (uint32_t *)dev_addr,
*(uint32_t *)host_addr);
break;
case sizeof (uint64_t):
i_ddi_put64(hp, (uint64_t *)dev_addr,
*(uint64_t *)host_addr);
break;
}
host_addr += size;
if (flags == DDI_DEV_AUTOINCR)
dev_addr += size;
}
}
i_ddi_notrap((ddi_acc_handle_t)hp);
i_ndi_busop_access_exit(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp);
hp->ahi_err->err_expected = DDI_FM_ERR_UNEXPECTED;
if (hp->ahi_err->err_status != DDI_FM_OK) {
/* Clear the expected fault from the handle before returning */
hp->ahi_err->err_status = DDI_FM_OK;
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
pci_ctlops_poke(pci_t *pci_p, peekpoke_ctlops_t *in_args)
{
return (in_args->handle ? pci_do_caut_put(pci_p, in_args) :
pci_do_poke(pci_p, in_args));
}
static int
pci_do_peek(pci_t *pci_p, peekpoke_ctlops_t *in_args)
{
int err = DDI_SUCCESS;
on_trap_data_t otd;
if (!on_trap(&otd, OT_DATA_ACCESS)) {
uintptr_t tramp = otd.ot_trampoline;
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;
no_trap();
#ifdef DEBUG
if (err == DDI_FAILURE)
pci_peekfault_cnt++;
#endif
return (err);
}
static int
pci_do_caut_get(pci_t *pci_p, peekpoke_ctlops_t *cautacc_ctlops_arg)
{
size_t size = cautacc_ctlops_arg->size;
uintptr_t dev_addr = cautacc_ctlops_arg->dev_addr;
uintptr_t host_addr = cautacc_ctlops_arg->host_addr;
ddi_acc_impl_t *hp = (ddi_acc_impl_t *)cautacc_ctlops_arg->handle;
size_t repcount = cautacc_ctlops_arg->repcount;
uint_t flags = cautacc_ctlops_arg->flags;
int err = DDI_SUCCESS;
hp->ahi_err->err_expected = DDI_FM_ERR_EXPECTED;
i_ndi_busop_access_enter(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp);
if (!i_ddi_ontrap((ddi_acc_handle_t)hp)) {
for (; repcount; repcount--) {
i_ddi_caut_get(size, (void *)dev_addr,
(void *)host_addr);
host_addr += size;
if (flags == DDI_DEV_AUTOINCR)
dev_addr += size;
}
} else {
int i;
uint8_t *ff_addr = (uint8_t *)host_addr;
for (i = 0; i < size; i++)
*ff_addr++ = 0xff;
err = DDI_FAILURE;
}
i_ddi_notrap((ddi_acc_handle_t)hp);
i_ndi_busop_access_exit(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp);
hp->ahi_err->err_expected = DDI_FM_ERR_UNEXPECTED;
return (err);
}
static int
pci_ctlops_peek(pci_t *pci_p, peekpoke_ctlops_t *in_args, void *result)
{
result = (void *)in_args->host_addr;
return (in_args->handle ? pci_do_caut_get(pci_p, in_args) :
pci_do_peek(pci_p, in_args));
}
/*
* get_reg_set_size
*
* Given a dev info pointer to a pci child and a register number, this
* routine returns the size element of that reg set property.
* return value: size of reg set on success, -1 on error
*/
static off_t
get_reg_set_size(dev_info_t *child, int rnumber)
{
pci_regspec_t *pci_rp;
off_t size;
int i;
if (rnumber < 0)
return (-1);
/*
* Get the reg property for the device.
*/
if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg",
(caddr_t)&pci_rp, &i) != DDI_SUCCESS)
return (-1);
if (rnumber >= (i / (int)sizeof (pci_regspec_t))) {
kmem_free(pci_rp, i);
return (-1);
}
size = pci_rp[rnumber].pci_size_low |
((uint64_t)pci_rp[rnumber].pci_size_hi << 32);
kmem_free(pci_rp, i);
return (size);
}
/*
* control ops entry point:
*
* Requests handled completely:
* DDI_CTLOPS_INITCHILD see init_child() for details
* DDI_CTLOPS_UNINITCHILD
* DDI_CTLOPS_REPORTDEV see report_dev() for details
* DDI_CTLOPS_IOMIN cache line size if streaming otherwise 1
* DDI_CTLOPS_REGSIZE
* DDI_CTLOPS_NREGS
* DDI_CTLOPS_DVMAPAGESIZE
* DDI_CTLOPS_POKE
* DDI_CTLOPS_PEEK
* DDI_CTLOPS_QUIESCE
* DDI_CTLOPS_UNQUIESCE
*
* All others passed to parent.
*/
int
pci_ctlops(dev_info_t *dip, dev_info_t *rdip,
ddi_ctl_enum_t op, void *arg, void *result)
{
pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
switch (op) {
case DDI_CTLOPS_INITCHILD:
return (init_child(pci_p, (dev_info_t *)arg));
case DDI_CTLOPS_UNINITCHILD:
return (uninit_child(pci_p, (dev_info_t *)arg));
case DDI_CTLOPS_REPORTDEV:
return (report_dev(rdip));
case DDI_CTLOPS_IOMIN:
/*
* If we are using the streaming cache, align at
* least on a cache line boundary. Otherwise use
* whatever alignment is passed in.
*/
if ((uintptr_t)arg) {
int val = *((int *)result);
val = maxbit(val, PCI_SBUF_LINE_SIZE);
*((int *)result) = val;
}
return (DDI_SUCCESS);
case DDI_CTLOPS_REGSIZE:
*((off_t *)result) = get_reg_set_size(rdip, *((int *)arg));
return (*((off_t *)result) == -1 ? DDI_FAILURE : DDI_SUCCESS);
case DDI_CTLOPS_NREGS:
*((uint_t *)result) = get_nreg_set(rdip);
return (DDI_SUCCESS);
case DDI_CTLOPS_DVMAPAGESIZE:
*((ulong_t *)result) = IOMMU_PAGE_SIZE;
return (DDI_SUCCESS);
case DDI_CTLOPS_POKE:
return (pci_ctlops_poke(pci_p, (peekpoke_ctlops_t *)arg));
case DDI_CTLOPS_PEEK:
return (pci_ctlops_peek(pci_p, (peekpoke_ctlops_t *)arg,
result));
case DDI_CTLOPS_AFFINITY:
break;
case DDI_CTLOPS_QUIESCE:
return (pci_bus_quiesce(pci_p, rdip, result));
case DDI_CTLOPS_UNQUIESCE:
return (pci_bus_unquiesce(pci_p, rdip, result));
default:
break;
}
/*
* Now pass the request up to our parent.
*/
DEBUG2(DBG_CTLOPS, dip, "passing request to parent: rdip=%s%d\n",
ddi_driver_name(rdip), ddi_get_instance(rdip));
return (ddi_ctlops(dip, rdip, op, arg, result));
}
/* ARGSUSED */
int
pci_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
ddi_intr_handle_impl_t *hdlp, void *result)
{
pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
ib_ino_t ino;
int ret = DDI_SUCCESS;
switch (intr_op) {
case DDI_INTROP_GETCAP:
/* GetCap will always fail for all non PCI devices */
(void) pci_intx_get_cap(rdip, (int *)result);
break;
case DDI_INTROP_SETCAP:
ret = DDI_ENOTSUP;
break;
case DDI_INTROP_ALLOC:
*(int *)result = hdlp->ih_scratch1;
break;
case DDI_INTROP_FREE:
break;
case DDI_INTROP_GETPRI:
*(int *)result = hdlp->ih_pri ?
hdlp->ih_pri : pci_class_to_pil(rdip);
break;
case DDI_INTROP_SETPRI:
break;
case DDI_INTROP_ADDISR:
ret = pci_add_intr(dip, rdip, hdlp);
break;
case DDI_INTROP_REMISR:
ret = pci_remove_intr(dip, rdip, hdlp);
break;
case DDI_INTROP_GETTARGET:
ino = IB_MONDO_TO_INO(pci_xlate_intr(dip, rdip,
pci_p->pci_ib_p, IB_MONDO_TO_INO(hdlp->ih_vector)));
ret = ib_get_intr_target(pci_p, ino, (int *)result);
break;
case DDI_INTROP_SETTARGET:
ret = DDI_ENOTSUP;
break;
case DDI_INTROP_ENABLE:
ret = ib_update_intr_state(pci_p, rdip, hdlp,
PCI_INTR_STATE_ENABLE);
break;
case DDI_INTROP_DISABLE:
ret = ib_update_intr_state(pci_p, rdip, hdlp,
PCI_INTR_STATE_DISABLE);
break;
case DDI_INTROP_SETMASK:
ret = pci_intx_set_mask(rdip);
break;
case DDI_INTROP_CLRMASK:
ret = pci_intx_clr_mask(rdip);
break;
case DDI_INTROP_GETPENDING:
ret = pci_intx_get_pending(rdip, (int *)result);
break;
case DDI_INTROP_NINTRS:
case DDI_INTROP_NAVAIL:
*(int *)result = i_ddi_get_intx_nintrs(rdip);
break;
case DDI_INTROP_SUPPORTED_TYPES:
/* PCI nexus driver supports only fixed interrupts */
*(int *)result = i_ddi_get_intx_nintrs(rdip) ?
DDI_INTR_TYPE_FIXED : 0;
break;
default:
ret = DDI_ENOTSUP;
break;
}
return (ret);
}
static void
pci_init_hotplug(struct pci *pci_p)
{
pci_bus_range_t bus_range;
dev_info_t *dip;
/*
* Before initializing hotplug - open up
* bus range. The busra module will
* initialize its pool of bus numbers from
* this. "busra" will be the agent that keeps
* track of them during hotplug. Also, note,
* that busra will remove any bus numbers
* already in use from boot time.
*/
bus_range.lo = 0x0;
bus_range.hi = 0xff;
dip = pci_p->pci_dip;
pci_p->hotplug_capable = B_FALSE;
/*
* If this property exists, this nexus has hot-plug
* slots.
*/
if (ddi_prop_exists(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
"hotplug-capable")) {
if (ndi_prop_update_int_array(DDI_DEV_T_NONE,
dip, "bus-range",
(int *)&bus_range,
2) != DDI_PROP_SUCCESS) {
return;
}
if (pcihp_init(dip) != DDI_SUCCESS) {
return;
}
if ((pcihp_ops = pcihp_get_cb_ops()) != NULL) {
DEBUG2(DBG_ATTACH, dip, "%s%d hotplug enabled",
ddi_driver_name(dip), ddi_get_instance(dip));
pci_p->hotplug_capable = B_TRUE;
}
}
}
|