NetBSD/sys/arch/evbmips/malta/malta_intr.c
dyoung d3e53912d2 Neither pci_dma64_available(), pci_probe_device(), pci_mapreg_map(9),
pci_find_rom(), pci_intr_map(9), pci_enumerate_bus(), nor the match
predicate passed to pciide_compat_intr_establish() should ever modify
their pci_attach_args argument, so make their pci_attach_args arguments
const and deal with the fallout throughout the kernel.

For the most part, these changes add a 'const' where there was no
'const' before, however, some drivers and MD code used to modify
pci_attach_args.  Now those drivers either copy their pci_attach_args
and modify the copy, or refrain from modifying pci_attach_args:

Xen: according to Manuel Bouyer, writing to pci_attach_args in
    pci_intr_map() was a leftover from Xen 2.  Probably a bug.  I
    stopped writing it.  I have not tested this change.

siside(4): sis_hostbr_match() needlessly wrote to pci_attach_args.
    Probably a bug.  I use a temporary variable.  I have not tested this
    change.

slide(4): sl82c105_chip_map() overwrote the caller's pci_attach_args.
    Probably a bug.  Use a local pci_attach_args.  I have not tested
    this change.

viaide(4): via_sata_chip_map() and via_sata_chip_map_new() overwrote the
    caller's pci_attach_args.  Probably a bug.  Make a local copy of the
    caller's pci_attach_args and modify the copy.  I have not tested
    this change.

While I'm here, make pci_mapreg_submap() static.

With these changes in place, I have tested the compilation of these
kernels:

alpha GENERIC
amd64 GENERIC XEN3_DOM0
arc GENERIC
atari HADES MILAN-PCIIDE
bebox GENERIC
cats GENERIC
cobalt GENERIC
evbarm-eb NSLU2
evbarm-el ADI_BRH ARMADILLO9 CP3100 GEMINI GEMINI_MASTER GEMINI_SLAVE GUMSTIX
	HDL_G IMX31LITE INTEGRATOR IQ31244 IQ80310 IQ80321 IXDP425 IXM1200
	KUROBOX_PRO LUBBOCK MARVELL_NAS NAPPI SHEEVAPLUG SMDK2800 TEAMASA_NPWR
	TEAMASA_NPWR_FC TS7200 TWINTAIL ZAO425
evbmips-el AP30 DBAU1500 DBAU1550 MALTA MERAKI MTX-1 OMSAL400 RB153 WGT624V3
evbmips64-el XLSATX
evbppc EV64260 MPC8536DS MPC8548CDS OPENBLOCKS200 OPENBLOCKS266
	OPENBLOCKS266_OPT P2020RDB PMPPC RB800 WALNUT
hp700 GENERIC
i386 ALL XEN3_DOM0 XEN3_DOMU
ibmnws GENERIC
macppc GENERIC
mvmeppc GENERIC
netwinder GENERIC
ofppc GENERIC
prep GENERIC
sandpoint GENERIC
sgimips GENERIC32_IP2x
sparc GENERIC_SUN4U KRUPS
sparc64 GENERIC

As of Sun Apr 3 15:26:26 CDT 2011, I could not compile these kernels
with or without my patches in place:

### evbmips-el GDIUM

nbmake: nbmake: don't know how to make /home/dyoung/pristine-nbsd/src/sys/arch/mips/mips/softintr.c. Stop

### evbarm-el MPCSA_GENERIC
src/sys/arch/evbarm/conf/MPCSA_GENERIC:318: ds1672rtc*: unknown device `ds1672rtc'

### ia64 GENERIC

/tmp/genassym.28085/assym.c: In function 'f111':
/tmp/genassym.28085/assym.c:67: error: invalid application of 'sizeof' to incomplete type 'struct pcb'
/tmp/genassym.28085/assym.c:76: error: dereferencing pointer to incomplete type

### sgimips GENERIC32_IP3x

crmfb.o: In function `crmfb_attach':
crmfb.c:(.text+0x2304): undefined reference to `ddc_read_edid'
crmfb.c:(.text+0x2304): relocation truncated to fit: R_MIPS_26 against `ddc_read_edid'
crmfb.c:(.text+0x234c): undefined reference to `edid_parse'
crmfb.c:(.text+0x234c): relocation truncated to fit: R_MIPS_26 against `edid_parse'
crmfb.c:(.text+0x2354): undefined reference to `edid_print'
crmfb.c:(.text+0x2354): relocation truncated to fit: R_MIPS_26 against `edid_print'
2011-04-04 20:37:49 +00:00

407 lines
11 KiB
C

/* $NetBSD: malta_intr.c,v 1.21 2011/04/04 20:37:49 dyoung Exp $ */
/*
* Copyright 2001, 2002 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Platform-specific interrupt support for the MIPS Malta.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: malta_intr.c,v 1.21 2011/04/04 20:37:49 dyoung Exp $");
#define __INTR_PRIVATE
#include <sys/param.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/cpu.h>
#include <mips/locore.h>
#include <evbmips/malta/maltavar.h>
#include <evbmips/malta/pci/pcibvar.h>
#include <dev/ic/mc146818reg.h> /* for malta_cal_timer() */
#include <dev/isa/isavar.h>
#include <dev/pci/pciidereg.h>
/*
* This is a mask of bits to clear in the SR when we go to a
* given hardware interrupt priority level.
*/
static const struct ipl_sr_map malta_ipl_sr_map = {
.sr_bits = {
[IPL_NONE] = 0,
[IPL_SOFTCLOCK] = MIPS_SOFT_INT_MASK_0,
[IPL_SOFTNET] = MIPS_SOFT_INT_MASK,
[IPL_VM] = MIPS_SOFT_INT_MASK | MIPS_INT_MASK_0,
[IPL_SCHED] = MIPS_SOFT_INT_MASK | MIPS_INT_MASK_0
| MIPS_INT_MASK_5,
[IPL_DDB] = MIPS_INT_MASK,
[IPL_HIGH] = MIPS_INT_MASK,
},
};
struct malta_cpuintr {
LIST_HEAD(, evbmips_intrhand) cintr_list;
struct evcnt cintr_count;
};
#define NINTRS 5 /* MIPS INT0 - INT4 */
struct malta_cpuintr malta_cpuintrs[NINTRS];
const char * const malta_cpuintrnames[NINTRS] = {
"int 0 (piix4)",
"int 1 (smi)",
"int 2 (uart)",
"int 3 (core hi/gt64120)",
"int 4 (core lo)",
};
static int malta_pci_intr_map(const struct pci_attach_args *,
pci_intr_handle_t *);
static const char
*malta_pci_intr_string(void *, pci_intr_handle_t);
static const struct evcnt
*malta_pci_intr_evcnt(void *, pci_intr_handle_t);
static void *malta_pci_intr_establish(void *, pci_intr_handle_t, int,
int (*)(void *), void *);
static void malta_pci_intr_disestablish(void *, void *);
static void malta_pci_conf_interrupt(void *, int, int, int, int, int *);
static void *malta_pciide_compat_intr_establish(void *, struct device *,
const struct pci_attach_args *, int, int (*)(void *),
void *);
void
evbmips_intr_init(void)
{
struct malta_config * const mcp = &malta_configuration;
ipl_sr_map = malta_ipl_sr_map;
for (size_t i = 0; i < NINTRS; i++) {
LIST_INIT(&malta_cpuintrs[i].cintr_list);
evcnt_attach_dynamic(&malta_cpuintrs[i].cintr_count,
EVCNT_TYPE_INTR, NULL, "mips", malta_cpuintrnames[i]);
}
mcp->mc_pc.pc_intr_v = NULL;
mcp->mc_pc.pc_intr_map = malta_pci_intr_map;
mcp->mc_pc.pc_intr_string = malta_pci_intr_string;
mcp->mc_pc.pc_intr_evcnt = malta_pci_intr_evcnt;
mcp->mc_pc.pc_intr_establish = malta_pci_intr_establish;
mcp->mc_pc.pc_intr_disestablish = malta_pci_intr_disestablish;
mcp->mc_pc.pc_conf_interrupt = malta_pci_conf_interrupt;
mcp->mc_pc.pc_pciide_compat_intr_establish =
malta_pciide_compat_intr_establish;
}
void
malta_cal_timer(bus_space_tag_t st, bus_space_handle_t sh)
{
struct cpu_info * const ci = curcpu();
uint32_t ctrdiff[4], startctr, endctr;
uint8_t regc;
int i;
/* Disable interrupts first. */
bus_space_write_1(st, sh, 0, MC_REGB);
bus_space_write_1(st, sh, 1, MC_REGB_SQWE | MC_REGB_BINARY |
MC_REGB_24HR);
/* Initialize for 16Hz. */
bus_space_write_1(st, sh, 0, MC_REGA);
bus_space_write_1(st, sh, 1, MC_BASE_32_KHz | MC_RATE_16_Hz);
/* Run the loop an extra time to prime the cache. */
for (i = 0; i < 4; i++) {
// led_display('h', 'z', '0' + i, ' ');
/* Enable the interrupt. */
bus_space_write_1(st, sh, 0, MC_REGB);
bus_space_write_1(st, sh, 1, MC_REGB_PIE | MC_REGB_SQWE |
MC_REGB_BINARY | MC_REGB_24HR);
/* Go to REGC. */
bus_space_write_1(st, sh, 0, MC_REGC);
/* Wait for it to happen. */
startctr = mips3_cp0_count_read();
do {
regc = bus_space_read_1(st, sh, 1);
endctr = mips3_cp0_count_read();
} while ((regc & MC_REGC_IRQF) == 0);
/* Already ACK'd. */
/* Disable. */
bus_space_write_1(st, sh, 0, MC_REGB);
bus_space_write_1(st, sh, 1, MC_REGB_SQWE | MC_REGB_BINARY |
MC_REGB_24HR);
ctrdiff[i] = endctr - startctr;
}
/* Compute the number of cycles per second. */
ci->ci_cpu_freq = ((ctrdiff[2] + ctrdiff[3]) / 2) * 16/*Hz*/;
/* Compute the number of ticks for hz. */
ci->ci_cycles_per_hz = (ci->ci_cpu_freq + hz / 2) / hz;
/* Compute the delay divisor. */
ci->ci_divisor_delay = ((ci->ci_cpu_freq + 500000) / 1000000);
/*
* Get correct cpu frequency if the CPU runs at twice the
* external/cp0-count frequency.
*/
ci->ci_cctr_freq = ci->ci_cpu_freq;
if (mips_options.mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
ci->ci_cpu_freq *= 2;
#ifdef DEBUG
printf("Timer calibration: %lu cycles/sec [(%u, %u) * 16]\n",
ci->ci_cpu_freq, ctrdiff[2], ctrdiff[3]);
#endif
}
void *
evbmips_intr_establish(int irq, int (*func)(void *), void *arg)
{
struct evbmips_intrhand *ih;
int s;
ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
if (ih == NULL)
return (NULL);
ih->ih_func = func;
ih->ih_arg = arg;
s = splhigh();
/*
* Link it into the tables.
*/
LIST_INSERT_HEAD(&malta_cpuintrs[0].cintr_list, ih, ih_q);
/* XXX - should check that MIPS_INT_MASK_0 is set... */
splx(s);
return (ih);
}
void
evbmips_intr_disestablish(void *arg)
{
struct evbmips_intrhand *ih = arg;
int s;
s = splhigh();
/*
* First, remove it from the table.
*/
LIST_REMOVE(ih, ih_q);
/* XXX - disable MIPS_INT_MASK_0 if list is empty? */
splx(s);
free(ih, M_DEVBUF);
}
void
evbmips_iointr(int ipl, vaddr_t pc, uint32_t ipending)
{
/* Check for error interrupts (SMI, GT64120) */
if (ipending & (MIPS_INT_MASK_1 | MIPS_INT_MASK_3)) {
if (ipending & MIPS_INT_MASK_1)
panic("piix4 SMI interrupt");
if (ipending & MIPS_INT_MASK_3)
panic("gt64120 error interrupt");
}
/*
* Read the interrupt pending registers, mask them with the
* ones we have enabled, and service them in order of decreasing
* priority.
*/
if (ipending & MIPS_INT_MASK_0) {
struct evbmips_intrhand *ih;
/* All interrupts are gated through MIPS HW interrupt 0 */
malta_cpuintrs[0].cintr_count.ev_count++;
LIST_FOREACH(ih, &malta_cpuintrs[0].cintr_list, ih_q)
(*ih->ih_func)(ih->ih_arg);
}
}
/*
* YAMON configures pa_intrline correctly (so far), so we trust it to DTRT
* in the future...
*/
#undef YAMON_IRQ_MAP_BAD
/*
* PCI interrupt support
*/
static int
malta_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
{
#ifdef YAMON_IRQ_MAP_BAD
static const int pciirqmap[12/*device*/][4/*pin*/] = {
{ -1, -1, -1, 11 }, /* 10: USB */
{ 10, -1, -1, -1 }, /* 11: Ethernet */
{ 11, -1, -1, -1 }, /* 12: Audio */
{ -1, -1, -1, -1 }, /* 13: not used */
{ -1, -1, -1, -1 }, /* 14: not used */
{ -1, -1, -1, -1 }, /* 15: not used */
{ -1, -1, -1, -1 }, /* 16: not used */
{ -1, -1, -1, -1 }, /* 17: Core card(?) */
{ 10, 10, 11, 11 }, /* 18: PCI Slot 1 */
{ 10, 11, 11, 10 }, /* 19: PCI Slot 2 */
{ 11, 11, 10, 10 }, /* 20: PCI Slot 3 */
{ 11, 10, 10, 11 }, /* 21: PCI Slot 4 */
};
int buspin, device, irq;
#else /* !YAMON_IRQ_MAP_BAD */
int buspin;
#endif /* !YAMON_IRQ_MAP_BAD */
buspin = pa->pa_intrpin;
if (buspin == 0) {
/* No IRQ used. */
return (1);
}
if (buspin > 4) {
printf("malta_pci_intr_map: bad interrupt pin %d\n", buspin);
return (1);
}
#ifdef YAMON_IRQ_MAP_BAD
pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &device, NULL);
if (device < 10 || device > 21) {
printf("malta_pci_intr_map: bad device %d\n", device);
return (1);
}
irq = pciirqmap[device - 10][buspin - 1];
if (irq == -1) {
printf("malta_pci_intr_map: no mapping for device %d pin %d\n",
device, buspin);
return (1);
}
*ihp = irq;
#else /* !YAMON_IRQ_MAP_BAD */
*ihp = pa->pa_intrline;
#endif /* !YAMON_IRQ_MAP_BAD */
return (0);
}
static const char *
malta_pci_intr_string(void *v, pci_intr_handle_t irq)
{
return (isa_intr_string(pcib_ic, irq));
}
static const struct evcnt *
malta_pci_intr_evcnt(void *v, pci_intr_handle_t irq)
{
return (isa_intr_evcnt(pcib_ic, irq));
}
static void *
malta_pci_intr_establish(void *v, pci_intr_handle_t irq, int level,
int (*func)(void *), void *arg)
{
return (isa_intr_establish(pcib_ic, irq, IST_LEVEL, level, func, arg));
}
static void
malta_pci_intr_disestablish(void *v, void *arg)
{
return (isa_intr_disestablish(pcib_ic, arg));
}
static void
malta_pci_conf_interrupt(void *v, int bus, int dev, int func, int swiz,
int *iline)
{
/*
* We actually don't need to do anything; everything is handled
* in pci_intr_map().
*/
*iline = 0;
}
void *
malta_pciide_compat_intr_establish(void *v, struct device *dev,
const struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
{
pci_chipset_tag_t pc = pa->pa_pc;
void *cookie;
int bus, irq;
pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
/*
* If this isn't PCI bus #0, all bets are off.
*/
if (bus != 0)
return (NULL);
irq = PCIIDE_COMPAT_IRQ(chan);
cookie = isa_intr_establish(pcib_ic, irq, IST_EDGE, IPL_BIO, func, arg);
if (cookie == NULL)
return (NULL);
printf("%s: %s channel interrupting at %s\n", dev->dv_xname,
PCIIDE_CHANNEL_NAME(chan), malta_pci_intr_string(v, irq));
return (cookie);
}