2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/interrupt.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
39 #include <sys/malloc.h>
42 #include <sys/pmckern.h>
44 #include <machine/bus.h>
45 #include <machine/intr_machdep.h>
47 #include <contrib/octeon-sdk/cvmx.h>
48 #include <mips/cavium/octeon_irq.h>
50 struct octeon_pmc_softc {
52 struct resource *octeon_pmc_irq;
55 static void octeon_pmc_identify(driver_t *, device_t);
56 static int octeon_pmc_probe(device_t);
57 static int octeon_pmc_attach(device_t);
58 static int octeon_pmc_intr(void *);
61 octeon_pmc_identify(driver_t *drv, device_t parent)
63 if (octeon_has_feature(OCTEON_FEATURE_USB))
64 BUS_ADD_CHILD(parent, 0, "pmc", 0);
68 octeon_pmc_probe(device_t dev)
70 if (device_get_unit(dev) != 0)
73 device_set_desc(dev, "Cavium Octeon Performance Counters");
78 octeon_pmc_attach(device_t dev)
80 struct octeon_pmc_softc *sc;
84 sc = device_get_softc(dev);
87 sc->octeon_pmc_irq = bus_alloc_resource(dev,
88 SYS_RES_IRQ, &rid, OCTEON_PMC_IRQ,
89 OCTEON_PMC_IRQ, 1, RF_ACTIVE);
91 if (sc->octeon_pmc_irq == NULL) {
92 device_printf(dev, "could not allocate irq%d\n", OCTEON_PMC_IRQ);
96 error = bus_setup_intr(dev, sc->octeon_pmc_irq,
97 INTR_TYPE_MISC, octeon_pmc_intr, NULL, sc, NULL);
99 device_printf(dev, "bus_setup_intr failed: %d\n", error);
107 octeon_pmc_intr(void *arg)
109 struct trapframe *tf = PCPU_GET(curthread)->td_intr_frame;
112 (*pmc_intr)(PCPU_GET(cpuid), tf);
114 return (FILTER_HANDLED);
117 static device_method_t octeon_pmc_methods[] = {
118 DEVMETHOD(device_identify, octeon_pmc_identify),
119 DEVMETHOD(device_probe, octeon_pmc_probe),
120 DEVMETHOD(device_attach, octeon_pmc_attach),
124 static driver_t octeon_pmc_driver = {
127 sizeof(struct octeon_pmc_softc),
129 static devclass_t octeon_pmc_devclass;
130 DRIVER_MODULE(octeon_pmc, nexus, octeon_pmc_driver, octeon_pmc_devclass, 0, 0);