pci_up1000.c revision 1.17       1  1.17   thorpej /* $NetBSD: pci_up1000.c,v 1.17 2021/06/19 16:59:07 thorpej Exp $ */
      2   1.1   thorpej 
      3   1.1   thorpej /*-
      4   1.1   thorpej  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5   1.1   thorpej  * All rights reserved.
      6   1.1   thorpej  *
      7   1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1   thorpej  * by Jason R. Thorpe.
      9   1.1   thorpej  *
     10   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11   1.1   thorpej  * modification, are permitted provided that the following conditions
     12   1.1   thorpej  * are met:
     13   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18   1.1   thorpej  *
     19   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1   thorpej  */
     31   1.1   thorpej 
     32   1.1   thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     33   1.1   thorpej 
     34  1.17   thorpej __KERNEL_RCSID(0, "$NetBSD: pci_up1000.c,v 1.17 2021/06/19 16:59:07 thorpej Exp $");
     35   1.1   thorpej 
     36   1.1   thorpej #include <sys/types.h>
     37   1.1   thorpej #include <sys/param.h>
     38   1.1   thorpej #include <sys/time.h>
     39   1.1   thorpej #include <sys/systm.h>
     40   1.1   thorpej #include <sys/errno.h>
     41   1.1   thorpej #include <sys/device.h>
     42   1.5       mrg 
     43   1.1   thorpej #include <machine/autoconf.h>
     44  1.17   thorpej #include <machine/rpb.h>
     45  1.14    dyoung #include <sys/bus.h>
     46   1.1   thorpej #include <machine/intr.h>
     47   1.1   thorpej 
     48   1.1   thorpej #include <dev/isa/isavar.h>
     49   1.1   thorpej 
     50   1.1   thorpej #include <dev/pci/pcireg.h>
     51   1.1   thorpej #include <dev/pci/pcivar.h>
     52   1.1   thorpej #include <dev/pci/pciidereg.h>
     53   1.1   thorpej #include <dev/pci/pciidevar.h>
     54   1.1   thorpej 
     55   1.1   thorpej #include <alpha/pci/irongatevar.h>
     56   1.1   thorpej 
     57   1.1   thorpej #include <alpha/pci/siovar.h>
     58   1.1   thorpej #include <alpha/pci/sioreg.h>
     59   1.1   thorpej 
     60   1.1   thorpej #include "sio.h"
     61   1.1   thorpej 
     62  1.16   thorpej static int	api_up1000_intr_map(const struct pci_attach_args *,
     63  1.16   thorpej 		    pci_intr_handle_t *);
     64   1.1   thorpej 
     65  1.17   thorpej static void
     66  1.17   thorpej pci_up1000_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
     67  1.17   thorpej     pci_chipset_tag_t pc)
     68   1.1   thorpej {
     69   1.9       mrg #if NSIO
     70  1.17   thorpej 	pc->pc_intr_v = core;
     71   1.1   thorpej 	pc->pc_intr_map = api_up1000_intr_map;
     72  1.16   thorpej 	pc->pc_intr_string = sio_pci_intr_string;
     73  1.16   thorpej 	pc->pc_intr_evcnt = sio_pci_intr_evcnt;
     74  1.16   thorpej 	pc->pc_intr_establish = sio_pci_intr_establish;
     75  1.16   thorpej 	pc->pc_intr_disestablish = sio_pci_intr_disestablish;
     76   1.1   thorpej 
     77   1.1   thorpej 	pc->pc_pciide_compat_intr_establish =
     78  1.16   thorpej 	    sio_pciide_compat_intr_establish;
     79   1.1   thorpej 
     80   1.1   thorpej 	sio_intr_setup(pc, iot);
     81   1.1   thorpej #else
     82   1.1   thorpej 	panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)");
     83   1.1   thorpej #endif
     84   1.1   thorpej }
     85  1.17   thorpej ALPHA_PCI_INTR_INIT(ST_API_NAUTILUS, pci_up1000_pickintr)
     86   1.1   thorpej 
     87  1.16   thorpej static int
     88  1.12    dyoung api_up1000_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
     89   1.1   thorpej {
     90   1.6  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
     91   1.6  sommerfe 	int buspin = pa->pa_intrpin;
     92   1.6  sommerfe 	int bustag = pa->pa_intrtag;
     93   1.6  sommerfe 	int line = pa->pa_intrline;
     94   1.1   thorpej 	int bus, device, function;
     95   1.1   thorpej 
     96   1.1   thorpej 	if (buspin == 0) {
     97   1.1   thorpej 		/* No IRQ used. */
     98   1.1   thorpej 		return 1;
     99   1.1   thorpej 	}
    100  1.16   thorpej 	if (buspin < 0 || buspin > 4) {
    101  1.16   thorpej 		printf("%s: bad interrupt pin %d\n", __func__, buspin);
    102   1.1   thorpej 		return 1;
    103   1.1   thorpej 	}
    104   1.1   thorpej 
    105   1.8   thorpej 	pci_decompose_tag(pc, bustag, &bus, &device, &function);
    106   1.1   thorpej 
    107   1.1   thorpej 	/*
    108   1.1   thorpej 	 * The console places the interrupt mapping in the "line" value.
    109   1.1   thorpej 	 * A value of (char)-1 indicates there is no mapping.
    110   1.1   thorpej 	 */
    111   1.1   thorpej 	if (line == 0xff) {
    112  1.16   thorpej 		printf("%s: no mapping for %d/%d/%d\n", __func__,
    113   1.1   thorpej 		    bus, device, function);
    114   1.1   thorpej 		return (1);
    115   1.1   thorpej 	}
    116   1.1   thorpej 
    117  1.16   thorpej 	if (line < 0 || line > 15) {
    118  1.16   thorpej 		printf("%s: bad ISA IRQ (%d)\n", __func__, line);
    119   1.1   thorpej 		return (1);
    120   1.1   thorpej 	}
    121   1.1   thorpej 	if (line == 2) {
    122  1.16   thorpej 		printf("%s: changed IRQ 2 to IRQ 9\n", __func__);
    123   1.1   thorpej 		line = 9;
    124   1.1   thorpej 	}
    125   1.1   thorpej 
    126  1.16   thorpej 	alpha_pci_intr_handle_init(ihp, line, 0);
    127   1.1   thorpej 	return (0);
    128   1.1   thorpej }
    129