2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/interrupt.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
41 #include <sys/malloc.h>
44 #include <sys/pmckern.h>
46 #include <machine/bus.h>
47 #include <machine/intr_machdep.h>
49 #include <contrib/octeon-sdk/cvmx.h>
50 #include <mips/cavium/octeon_irq.h>
52 struct octeon_pmc_softc {
54 struct resource *octeon_pmc_irq;
57 static void octeon_pmc_identify(driver_t *, device_t);
58 static int octeon_pmc_probe(device_t);
59 static int octeon_pmc_attach(device_t);
60 static int octeon_pmc_intr(void *);
63 octeon_pmc_identify(driver_t *drv, device_t parent)
65 if (octeon_has_feature(OCTEON_FEATURE_USB))
66 BUS_ADD_CHILD(parent, 0, "pmc", 0);
70 octeon_pmc_probe(device_t dev)
72 if (device_get_unit(dev) != 0)
75 device_set_desc(dev, "Cavium Octeon Performance Counters");
76 return (BUS_PROBE_NOWILDCARD);
80 octeon_pmc_attach(device_t dev)
82 struct octeon_pmc_softc *sc;
86 sc = device_get_softc(dev);
89 sc->octeon_pmc_irq = bus_alloc_resource(dev,
90 SYS_RES_IRQ, &rid, OCTEON_PMC_IRQ,
91 OCTEON_PMC_IRQ, 1, RF_ACTIVE);
93 if (sc->octeon_pmc_irq == NULL) {
94 device_printf(dev, "could not allocate irq%d\n", OCTEON_PMC_IRQ);
98 error = bus_setup_intr(dev, sc->octeon_pmc_irq,
99 INTR_TYPE_MISC, octeon_pmc_intr, NULL, sc, NULL);
101 device_printf(dev, "bus_setup_intr failed: %d\n", error);
109 octeon_pmc_intr(void *arg)
111 struct trapframe *tf = PCPU_GET(curthread)->td_intr_frame;
116 return (FILTER_HANDLED);
119 static device_method_t octeon_pmc_methods[] = {
120 DEVMETHOD(device_identify, octeon_pmc_identify),
121 DEVMETHOD(device_probe, octeon_pmc_probe),
122 DEVMETHOD(device_attach, octeon_pmc_attach),
126 static driver_t octeon_pmc_driver = {
129 sizeof(struct octeon_pmc_softc),
131 static devclass_t octeon_pmc_devclass;
132 DRIVER_MODULE(octeon_pmc, nexus, octeon_pmc_driver, octeon_pmc_devclass, 0, 0);