7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * CDDL HEADER START
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * The contents of this file are subject to the terms of the
d48713b83f032afcef6785303e68f293eacd5671esolom * Common Development and Distribution License (the "License").
d48713b83f032afcef6785303e68f293eacd5671esolom * You may not use this file except in compliance with the License.
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * See the License for the specific language governing permissions
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * and limitations under the License.
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * When distributing Covered Code, include this CDDL HEADER in each
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * If applicable, add the following below this CDDL HEADER, with the
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * fields enclosed by brackets "[]" replaced with your own identifying
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * information: Portions Copyright [yyyy] [name of copyright owner]
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * CDDL HEADER END
5cd376e8b7030707d78315f63adb4bb2b4d9963eJimmy Vetayases * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * Kstat support for X86 PCI driver
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartzstatic struct {
7ff178cd8db129d385d3177eb20744d3b6efc59bJimmy Vetayasesextern int (*psm_intr_ops)(dev_info_t *, ddi_intr_handle_impl_t *,
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz/*ARGSUSED*/
2917a9c9c3eee6fcaedb239f5f68da01f4ed0da9schwartz dev_info_t *rootnex_dip = private_data->rootnex_dip;
7ff178cd8db129d385d3177eb20744d3b6efc59bJimmy Vetayases ddi_intr_handle_impl_t tmp_hdl, *ih_p = private_data->hdlp;
2917a9c9c3eee6fcaedb239f5f68da01f4ed0da9schwartz int maxlen = sizeof (pci_ks_template.ihks_name.value.c);
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz (void) snprintf(pci_ks_template.ihks_name.value.c, maxlen, "%s%d",
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz kstat_named_setstr(&pci_ks_template.ihks_devpath, ih_devpath);
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz kstat_named_setstr(&pci_ks_template.ihks_buspath, ih_buspath);
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * Note that although possibly multiple vectors can map to an IRQ, the
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * vector returned below will always be the same for a given IRQ
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * specified, and so all kstats for a given IRQ will report the same
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * value for the ino field.
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * Check for the enabled state, since kstats are set up when the ISR is
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * added, not enabled. There may be a period where interrupts are not
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * enabled even though they may have been added.
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * It is also possible that the vector is for a dummy interrupt.
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * pci_get_intr_from_vecirq will return failure in this case.
7ff178cd8db129d385d3177eb20744d3b6efc59bJimmy Vetayases bcopy(ih_p, &tmp_hdl, sizeof (ddi_intr_handle_impl_t));
7ff178cd8db129d385d3177eb20744d3b6efc59bJimmy Vetayases intrinfo.avgi_cpu_id = 0; /* In case psm_intr_ops fails */
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz intrinfo.avgi_req_flags = PSMGI_REQ_CPUID | PSMGI_REQ_VECTOR;
7ff178cd8db129d385d3177eb20744d3b6efc59bJimmy Vetayases intrinfo.avgi_req_flags |= PSMGI_INTRBY_DEFAULT;
7ff178cd8db129d385d3177eb20744d3b6efc59bJimmy Vetayases ((*psm_intr_ops)(NULL, &tmp_hdl, PSM_INTR_OP_GET_INTR, NULL) !=
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz (void) strcpy(pci_ks_template.ihks_type.value.c, "disabled");
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz /* Interrupt is user-bound. Remove kstat. */
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz (void (*)(void *))pci_kstat_delete, ksp, TQ_SLEEP);
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz return (0);
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * Interrupt is valid (not a dummy), not user-bound to a specific cpu,
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * and enabled. Update kstat fields.
2917a9c9c3eee6fcaedb239f5f68da01f4ed0da9schwartz (void) strcpy(pci_ks_template.ihks_type.value.c, "msi");
2917a9c9c3eee6fcaedb239f5f68da01f4ed0da9schwartz (void) strcpy(pci_ks_template.ihks_type.value.c, "msix");
2917a9c9c3eee6fcaedb239f5f68da01f4ed0da9schwartz (void) strcpy(pci_ks_template.ihks_type.value.c, "fixed");
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz pci_ks_template.ihks_pil.value.ui64 = ih_p->ih_pri;
843e19887f64dde75055cf8842fc4db2171eff45johnlev scalehrtime((hrtime_t *)&pci_ks_template.ihks_time.value.ui64);
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz pci_ks_template.ihks_cookie.value.ui64 = ih_p->ih_vector;
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz /* CPU won't be user bound at this point. */
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz pci_ks_template.ihks_cpu.value.ui64 = intrinfo.avgi_cpu_id;
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz pci_ks_template.ihks_ino.value.ui64 = intrinfo.avgi_vector;
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz return (0);
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartzvoid pci_kstat_create(kstat_t **kspp, dev_info_t *rootnex_dip,
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz *kspp = kstat_create("pci_intrs", atomic_inc_32_nv(&pci_ks_inst),
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz kmem_zalloc(sizeof (pci_kstat_private_t), KM_SLEEP);
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * This function is invoked in two ways:
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * - Thru taskq thread via pci_ih_ks_update to remove kstats for user-bound
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * interrupts.
e1d9f4e6832768425b218c917c09c9afaed8ae36schwartz * - From the REMISR introp when an interrupt is being removed.
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * Delete the kstat before removing the private pointer, to
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz * prevent a kstat update from coming after private is freed.