4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved.
30 * PCI to PCI bus bridge nexus driver
35 #include <sys/debug.h>
36 #include <sys/modctl.h>
37 #include <sys/autoconf.h>
38 #include <sys/ddi_impldefs.h>
40 #include <sys/pci_impl.h>
41 #include <sys/pcie_impl.h>
43 #include <sys/sunddi.h>
44 #include <sys/sunndi.h>
45 #include <sys/ddifm.h>
46 #include <sys/ndifm.h>
47 #include <sys/fm/protocol.h>
48 #include <sys/hotplug/pci/pcie_hp.h>
49 #include <sys/hotplug/pci/pcihp.h>
50 #include <sys/pci_intr_lib.h>
52 #include <sys/pci_cap.h>
55 * The variable controls the default setting of the command register
56 * for pci devices. See ppb_initchild() for details.
58 static ushort_t ppb_command_default
= PCI_COMM_ME
| PCI_COMM_MAE
| PCI_COMM_IO
;
61 static int ppb_bus_map(dev_info_t
*, dev_info_t
*, ddi_map_req_t
*,
62 off_t
, off_t
, caddr_t
*);
63 static int ppb_ctlops(dev_info_t
*, dev_info_t
*, ddi_ctl_enum_t
,
65 static int ppb_fm_init(dev_info_t
*, dev_info_t
*, int,
66 ddi_iblock_cookie_t
*);
67 static int ppb_fm_callback(dev_info_t
*, ddi_fm_error_t
*, const void *);
68 static int ppb_intr_ops(dev_info_t
*, dev_info_t
*, ddi_intr_op_t
,
69 ddi_intr_handle_impl_t
*, void *);
72 * ppb_support_msi: Flag that controls MSI support across P2P Bridges.
73 * By default, MSI is not supported except for special cases like HT
74 * bridges/tunnels that have HT MSI mapping enabled.
76 * However, MSI support behavior can be patched on a system by changing
77 * the value of this flag as shown below:-
78 * 0 = default value, MSI is allowed by this driver for special cases
79 * 1 = MSI supported without any checks for this driver
80 * -1 = MSI not supported at all
82 int ppb_support_msi
= 0;
85 * Controls the usage of the Hypertransport MSI mapping capability
86 * 0 = default value, leave hardware function as it is
87 * 1 = always enable HT MSI mapping
88 * -1 = always disable HT MSI mapping
90 int ppb_support_ht_msimap
= 0;
92 struct bus_ops ppb_bus_ops
= {
109 0, /* (*bus_get_eventcookie)(); */
110 0, /* (*bus_add_eventcall)(); */
111 0, /* (*bus_remove_eventcall)(); */
112 0, /* (*bus_post_event)(); */
113 0, /* (*bus_intr_ctl)(); */
114 0, /* (*bus_config)(); */
115 0, /* (*bus_unconfig)(); */
116 ppb_fm_init
, /* (*bus_fm_init)(); */
117 NULL
, /* (*bus_fm_fini)(); */
118 NULL
, /* (*bus_fm_access_enter)(); */
119 NULL
, /* (*bus_fm_access_exit)(); */
120 NULL
, /* (*bus_power)(); */
121 ppb_intr_ops
, /* (*bus_intr_op)(); */
122 pcie_hp_common_ops
/* (*bus_hp_op)(); */
126 * The goal here is to leverage off of the pcihp.c source without making
127 * changes to it. Call into it's cb_ops directly if needed.
129 static int ppb_open(dev_t
*, int, int, cred_t
*);
130 static int ppb_close(dev_t
, int, int, cred_t
*);
131 static int ppb_ioctl(dev_t
, int, intptr_t, int, cred_t
*, int *);
132 static int ppb_prop_op(dev_t
, dev_info_t
*, ddi_prop_op_t
, int, char *,
134 static int ppb_info(dev_info_t
*, ddi_info_cmd_t
, void *, void **);
135 static void ppb_peekpoke_cb(dev_info_t
*, ddi_fm_error_t
*);
137 struct cb_ops ppb_cb_ops
= {
139 ppb_close
, /* close */
140 nodev
, /* strategy */
145 ppb_ioctl
, /* ioctl */
150 ppb_prop_op
, /* cb_prop_op */
151 NULL
, /* streamtab */
152 D_NEW
| D_MP
| D_HOTPLUG
, /* Driver compatibility flag */
154 nodev
, /* int (*cb_aread)() */
155 nodev
/* int (*cb_awrite)() */
159 static int ppb_probe(dev_info_t
*);
160 static int ppb_attach(dev_info_t
*devi
, ddi_attach_cmd_t cmd
);
161 static int ppb_detach(dev_info_t
*devi
, ddi_detach_cmd_t cmd
);
163 struct dev_ops ppb_ops
= {
164 DEVO_REV
, /* devo_rev */
167 nulldev
, /* identify */
168 ppb_probe
, /* probe */
169 ppb_attach
, /* attach */
170 ppb_detach
, /* detach */
172 &ppb_cb_ops
, /* driver operations */
173 &ppb_bus_ops
, /* bus operations */
175 ddi_quiesce_not_needed
, /* quiesce */
179 * Module linkage information for the kernel.
182 static struct modldrv modldrv
= {
183 &mod_driverops
, /* Type of module */
184 "Standard PCI to PCI bridge nexus driver",
185 &ppb_ops
, /* driver ops */
188 static struct modlinkage modlinkage
= {
195 * soft state pointer and structure template:
197 static void *ppb_state
;
202 ddi_iblock_cookie_t ppb_fm_ibc
;
204 kmutex_t ppb_peek_poke_mutex
;
205 kmutex_t ppb_err_mutex
;
210 uint_t config_state_index
;
214 uchar_t cache_line_size
;
215 uchar_t latency_timer
;
217 uchar_t sec_latency_timer
;
218 ushort_t bridge_control
;
219 } config_state
[PCI_MAX_CHILDREN
];
226 * forward function declarations:
228 static void ppb_removechild(dev_info_t
*);
229 static int ppb_initchild(dev_info_t
*child
);
230 static void ppb_save_config_regs(ppb_devstate_t
*ppb_p
);
231 static void ppb_restore_config_regs(ppb_devstate_t
*ppb_p
);
232 static boolean_t
ppb_ht_msimap_check(ddi_acc_handle_t cfg_hdl
);
233 static int ppb_ht_msimap_set(ddi_acc_handle_t cfg_hdl
, int cmd
);
236 * for <cmd> in ppb_ht_msimap_set
238 #define HT_MSIMAP_ENABLE 1
239 #define HT_MSIMAP_DISABLE 0
247 if ((e
= ddi_soft_state_init(&ppb_state
, sizeof (ppb_devstate_t
),
248 1)) == 0 && (e
= mod_install(&modlinkage
)) != 0)
249 ddi_soft_state_fini(&ppb_state
);
258 if ((e
= mod_remove(&modlinkage
)) == 0)
259 ddi_soft_state_fini(&ppb_state
);
264 _info(struct modinfo
*modinfop
)
266 return (mod_info(&modlinkage
, modinfop
));
271 ppb_probe(dev_info_t
*devi
)
273 return (DDI_PROBE_SUCCESS
);
278 ppb_attach(dev_info_t
*devi
, ddi_attach_cmd_t cmd
)
280 dev_info_t
*root
= ddi_root_node();
284 ddi_acc_handle_t config_handle
;
292 * Make sure the "device_type" property exists.
294 (void) ddi_prop_update_string(DDI_DEV_T_NONE
, devi
,
295 "device_type", "pci");
298 * Allocate and get soft state structure.
300 instance
= ddi_get_instance(devi
);
301 if (ddi_soft_state_zalloc(ppb_state
, instance
) != DDI_SUCCESS
)
302 return (DDI_FAILURE
);
303 ppb
= ddi_get_soft_state(ppb_state
, instance
);
307 * don't enable ereports if immediate child of npe
309 if (strcmp(ddi_driver_name(ddi_get_parent(devi
)), "npe") == 0)
310 ppb
->ppb_fmcap
= DDI_FM_ERRCB_CAPABLE
|
311 DDI_FM_ACCCHK_CAPABLE
| DDI_FM_DMACHK_CAPABLE
;
313 ppb
->ppb_fmcap
= DDI_FM_EREPORT_CAPABLE
|
314 DDI_FM_ERRCB_CAPABLE
| DDI_FM_ACCCHK_CAPABLE
|
315 DDI_FM_DMACHK_CAPABLE
;
317 ddi_fm_init(devi
, &ppb
->ppb_fmcap
, &ppb
->ppb_fm_ibc
);
318 mutex_init(&ppb
->ppb_mutex
, NULL
, MUTEX_DRIVER
, NULL
);
319 mutex_init(&ppb
->ppb_err_mutex
, NULL
, MUTEX_DRIVER
,
320 (void *)ppb
->ppb_fm_ibc
);
321 mutex_init(&ppb
->ppb_peek_poke_mutex
, NULL
, MUTEX_DRIVER
,
322 (void *)ppb
->ppb_fm_ibc
);
324 if (ppb
->ppb_fmcap
& (DDI_FM_ERRCB_CAPABLE
|
325 DDI_FM_EREPORT_CAPABLE
))
326 pci_ereport_setup(devi
);
327 if (ppb
->ppb_fmcap
& DDI_FM_ERRCB_CAPABLE
)
328 ddi_fm_handler_register(devi
, ppb_fm_callback
, NULL
);
330 if (pci_config_setup(devi
, &config_handle
) != DDI_SUCCESS
) {
331 if (ppb
->ppb_fmcap
& DDI_FM_ERRCB_CAPABLE
)
332 ddi_fm_handler_unregister(devi
);
333 if (ppb
->ppb_fmcap
& (DDI_FM_ERRCB_CAPABLE
|
334 DDI_FM_EREPORT_CAPABLE
))
335 pci_ereport_teardown(devi
);
337 ddi_soft_state_free(ppb_state
, instance
);
338 return (DDI_FAILURE
);
341 ppb
->parent_bus
= PCIE_PCIECAP_DEV_TYPE_PCI_PSEUDO
;
342 for (pdip
= ddi_get_parent(devi
); pdip
&& (pdip
!= root
) &&
343 (ppb
->parent_bus
!= PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
);
344 pdip
= ddi_get_parent(pdip
)) {
345 if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, pdip
,
346 DDI_PROP_DONTPASS
, "device_type", &bus
) !=
350 if (strcmp(bus
, "pciex") == 0)
352 PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
;
357 if (ppb_support_ht_msimap
== 1)
358 (void) ppb_ht_msimap_set(config_handle
,
360 else if (ppb_support_ht_msimap
== -1)
361 (void) ppb_ht_msimap_set(config_handle
,
364 pci_config_teardown(&config_handle
);
367 * Initialize hotplug support on this bus.
369 if (ppb
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
)
370 ret
= pcie_init(devi
, NULL
);
372 ret
= pcihp_init(devi
);
374 if (ret
!= DDI_SUCCESS
) {
376 "pci: Failed to setup hotplug framework");
377 (void) ppb_detach(devi
, DDI_DETACH
);
381 ddi_report_dev(devi
);
382 return (DDI_SUCCESS
);
387 * Get the soft state structure for the bridge.
389 ppb
= ddi_get_soft_state(ppb_state
, ddi_get_instance(devi
));
390 ppb_restore_config_regs(ppb
);
391 return (DDI_SUCCESS
);
396 return (DDI_FAILURE
);
401 ppb_detach(dev_info_t
*devi
, ddi_detach_cmd_t cmd
)
408 (void) ddi_prop_remove(DDI_DEV_T_NONE
, devi
, "device_type");
410 ppb
= ddi_get_soft_state(ppb_state
, ddi_get_instance(devi
));
411 if (ppb
->ppb_fmcap
& DDI_FM_ERRCB_CAPABLE
)
412 ddi_fm_handler_unregister(devi
);
413 if (ppb
->ppb_fmcap
& (DDI_FM_ERRCB_CAPABLE
|
414 DDI_FM_EREPORT_CAPABLE
))
415 pci_ereport_teardown(devi
);
418 * Uninitialize hotplug support on this bus.
420 ret
= (ppb
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
) ?
421 pcie_uninit(devi
) : pcihp_uninit(devi
);
422 if (ret
!= DDI_SUCCESS
)
423 return (DDI_FAILURE
);
425 mutex_destroy(&ppb
->ppb_peek_poke_mutex
);
426 mutex_destroy(&ppb
->ppb_err_mutex
);
427 mutex_destroy(&ppb
->ppb_mutex
);
431 * And finally free the per-pci soft state.
433 ddi_soft_state_free(ppb_state
, ddi_get_instance(devi
));
435 return (DDI_SUCCESS
);
438 ppb
= ddi_get_soft_state(ppb_state
, ddi_get_instance(devi
));
439 ppb_save_config_regs(ppb
);
440 return (DDI_SUCCESS
);
445 return (DDI_FAILURE
);
450 ppb_bus_map(dev_info_t
*dip
, dev_info_t
*rdip
, ddi_map_req_t
*mp
,
451 off_t offset
, off_t len
, caddr_t
*vaddrp
)
454 ppb_devstate_t
*ppb
= ddi_get_soft_state(ppb_state
,
455 ddi_get_instance(dip
));
457 if (strcmp(ddi_driver_name(ddi_get_parent(dip
)), "npe") == 0 &&
458 mp
->map_handlep
!= NULL
) {
459 ddi_acc_impl_t
*hdlp
=
460 (ddi_acc_impl_t
*)(mp
->map_handlep
)->ah_platform_private
;
461 hdlp
->ahi_err_mutexp
= &ppb
->ppb_err_mutex
;
462 hdlp
->ahi_peekpoke_mutexp
= &ppb
->ppb_peek_poke_mutex
;
463 hdlp
->ahi_scan_dip
= dip
;
464 hdlp
->ahi_scan
= ppb_peekpoke_cb
;
466 pdip
= (dev_info_t
*)DEVI(dip
)->devi_parent
;
467 return ((DEVI(pdip
)->devi_ops
->devo_bus_ops
->bus_map
)(pdip
,
468 rdip
, mp
, offset
, len
, vaddrp
));
473 ppb_ctlops(dev_info_t
*dip
, dev_info_t
*rdip
,
474 ddi_ctl_enum_t ctlop
, void *arg
, void *result
)
476 pci_regspec_t
*drv_regp
;
480 ppb_devstate_t
*ppb
= ddi_get_soft_state(ppb_state
,
481 ddi_get_instance(dip
));
482 struct detachspec
*dsp
;
483 struct attachspec
*asp
;
486 case DDI_CTLOPS_REPORTDEV
:
487 if (rdip
== (dev_info_t
*)0)
488 return (DDI_FAILURE
);
489 cmn_err(CE_CONT
, "?PCI-device: %s@%s, %s%d\n",
490 ddi_node_name(rdip
), ddi_get_name_addr(rdip
),
491 ddi_driver_name(rdip
),
492 ddi_get_instance(rdip
));
493 return (DDI_SUCCESS
);
495 case DDI_CTLOPS_INITCHILD
:
496 return (ppb_initchild((dev_info_t
*)arg
));
498 case DDI_CTLOPS_UNINITCHILD
:
499 ppb_removechild((dev_info_t
*)arg
);
500 return (DDI_SUCCESS
);
502 case DDI_CTLOPS_SIDDEV
:
503 return (DDI_SUCCESS
);
505 case DDI_CTLOPS_REGSIZE
:
506 case DDI_CTLOPS_NREGS
:
507 if (rdip
== (dev_info_t
*)0)
508 return (DDI_FAILURE
);
511 /* X86 systems support PME wakeup from suspend */
512 case DDI_CTLOPS_ATTACH
:
513 if (!pcie_is_child(dip
, rdip
))
514 return (DDI_SUCCESS
);
516 asp
= (struct attachspec
*)arg
;
517 if ((ppb
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
) &&
518 (asp
->when
== DDI_POST
) && (asp
->result
== DDI_SUCCESS
))
519 pf_init(rdip
, (void *)ppb
->ppb_fm_ibc
, asp
->cmd
);
521 if (asp
->cmd
== DDI_RESUME
&& asp
->when
== DDI_PRE
)
522 if (pci_pre_resume(rdip
) != DDI_SUCCESS
)
523 return (DDI_FAILURE
);
525 return (DDI_SUCCESS
);
527 case DDI_CTLOPS_DETACH
:
528 if (!pcie_is_child(dip
, rdip
))
529 return (DDI_SUCCESS
);
531 dsp
= (struct detachspec
*)arg
;
532 if ((ppb
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
) &&
533 (dsp
->when
== DDI_PRE
))
534 pf_fini(rdip
, dsp
->cmd
);
536 if (dsp
->cmd
== DDI_SUSPEND
&& dsp
->when
== DDI_POST
)
537 if (pci_post_suspend(rdip
) != DDI_SUCCESS
)
538 return (DDI_FAILURE
);
540 return (DDI_SUCCESS
);
542 case DDI_CTLOPS_PEEK
:
543 case DDI_CTLOPS_POKE
:
544 if (strcmp(ddi_driver_name(ddi_get_parent(dip
)), "npe") != 0)
545 return (ddi_ctlops(dip
, rdip
, ctlop
, arg
, result
));
546 return (pci_peekpoke_check(dip
, rdip
, ctlop
, arg
, result
,
547 ddi_ctlops
, &ppb
->ppb_err_mutex
,
548 &ppb
->ppb_peek_poke_mutex
, ppb_peekpoke_cb
));
551 return (ddi_ctlops(dip
, rdip
, ctlop
, arg
, result
));
555 if (ddi_getlongprop(DDI_DEV_T_ANY
, rdip
,
556 DDI_PROP_DONTPASS
| DDI_PROP_CANSLEEP
, "reg",
557 (caddr_t
)&drv_regp
, ®len
) != DDI_SUCCESS
)
558 return (DDI_FAILURE
);
560 totreg
= reglen
/ sizeof (pci_regspec_t
);
561 if (ctlop
== DDI_CTLOPS_NREGS
)
562 *(int *)result
= totreg
;
563 else if (ctlop
== DDI_CTLOPS_REGSIZE
) {
566 kmem_free(drv_regp
, reglen
);
567 return (DDI_FAILURE
);
569 *(off_t
*)result
= drv_regp
[rn
].pci_size_low
;
572 kmem_free(drv_regp
, reglen
);
573 return (DDI_SUCCESS
);
577 ppb_name_child(dev_info_t
*child
, char *name
, int namelen
)
579 pci_regspec_t
*pci_rp
;
585 * For .conf nodes, use unit-address property as name
587 if (ndi_dev_is_persistent_node(child
) == 0) {
588 if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY
, child
,
589 DDI_PROP_DONTPASS
, "unit-address", &unit_addr
, &n
) !=
592 "cannot find unit-address in %s.conf",
593 ddi_driver_name(child
));
594 return (DDI_FAILURE
);
596 if (n
!= 1 || *unit_addr
== NULL
|| **unit_addr
== 0) {
597 cmn_err(CE_WARN
, "unit-address property in %s.conf"
598 " not well-formed", ddi_driver_name(child
));
599 ddi_prop_free(unit_addr
);
600 return (DDI_SUCCESS
);
602 (void) snprintf(name
, namelen
, "%s", *unit_addr
);
603 ddi_prop_free(unit_addr
);
604 return (DDI_SUCCESS
);
607 /* get child "reg" property */
608 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY
, child
,
609 DDI_PROP_DONTPASS
, "reg", (int **)&pci_rp
, &n
) != DDI_SUCCESS
) {
610 return (DDI_FAILURE
);
613 /* copy the device identifications */
614 slot
= PCI_REG_DEV_G(pci_rp
->pci_phys_hi
);
615 func
= PCI_REG_FUNC_G(pci_rp
->pci_phys_hi
);
618 (void) snprintf(name
, namelen
, "%x,%x", slot
, func
);
620 (void) snprintf(name
, namelen
, "%x", slot
);
622 ddi_prop_free(pci_rp
);
623 return (DDI_SUCCESS
);
627 ppb_initchild(dev_info_t
*child
)
629 struct ddi_parent_private_data
*pdptr
;
631 char name
[MAXNAMELEN
];
632 ddi_acc_handle_t config_handle
;
633 ushort_t command_preserve
, command
;
635 ppb
= (ppb_devstate_t
*)ddi_get_soft_state(ppb_state
,
636 ddi_get_instance(ddi_get_parent(child
)));
638 if (ppb_name_child(child
, name
, MAXNAMELEN
) != DDI_SUCCESS
)
639 return (DDI_FAILURE
);
640 ddi_set_name_addr(child
, name
);
643 * Pseudo nodes indicate a prototype node with per-instance
644 * properties to be merged into the real h/w device node.
645 * The interpretation of the unit-address is DD[,F]
646 * where DD is the device id and F is the function.
648 if (ndi_dev_is_persistent_node(child
) == 0) {
649 extern int pci_allow_pseudo_children
;
651 ddi_set_parent_data(child
, NULL
);
654 * Try to merge the properties from this prototype
655 * node into real h/w nodes.
657 if (ndi_merge_node(child
, ppb_name_child
) == DDI_SUCCESS
) {
659 * Merged ok - return failure to remove the node.
661 ddi_set_name_addr(child
, NULL
);
662 return (DDI_FAILURE
);
665 /* workaround for ddivs to run under PCI */
666 if (pci_allow_pseudo_children
)
667 return (DDI_SUCCESS
);
670 * The child was not merged into a h/w node,
671 * but there's not much we can do with it other
672 * than return failure to cause the node to be removed.
674 cmn_err(CE_WARN
, "!%s@%s: %s.conf properties not merged",
675 ddi_driver_name(child
), ddi_get_name_addr(child
),
676 ddi_driver_name(child
));
677 ddi_set_name_addr(child
, NULL
);
678 return (DDI_NOT_WELL_FORMED
);
681 ddi_set_parent_data(child
, NULL
);
686 * Note: parent_data for parent is created only if this is PCI-E
687 * platform, for which, SG take a different route to handle device
690 if (ppb
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
) {
691 if (pcie_init_cfghdl(child
) != DDI_SUCCESS
)
692 return (DDI_FAILURE
);
693 pcie_init_dom(child
);
696 /* transfer select properties from PROM to kernel */
697 if (ddi_getprop(DDI_DEV_T_NONE
, child
, DDI_PROP_DONTPASS
,
698 "interrupts", -1) != -1) {
699 pdptr
= kmem_zalloc((sizeof (struct ddi_parent_private_data
) +
700 sizeof (struct intrspec
)), KM_SLEEP
);
701 pdptr
->par_intr
= (struct intrspec
*)(pdptr
+ 1);
702 pdptr
->par_nintr
= 1;
703 ddi_set_parent_data(child
, pdptr
);
705 ddi_set_parent_data(child
, NULL
);
707 if (pci_config_setup(child
, &config_handle
) != DDI_SUCCESS
) {
708 pcie_fini_dom(child
);
709 return (DDI_FAILURE
);
713 * Support for the "command-preserve" property.
715 command_preserve
= ddi_prop_get_int(DDI_DEV_T_ANY
, child
,
716 DDI_PROP_DONTPASS
, "command-preserve", 0);
717 command
= pci_config_get16(config_handle
, PCI_CONF_COMM
);
718 command
&= (command_preserve
| PCI_COMM_BACK2BACK_ENAB
);
719 command
|= (ppb_command_default
& ~command_preserve
);
720 pci_config_put16(config_handle
, PCI_CONF_COMM
, command
);
722 pci_config_teardown(&config_handle
);
723 return (DDI_SUCCESS
);
727 ppb_removechild(dev_info_t
*dip
)
729 struct ddi_parent_private_data
*pdptr
;
732 ppb
= (ppb_devstate_t
*)ddi_get_soft_state(ppb_state
,
733 ddi_get_instance(ddi_get_parent(dip
)));
735 if (ppb
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
) {
737 pcie_fini_cfghdl(dip
);
738 } else if ((pdptr
= ddi_get_parent_data(dip
)) != NULL
) {
739 kmem_free(pdptr
, (sizeof (*pdptr
) + sizeof (struct intrspec
)));
740 ddi_set_parent_data(dip
, NULL
);
742 ddi_set_name_addr(dip
, NULL
);
745 * Strip the node to properly convert it back to prototype form
747 ddi_remove_minor_node(dip
, NULL
);
749 impl_rem_dev_props(dip
);
753 * ppb_save_config_regs
755 * This routine saves the state of the configuration registers of all
756 * the child nodes of each PBM.
758 * used by: ppb_detach() on suspends
763 ppb_save_config_regs(ppb_devstate_t
*ppb_p
)
767 ddi_acc_handle_t config_handle
;
769 for (i
= 0, dip
= ddi_get_child(ppb_p
->dip
); dip
!= NULL
;
770 i
++, dip
= ddi_get_next_sibling(dip
)) {
772 if (pci_config_setup(dip
, &config_handle
) != DDI_SUCCESS
) {
773 cmn_err(CE_WARN
, "%s%d: can't config space for %s%d\n",
774 ddi_driver_name(ppb_p
->dip
),
775 ddi_get_instance(ppb_p
->dip
),
776 ddi_driver_name(dip
),
777 ddi_get_instance(dip
));
781 ppb_p
->config_state
[i
].dip
= dip
;
782 ppb_p
->config_state
[i
].command
=
783 pci_config_get16(config_handle
, PCI_CONF_COMM
);
784 pci_config_teardown(&config_handle
);
786 ppb_p
->config_state_index
= i
;
791 * ppb_restore_config_regs
793 * This routine restores the state of the configuration registers of all
794 * the child nodes of each PBM.
796 * used by: ppb_attach() on resume
801 ppb_restore_config_regs(ppb_devstate_t
*ppb_p
)
805 ddi_acc_handle_t config_handle
;
807 for (i
= 0; i
< ppb_p
->config_state_index
; i
++) {
808 dip
= ppb_p
->config_state
[i
].dip
;
809 if (pci_config_setup(dip
, &config_handle
) != DDI_SUCCESS
) {
810 cmn_err(CE_WARN
, "%s%d: can't config space for %s%d\n",
811 ddi_driver_name(ppb_p
->dip
),
812 ddi_get_instance(ppb_p
->dip
),
813 ddi_driver_name(dip
),
814 ddi_get_instance(dip
));
817 pci_config_put16(config_handle
, PCI_CONF_COMM
,
818 ppb_p
->config_state
[i
].command
);
819 pci_config_teardown(&config_handle
);
825 ppb_ht_msimap_check(ddi_acc_handle_t cfg_hdl
)
829 if (pci_htcap_locate(cfg_hdl
,
830 PCI_HTCAP_TYPE_MASK
| PCI_HTCAP_MSIMAP_ENABLE_MASK
,
831 PCI_HTCAP_MSIMAP_TYPE
| PCI_HTCAP_MSIMAP_ENABLE
, &ptr
) !=
840 ppb_ht_msimap_set(ddi_acc_handle_t cfg_hdl
, int cmd
)
845 if (pci_htcap_locate(cfg_hdl
, PCI_HTCAP_TYPE_MASK
,
846 PCI_HTCAP_MSIMAP_TYPE
, &ptr
) != DDI_SUCCESS
)
849 reg
= pci_config_get16(cfg_hdl
, ptr
+ PCI_CAP_ID_REGS_OFF
);
851 case HT_MSIMAP_ENABLE
:
852 reg
|= PCI_HTCAP_MSIMAP_ENABLE
;
854 case HT_MSIMAP_DISABLE
:
856 reg
&= ~(uint16_t)PCI_HTCAP_MSIMAP_ENABLE
;
859 pci_config_put16(cfg_hdl
, ptr
+ PCI_CAP_ID_REGS_OFF
, reg
);
865 * intercept certain interrupt services to handle special cases
868 ppb_intr_ops(dev_info_t
*pdip
, dev_info_t
*rdip
, ddi_intr_op_t intr_op
,
869 ddi_intr_handle_impl_t
*hdlp
, void *result
)
871 ddi_acc_handle_t cfg_hdl
;
872 int rv
= DDI_SUCCESS
;
874 if (intr_op
!= DDI_INTROP_SUPPORTED_TYPES
)
875 return (i_ddi_intr_ops(pdip
, rdip
, intr_op
, hdlp
, result
));
877 DDI_INTR_NEXDBG((CE_CONT
,
878 "ppb_intr_ops: pdip 0x%p, rdip 0x%p, op %x handle 0x%p\n",
879 (void *)pdip
, (void *)rdip
, intr_op
, (void *)hdlp
));
881 /* Fixed interrupt is supported by default */
882 *(int *)result
= DDI_INTR_TYPE_FIXED
;
884 if (ppb_support_msi
== -1) {
885 DDI_INTR_NEXDBG((CE_CONT
,
886 "ppb_intr_ops: MSI is not allowed\n"));
890 if (ppb_support_msi
== 1) {
891 DDI_INTR_NEXDBG((CE_CONT
,
892 "ppb_intr_ops: MSI is always allowed\n"));
893 rv
= i_ddi_intr_ops(pdip
, rdip
, intr_op
, hdlp
, result
);
897 if (pci_config_setup(pdip
, &cfg_hdl
) != DDI_SUCCESS
) {
898 DDI_INTR_NEXDBG((CE_CONT
,
899 "ppb_intr_ops: pci_config_setup() failed\n"));
904 * check for hypertransport msi mapping capability
906 if (ppb_ht_msimap_check(cfg_hdl
)) {
907 DDI_INTR_NEXDBG((CE_CONT
,
908 "ppb_intr_ops: HT MSI mapping enabled\n"));
909 rv
= i_ddi_intr_ops(pdip
, rdip
, intr_op
, hdlp
, result
);
913 * if we add failure conditions after pci_config_setup, move this to
914 * OUT and use an extra flag to indicate the need to teardown cfg_hdl
916 pci_config_teardown(&cfg_hdl
);
919 DDI_INTR_NEXDBG((CE_CONT
,
920 "ppb_intr_ops: rdip 0x%p, returns supported types: 0x%x\n",
921 (void *)rdip
, *(int *)result
));
927 ppb_open(dev_t
*devp
, int flags
, int otyp
, cred_t
*credp
)
929 int instance
= PCI_MINOR_NUM_TO_INSTANCE(getminor(*devp
));
930 ppb_devstate_t
*ppb_p
= ddi_get_soft_state(ppb_state
, instance
);
937 * Ioctls will be handled by PCI Express framework for all
940 if (ppb_p
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
) {
941 mutex_enter(&ppb_p
->ppb_mutex
);
942 rv
= pcie_open(ppb_p
->dip
, devp
, flags
, otyp
, credp
);
943 mutex_exit(&ppb_p
->ppb_mutex
);
947 return ((pcihp_get_cb_ops())->cb_open(devp
, flags
, otyp
, credp
));
952 ppb_close(dev_t dev
, int flags
, int otyp
, cred_t
*credp
)
954 int instance
= PCI_MINOR_NUM_TO_INSTANCE(getminor(dev
));
955 ppb_devstate_t
*ppb_p
= ddi_get_soft_state(ppb_state
, instance
);
961 mutex_enter(&ppb_p
->ppb_mutex
);
963 * Ioctls will be handled by PCI Express framework for all
966 if (ppb_p
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
) {
967 rv
= pcie_close(ppb_p
->dip
, dev
, flags
, otyp
, credp
);
968 mutex_exit(&ppb_p
->ppb_mutex
);
972 mutex_exit(&ppb_p
->ppb_mutex
);
973 return ((pcihp_get_cb_ops())->cb_close(dev
, flags
, otyp
, credp
));
977 * ppb_ioctl: devctl hotplug controls
981 ppb_ioctl(dev_t dev
, int cmd
, intptr_t arg
, int mode
, cred_t
*credp
,
984 int instance
= PCI_MINOR_NUM_TO_INSTANCE(getminor(dev
));
985 ppb_devstate_t
*ppb_p
= ddi_get_soft_state(ppb_state
, instance
);
991 * Ioctls will be handled by PCI Express framework for all
994 if (ppb_p
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
)
995 return (pcie_ioctl(ppb_p
->dip
, dev
, cmd
, arg
, mode
, credp
,
998 return ((pcihp_get_cb_ops())->cb_ioctl(dev
, cmd
, arg
, mode
, credp
,
1003 ppb_prop_op(dev_t dev
, dev_info_t
*dip
, ddi_prop_op_t prop_op
, int flags
,
1004 char *name
, caddr_t valuep
, int *lengthp
)
1006 int instance
= PCI_MINOR_NUM_TO_INSTANCE(getminor(dev
));
1007 ppb_devstate_t
*ppb_p
= ddi_get_soft_state(ppb_state
, instance
);
1012 if (ppb_p
->parent_bus
== PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
)
1013 return (pcie_prop_op(dev
, dip
, prop_op
, flags
, name
,
1016 return ((pcihp_get_cb_ops())->cb_prop_op(dev
, dip
, prop_op
, flags
,
1017 name
, valuep
, lengthp
));
1021 ppb_info(dev_info_t
*dip
, ddi_info_cmd_t cmd
, void *arg
, void **result
)
1023 minor_t minor
= getminor((dev_t
)arg
);
1024 int instance
= PCI_MINOR_NUM_TO_INSTANCE(minor
);
1025 ppb_devstate_t
*ppb_p
= ddi_get_soft_state(ppb_state
, instance
);
1028 return (DDI_FAILURE
);
1030 if (ppb_p
->parent_bus
!= PCIE_PCIECAP_DEV_TYPE_PCIE_DEV
)
1031 return (pcihp_info(dip
, cmd
, arg
, result
));
1035 return (DDI_FAILURE
);
1037 case DDI_INFO_DEVT2INSTANCE
:
1038 *result
= (void *)(uintptr_t)instance
;
1039 return (DDI_SUCCESS
);
1041 case DDI_INFO_DEVT2DEVINFO
:
1043 return (DDI_FAILURE
);
1044 *result
= (void *)ppb_p
->dip
;
1045 return (DDI_SUCCESS
);
1049 void ppb_peekpoke_cb(dev_info_t
*dip
, ddi_fm_error_t
*derr
) {
1050 (void) pci_ereport_post(dip
, derr
, NULL
);
1055 ppb_fm_init(dev_info_t
*dip
, dev_info_t
*tdip
, int cap
,
1056 ddi_iblock_cookie_t
*ibc
)
1058 ppb_devstate_t
*ppb
= ddi_get_soft_state(ppb_state
,
1059 ddi_get_instance(dip
));
1061 ASSERT(ibc
!= NULL
);
1062 *ibc
= ppb
->ppb_fm_ibc
;
1064 return (ppb
->ppb_fmcap
);
1069 ppb_fm_callback(dev_info_t
*dip
, ddi_fm_error_t
*derr
, const void *no_used
)
1071 ppb_devstate_t
*ppb
= ddi_get_soft_state(ppb_state
,
1072 ddi_get_instance(dip
));
1074 mutex_enter(&ppb
->ppb_err_mutex
);
1075 pci_ereport_post(dip
, derr
, NULL
);
1076 mutex_exit(&ppb
->ppb_err_mutex
);
1077 return (derr
->fme_status
);