Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.27
      1  1.27   thorpej /* $NetBSD: pci_machdep.c,v 1.27 2020/09/26 02:46:28 thorpej Exp $ */
      2  1.25   thorpej 
      3  1.25   thorpej /*-
      4  1.25   thorpej  * Copyright (c) 2020 The NetBSD Foundation, Inc.
      5  1.25   thorpej  * All rights reserved.
      6  1.25   thorpej  *
      7  1.25   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.25   thorpej  * by Jason R. Thorpe.
      9  1.25   thorpej  *
     10  1.25   thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.25   thorpej  * modification, are permitted provided that the following conditions
     12  1.25   thorpej  * are met:
     13  1.25   thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.25   thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.25   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.25   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.25   thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.25   thorpej  *
     19  1.25   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.25   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.25   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.25   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.25   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.25   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.25   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.25   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.25   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.25   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.25   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30  1.25   thorpej  */
     31   1.1       cgd 
     32   1.1       cgd /*
     33   1.5       cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     34   1.3       cgd  * All rights reserved.
     35   1.1       cgd  *
     36   1.3       cgd  * Author: Chris G. Demetriou
     37  1.19      matt  *
     38   1.3       cgd  * Permission to use, copy, modify and distribute this software and
     39   1.3       cgd  * its documentation is hereby granted, provided that both the copyright
     40   1.3       cgd  * notice and this permission notice appear in all copies of the
     41   1.3       cgd  * software, derivative works or modified versions, and any portions
     42   1.3       cgd  * thereof, and that both notices appear in supporting documentation.
     43  1.19      matt  *
     44  1.19      matt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     45  1.19      matt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     46   1.3       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     47  1.19      matt  *
     48   1.3       cgd  * Carnegie Mellon requests users of this software to return to
     49   1.1       cgd  *
     50   1.3       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     51   1.3       cgd  *  School of Computer Science
     52   1.3       cgd  *  Carnegie Mellon University
     53   1.3       cgd  *  Pittsburgh PA 15213-3890
     54   1.3       cgd  *
     55   1.3       cgd  * any improvements or extensions that they make and grant Carnegie the
     56   1.3       cgd  * rights to redistribute these changes.
     57   1.1       cgd  */
     58   1.1       cgd 
     59   1.1       cgd /*
     60   1.1       cgd  * Machine-specific functions for PCI autoconfiguration.
     61   1.1       cgd  */
     62   1.9       cgd 
     63  1.10       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     64  1.10       cgd 
     65  1.27   thorpej __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.27 2020/09/26 02:46:28 thorpej Exp $");
     66   1.1       cgd 
     67   1.1       cgd #include <sys/types.h>
     68   1.1       cgd #include <sys/param.h>
     69   1.1       cgd #include <sys/time.h>
     70   1.1       cgd #include <sys/systm.h>
     71   1.1       cgd #include <sys/errno.h>
     72   1.1       cgd #include <sys/device.h>
     73  1.26   thorpej #include <sys/cpu.h>
     74  1.14       mrg 
     75   1.1       cgd #include <dev/isa/isavar.h>
     76   1.3       cgd #include <dev/pci/pcireg.h>
     77   1.1       cgd #include <dev/pci/pcivar.h>
     78   1.2       cgd #include <dev/pci/pcidevs.h>
     79   1.1       cgd 
     80   1.7       cgd #include "vga_pci.h"
     81   1.7       cgd #if NVGA_PCI
     82  1.13  drochner #include <dev/ic/mc6845reg.h>
     83  1.13  drochner #include <dev/ic/pcdisplayvar.h>
     84  1.12  drochner #include <dev/pci/vga_pcivar.h>
     85   1.3       cgd #endif
     86   1.3       cgd 
     87   1.2       cgd #include "tga.h"
     88   1.3       cgd #if NTGA
     89  1.12  drochner #include <dev/pci/tgavar.h>
     90   1.3       cgd #endif
     91   1.1       cgd 
     92  1.20   tsutsui #include <machine/rpb.h>
     93  1.20   tsutsui 
     94   1.1       cgd void
     95  1.17       dsl pci_display_console(bus_space_tag_t iot, bus_space_tag_t memt, pci_chipset_tag_t pc, int bus, int device, int function)
     96   1.1       cgd {
     97  1.23  uebayasi #if NVGA_PCI || NTGA
     98   1.4       cgd 	pcitag_t tag;
     99  1.24       rin 	pcireg_t id;
    100   1.4       cgd 	int match, nmatch;
    101  1.23  uebayasi #endif
    102  1.24       rin #if NVGA_PCI
    103  1.24       rin 	pcireg_t class;
    104  1.24       rin #endif
    105  1.16       dsl 	int (*fn)(bus_space_tag_t, bus_space_tag_t, pci_chipset_tag_t,
    106  1.16       dsl 	    int, int, int);
    107   1.1       cgd 
    108  1.23  uebayasi #if NVGA_PCI || NTGA
    109   1.4       cgd 	tag = pci_make_tag(pc, bus, device, function);
    110   1.4       cgd 	id = pci_conf_read(pc, tag, PCI_ID_REG);
    111   1.2       cgd 	if (id == 0 || id == 0xffffffff)
    112   1.2       cgd 		panic("pci_display_console: no device at %d/%d/%d",
    113   1.2       cgd 		    bus, device, function);
    114  1.24       rin #  if NVGA_PCI
    115   1.4       cgd 	class = pci_conf_read(pc, tag, PCI_CLASS_REG);
    116  1.24       rin #  endif
    117   1.4       cgd 
    118  1.23  uebayasi 	match = 0;
    119  1.23  uebayasi #endif
    120   1.4       cgd 	fn = NULL;
    121   1.2       cgd 
    122   1.7       cgd #if NVGA_PCI
    123   1.7       cgd 	nmatch = DEVICE_IS_VGA_PCI(class, id);
    124   1.4       cgd 	if (nmatch > match) {
    125   1.4       cgd 		match = nmatch;
    126  1.12  drochner 		fn = vga_pci_cnattach;
    127   1.2       cgd 	}
    128   1.3       cgd #endif
    129   1.2       cgd #if NTGA
    130   1.4       cgd 	nmatch = DEVICE_IS_TGA(class, id);
    131  1.15     elric 	if (nmatch > match)
    132  1.15     elric 		nmatch = tga_cnmatch(iot, memt, pc, tag);
    133   1.4       cgd 	if (nmatch > match) {
    134   1.4       cgd 		match = nmatch;
    135  1.12  drochner 		fn = tga_cnattach;
    136   1.2       cgd 	}
    137   1.3       cgd #endif
    138   1.2       cgd 
    139   1.4       cgd 	if (fn != NULL)
    140   1.6       cgd 		(*fn)(iot, memt, pc, bus, device, function);
    141   1.4       cgd 	else
    142   1.4       cgd 		panic("pci_display_console: unconfigured device at %d/%d/%d",
    143   1.2       cgd 		    bus, device, function);
    144   1.1       cgd }
    145  1.20   tsutsui 
    146  1.20   tsutsui void
    147  1.20   tsutsui device_pci_register(device_t dev, void *aux)
    148  1.20   tsutsui {
    149  1.20   tsutsui 	struct pci_attach_args *pa = aux;
    150  1.20   tsutsui 	struct ctb *ctb;
    151  1.20   tsutsui 	prop_dictionary_t dict;
    152  1.20   tsutsui 
    153  1.20   tsutsui 	/* set properties for PCI framebuffers */
    154  1.20   tsutsui 	ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
    155  1.20   tsutsui 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
    156  1.20   tsutsui 	    ctb->ctb_term_type == CTB_GRAPHICS) {
    157  1.20   tsutsui 		/* XXX should consider multiple displays? */
    158  1.20   tsutsui 		dict = device_properties(dev);
    159  1.20   tsutsui 		prop_dictionary_set_bool(dict, "is_console", true);
    160  1.20   tsutsui 	}
    161  1.20   tsutsui }
    162  1.25   thorpej 
    163  1.25   thorpej int
    164  1.25   thorpej alpha_pci_generic_intr_map(const struct pci_attach_args * const pa,
    165  1.25   thorpej     pci_intr_handle_t * const ihp)
    166  1.25   thorpej {
    167  1.25   thorpej 	pcitag_t const bustag = pa->pa_intrtag;
    168  1.25   thorpej 	int const buspin = pa->pa_intrpin;
    169  1.25   thorpej 	int const line = pa->pa_intrline;
    170  1.25   thorpej 	pci_chipset_tag_t const pc = pa->pa_pc;
    171  1.25   thorpej 	int bus, device, function;
    172  1.25   thorpej 
    173  1.25   thorpej 	if (buspin == 0) {
    174  1.25   thorpej 		/* No IRQ used. */
    175  1.25   thorpej 		return 1;
    176  1.25   thorpej 	}
    177  1.25   thorpej 	if (buspin < 0 || buspin > 4) {
    178  1.25   thorpej 		printf("%s: bad interrupt pin %d\n", __func__, buspin);
    179  1.25   thorpej 		return 1;
    180  1.25   thorpej 	}
    181  1.25   thorpej 
    182  1.25   thorpej 	pci_decompose_tag(pc, bustag, &bus, &device, &function);
    183  1.25   thorpej 
    184  1.25   thorpej 	/*
    185  1.25   thorpej 	 * The console firmware places the interrupt mapping in the "line"
    186  1.25   thorpej 	 * value.  A valaue of (char)-1 indicates there is no mapping.
    187  1.25   thorpej 	 */
    188  1.25   thorpej 	if (line == 0xff) {
    189  1.25   thorpej 		printf("%s: no mapping for %d/%d/%d\n", __func__,
    190  1.25   thorpej 		    bus, device, function);
    191  1.25   thorpej 		return 1;
    192  1.25   thorpej 	}
    193  1.25   thorpej 
    194  1.25   thorpej 	if (line < 0 || line >= pc->pc_nirq) {
    195  1.25   thorpej 		printf("%s: bad line %d for %d/%d/%d\n", __func__,
    196  1.25   thorpej 		    line, bus, device, function);
    197  1.25   thorpej 		return 1;
    198  1.25   thorpej 	}
    199  1.25   thorpej 
    200  1.25   thorpej 	alpha_pci_intr_handle_init(ihp, line, 0);
    201  1.25   thorpej 	return 0;
    202  1.25   thorpej }
    203  1.25   thorpej 
    204  1.25   thorpej const char *
    205  1.25   thorpej alpha_pci_generic_intr_string(pci_chipset_tag_t const pc,
    206  1.25   thorpej     pci_intr_handle_t const ih, char * const buf, size_t const len)
    207  1.25   thorpej {
    208  1.25   thorpej 	const u_int irq = alpha_pci_intr_handle_get_irq(&ih);
    209  1.25   thorpej 
    210  1.25   thorpej 	KASSERT(irq < pc->pc_nirq);
    211  1.25   thorpej 
    212  1.25   thorpej 	snprintf(buf, len, "%s %u", pc->pc_intr_desc, irq);
    213  1.25   thorpej 	return buf;
    214  1.25   thorpej }
    215  1.25   thorpej 
    216  1.25   thorpej const struct evcnt *
    217  1.25   thorpej alpha_pci_generic_intr_evcnt(pci_chipset_tag_t const pc,
    218  1.25   thorpej     pci_intr_handle_t const ih)
    219  1.25   thorpej {
    220  1.25   thorpej 	const u_int irq = alpha_pci_intr_handle_get_irq(&ih);
    221  1.25   thorpej 
    222  1.25   thorpej 	KASSERT(irq < pc->pc_nirq);
    223  1.25   thorpej 
    224  1.25   thorpej 	return alpha_shared_intr_evcnt(pc->pc_shared_intrs, irq);
    225  1.25   thorpej }
    226  1.25   thorpej 
    227  1.27   thorpej static struct cpu_info *
    228  1.27   thorpej alpha_pci_generic_intr_select_cpu(pci_chipset_tag_t const pc, u_int const irq,
    229  1.27   thorpej     u_int const flags)
    230  1.27   thorpej {
    231  1.27   thorpej 	struct cpu_info *ci, *best_ci;
    232  1.27   thorpej 	CPU_INFO_ITERATOR cii;
    233  1.27   thorpej 
    234  1.27   thorpej 	KASSERT(mutex_owned(&cpu_lock));
    235  1.27   thorpej 
    236  1.27   thorpej 	/*
    237  1.27   thorpej 	 * If the back-end didn't tell us where we can route, then
    238  1.27   thorpej 	 * they all go to the primry CPU.
    239  1.27   thorpej 	 */
    240  1.27   thorpej 	if (pc->pc_eligible_cpus == 0) {
    241  1.27   thorpej 		return &cpu_info_primary;
    242  1.27   thorpej 	}
    243  1.27   thorpej 
    244  1.27   thorpej 	/*
    245  1.27   thorpej 	 * If the interrupt already has a CPU assigned, keep on using it,
    246  1.27   thorpej 	 * unless the CPU has become ineligible.
    247  1.27   thorpej 	 */
    248  1.27   thorpej 	ci = alpha_shared_intr_get_cpu(pc->pc_shared_intrs, irq);
    249  1.27   thorpej 	if (ci != NULL) {
    250  1.27   thorpej 		if ((ci->ci_schedstate.spc_flags & SPCF_NOINTR) == 0 ||
    251  1.27   thorpej 		    CPU_IS_PRIMARY(ci)) {
    252  1.27   thorpej 			return ci;
    253  1.27   thorpej 		}
    254  1.27   thorpej 	}
    255  1.27   thorpej 
    256  1.27   thorpej 	/*
    257  1.27   thorpej 	 * Pick the CPU with the fewest handlers.
    258  1.27   thorpej 	 */
    259  1.27   thorpej 	best_ci = NULL;
    260  1.27   thorpej 	for (CPU_INFO_FOREACH(cii, ci)) {
    261  1.27   thorpej 		if ((pc->pc_eligible_cpus & __BIT(ci->ci_cpuid)) == 0) {
    262  1.27   thorpej 			/* This CPU is not eligible in hardware. */
    263  1.27   thorpej 			continue;
    264  1.27   thorpej 		}
    265  1.27   thorpej 		if (ci->ci_schedstate.spc_flags & SPCF_NOINTR) {
    266  1.27   thorpej 			/* This CPU is not eligible in software. */
    267  1.27   thorpej 			continue;
    268  1.27   thorpej 		}
    269  1.27   thorpej 		if (best_ci == NULL ||
    270  1.27   thorpej 		    ci->ci_nintrhand < best_ci->ci_nintrhand) {
    271  1.27   thorpej 			best_ci = ci;
    272  1.27   thorpej 		}
    273  1.27   thorpej 	}
    274  1.27   thorpej 
    275  1.27   thorpej 	/* If we found one, cool... */
    276  1.27   thorpej 	if (best_ci != NULL) {
    277  1.27   thorpej 		return best_ci;
    278  1.27   thorpej 	}
    279  1.27   thorpej 
    280  1.27   thorpej 	/* ...if not, well I guess we'll just fall back on the primary. */
    281  1.27   thorpej 	return &cpu_info_primary;
    282  1.27   thorpej }
    283  1.27   thorpej 
    284  1.25   thorpej void *
    285  1.25   thorpej alpha_pci_generic_intr_establish(pci_chipset_tag_t const pc,
    286  1.25   thorpej     pci_intr_handle_t const ih, int const level,
    287  1.25   thorpej     int (*func)(void *), void *arg)
    288  1.25   thorpej {
    289  1.25   thorpej 	const u_int irq = alpha_pci_intr_handle_get_irq(&ih);
    290  1.25   thorpej 	const u_int flags = alpha_pci_intr_handle_get_flags(&ih);
    291  1.25   thorpej 	void *cookie;
    292  1.25   thorpej 
    293  1.25   thorpej 	KASSERT(irq < pc->pc_nirq);
    294  1.25   thorpej 
    295  1.26   thorpej 	cookie = alpha_shared_intr_alloc_intrhand(pc->pc_shared_intrs,
    296  1.25   thorpej 	    irq, IST_LEVEL, level, flags, func, arg, pc->pc_intr_desc);
    297  1.25   thorpej 
    298  1.26   thorpej 	if (cookie == NULL)
    299  1.26   thorpej 		return NULL;
    300  1.26   thorpej 
    301  1.26   thorpej 	mutex_enter(&cpu_lock);
    302  1.26   thorpej 
    303  1.27   thorpej 	struct cpu_info *target_ci =
    304  1.27   thorpej 	    alpha_pci_generic_intr_select_cpu(pc, irq, flags);
    305  1.27   thorpej 	struct cpu_info *current_ci =
    306  1.27   thorpej 	    alpha_shared_intr_get_cpu(pc->pc_shared_intrs, irq);
    307  1.27   thorpej 
    308  1.27   thorpej 	const bool first_handler =
    309  1.27   thorpej 	    ! alpha_shared_intr_isactive(pc->pc_shared_intrs, irq);
    310  1.27   thorpej 
    311  1.27   thorpej 	/*
    312  1.27   thorpej 	 * If this is the first handler on this interrupt, or if the
    313  1.27   thorpej 	 * target CPU has changed, then program the route if the
    314  1.27   thorpej 	 * hardware supports it.
    315  1.27   thorpej 	 */
    316  1.27   thorpej 	if (first_handler || target_ci != current_ci) {
    317  1.27   thorpej 		alpha_shared_intr_set_cpu(pc->pc_shared_intrs, irq, target_ci);
    318  1.27   thorpej 		if (pc->pc_intr_set_affinity != NULL) {
    319  1.27   thorpej 			pc->pc_intr_set_affinity(pc, irq, target_ci);
    320  1.27   thorpej 		}
    321  1.27   thorpej 	}
    322  1.27   thorpej 
    323  1.26   thorpej 	if (! alpha_shared_intr_link(pc->pc_shared_intrs, cookie,
    324  1.26   thorpej 				     pc->pc_intr_desc)) {
    325  1.26   thorpej 		mutex_exit(&cpu_lock);
    326  1.26   thorpej 		alpha_shared_intr_free_intrhand(cookie);
    327  1.26   thorpej 		return NULL;
    328  1.26   thorpej 	}
    329  1.26   thorpej 
    330  1.27   thorpej 	if (first_handler) {
    331  1.25   thorpej 		scb_set(pc->pc_vecbase + SCB_IDXTOVEC(irq),
    332  1.25   thorpej 		    alpha_pci_generic_iointr, pc);
    333  1.25   thorpej 		pc->pc_intr_enable(pc, irq);
    334  1.25   thorpej 	}
    335  1.26   thorpej 
    336  1.26   thorpej 	mutex_exit(&cpu_lock);
    337  1.26   thorpej 
    338  1.25   thorpej 	return cookie;
    339  1.25   thorpej }
    340  1.25   thorpej 
    341  1.25   thorpej void
    342  1.25   thorpej alpha_pci_generic_intr_disestablish(pci_chipset_tag_t const pc,
    343  1.25   thorpej     void * const cookie)
    344  1.25   thorpej {
    345  1.25   thorpej 	struct alpha_shared_intrhand * const ih = cookie;
    346  1.25   thorpej 	const u_int irq = ih->ih_num;
    347  1.25   thorpej 
    348  1.26   thorpej 	mutex_enter(&cpu_lock);
    349  1.25   thorpej 
    350  1.26   thorpej 	if (alpha_shared_intr_firstactive(pc->pc_shared_intrs, irq)) {
    351  1.25   thorpej 		pc->pc_intr_disable(pc, irq);
    352  1.25   thorpej 		alpha_shared_intr_set_dfltsharetype(pc->pc_shared_intrs,
    353  1.25   thorpej 		    irq, IST_NONE);
    354  1.25   thorpej 		scb_free(pc->pc_vecbase + SCB_IDXTOVEC(irq));
    355  1.25   thorpej 	}
    356  1.25   thorpej 
    357  1.26   thorpej 	alpha_shared_intr_unlink(pc->pc_shared_intrs, cookie, pc->pc_intr_desc);
    358  1.26   thorpej 
    359  1.26   thorpej 	mutex_exit(&cpu_lock);
    360  1.26   thorpej 
    361  1.26   thorpej 	alpha_shared_intr_free_intrhand(cookie);
    362  1.25   thorpej }
    363  1.25   thorpej 
    364  1.25   thorpej void
    365  1.25   thorpej alpha_pci_generic_iointr(void * const arg, unsigned long const vec)
    366  1.25   thorpej {
    367  1.25   thorpej 	pci_chipset_tag_t const pc = arg;
    368  1.25   thorpej 	const u_int irq = SCB_VECTOIDX(vec - pc->pc_vecbase);
    369  1.25   thorpej 
    370  1.25   thorpej 	if (!alpha_shared_intr_dispatch(pc->pc_shared_intrs, irq)) {
    371  1.25   thorpej 		alpha_shared_intr_stray(pc->pc_shared_intrs, irq,
    372  1.25   thorpej 		    pc->pc_intr_desc);
    373  1.25   thorpej 		if (ALPHA_SHARED_INTR_DISABLE(pc->pc_shared_intrs, irq)) {
    374  1.25   thorpej 			pc->pc_intr_disable(pc, irq);
    375  1.25   thorpej 		}
    376  1.25   thorpej 	} else {
    377  1.25   thorpej 		alpha_shared_intr_reset_strays(pc->pc_shared_intrs, irq);
    378  1.25   thorpej 	}
    379  1.25   thorpej }
    380  1.25   thorpej 
    381  1.25   thorpej #define	ALPHA_PCI_INTR_HANDLE_IRQ	__BITS(0,31)
    382  1.25   thorpej #define	ALPHA_PCI_INTR_HANDLE_FLAGS	__BITS(32,63)
    383  1.25   thorpej 
    384  1.25   thorpej void
    385  1.25   thorpej alpha_pci_intr_handle_init(pci_intr_handle_t * const ihp, u_int const irq,
    386  1.25   thorpej     u_int const flags)
    387  1.25   thorpej {
    388  1.25   thorpej 	ihp->value = __SHIFTIN(irq, ALPHA_PCI_INTR_HANDLE_IRQ) |
    389  1.25   thorpej 	    __SHIFTIN(flags, ALPHA_PCI_INTR_HANDLE_FLAGS);
    390  1.25   thorpej }
    391  1.25   thorpej 
    392  1.25   thorpej void
    393  1.25   thorpej alpha_pci_intr_handle_set_irq(pci_intr_handle_t * const ihp, u_int const irq)
    394  1.25   thorpej {
    395  1.25   thorpej 	ihp->value = (ihp->value & ALPHA_PCI_INTR_HANDLE_FLAGS) |
    396  1.25   thorpej 	    __SHIFTIN(irq, ALPHA_PCI_INTR_HANDLE_IRQ);
    397  1.25   thorpej }
    398  1.25   thorpej 
    399  1.25   thorpej u_int
    400  1.25   thorpej alpha_pci_intr_handle_get_irq(const pci_intr_handle_t * const ihp)
    401  1.25   thorpej {
    402  1.25   thorpej 	return __SHIFTOUT(ihp->value, ALPHA_PCI_INTR_HANDLE_IRQ);
    403  1.25   thorpej }
    404  1.25   thorpej 
    405  1.25   thorpej void
    406  1.25   thorpej alpha_pci_intr_handle_set_flags(pci_intr_handle_t * const ihp,
    407  1.25   thorpej     u_int const flags)
    408  1.25   thorpej {
    409  1.25   thorpej 	ihp->value = (ihp->value & ALPHA_PCI_INTR_HANDLE_IRQ) |
    410  1.25   thorpej 	    __SHIFTIN(flags, ALPHA_PCI_INTR_HANDLE_FLAGS);
    411  1.25   thorpej }
    412  1.25   thorpej 
    413  1.25   thorpej u_int
    414  1.25   thorpej alpha_pci_intr_handle_get_flags(const pci_intr_handle_t * const ihp)
    415  1.25   thorpej {
    416  1.25   thorpej 	return __SHIFTOUT(ihp->value, ALPHA_PCI_INTR_HANDLE_FLAGS);
    417  1.25   thorpej }
    418  1.25   thorpej 
    419  1.25   thorpej /*
    420  1.25   thorpej  * MI PCI back-end entry points.
    421  1.25   thorpej  */
    422  1.25   thorpej 
    423  1.25   thorpej void
    424  1.25   thorpej pci_attach_hook(device_t const parent, device_t const self,
    425  1.25   thorpej     struct pcibus_attach_args * const pba)
    426  1.25   thorpej {
    427  1.25   thorpej 	pci_chipset_tag_t const pc = pba->pba_pc;
    428  1.25   thorpej 
    429  1.25   thorpej 	KASSERT(pc->pc_attach_hook != NULL);
    430  1.25   thorpej 	pc->pc_attach_hook(parent, self, pba);
    431  1.25   thorpej }
    432  1.25   thorpej 
    433  1.25   thorpej int
    434  1.25   thorpej pci_bus_maxdevs(pci_chipset_tag_t const pc, int const busno)
    435  1.25   thorpej {
    436  1.25   thorpej 	KASSERT(pc->pc_bus_maxdevs != NULL);
    437  1.25   thorpej 	return pc->pc_bus_maxdevs(pc->pc_conf_v, busno);
    438  1.25   thorpej }
    439  1.25   thorpej 
    440  1.25   thorpej pcitag_t
    441  1.25   thorpej pci_make_tag(pci_chipset_tag_t const pc, int const bus, int const dev,
    442  1.25   thorpej     int const func)
    443  1.25   thorpej {
    444  1.25   thorpej 	KASSERT(pc->pc_make_tag != NULL);
    445  1.25   thorpej 	return pc->pc_make_tag(pc->pc_conf_v, bus, dev, func);
    446  1.25   thorpej }
    447  1.25   thorpej 
    448  1.25   thorpej void
    449  1.25   thorpej pci_decompose_tag(pci_chipset_tag_t const pc, pcitag_t const tag,
    450  1.25   thorpej     int * const busp, int * const devp, int * const funcp)
    451  1.25   thorpej {
    452  1.25   thorpej 	KASSERT(pc->pc_decompose_tag != NULL);
    453  1.25   thorpej 	pc->pc_decompose_tag(pc->pc_conf_v, tag, busp, devp, funcp);
    454  1.25   thorpej }
    455  1.25   thorpej 
    456  1.25   thorpej pcireg_t
    457  1.25   thorpej pci_conf_read(pci_chipset_tag_t const pc, pcitag_t const tag, int const reg)
    458  1.25   thorpej {
    459  1.25   thorpej 	KASSERT(pc->pc_conf_read != NULL);
    460  1.25   thorpej 	return pc->pc_conf_read(pc->pc_conf_v, tag, reg);
    461  1.25   thorpej }
    462  1.25   thorpej 
    463  1.25   thorpej void
    464  1.25   thorpej pci_conf_write(pci_chipset_tag_t const pc, pcitag_t const tag, int const reg,
    465  1.25   thorpej     pcireg_t const val)
    466  1.25   thorpej {
    467  1.25   thorpej 	KASSERT(pc->pc_conf_write != NULL);
    468  1.25   thorpej 	pc->pc_conf_write(pc->pc_conf_v, tag, reg, val);
    469  1.25   thorpej }
    470  1.25   thorpej 
    471  1.25   thorpej int
    472  1.25   thorpej pci_intr_map(const struct pci_attach_args * const pa,
    473  1.25   thorpej     pci_intr_handle_t * const ihp)
    474  1.25   thorpej {
    475  1.25   thorpej 	pci_chipset_tag_t const pc = pa->pa_pc;
    476  1.25   thorpej 
    477  1.25   thorpej 	KASSERT(pc->pc_intr_map != NULL);
    478  1.25   thorpej 	return pc->pc_intr_map(pa, ihp);
    479  1.25   thorpej }
    480  1.25   thorpej 
    481  1.25   thorpej const char *
    482  1.25   thorpej pci_intr_string(pci_chipset_tag_t const pc, pci_intr_handle_t const ih,
    483  1.25   thorpej     char * const buf, size_t const len)
    484  1.25   thorpej {
    485  1.25   thorpej 	KASSERT(pc->pc_intr_string != NULL);
    486  1.25   thorpej 	return pc->pc_intr_string(pc, ih, buf, len);
    487  1.25   thorpej }
    488  1.25   thorpej 
    489  1.25   thorpej const struct evcnt *
    490  1.25   thorpej pci_intr_evcnt(pci_chipset_tag_t const pc, pci_intr_handle_t const ih)
    491  1.25   thorpej {
    492  1.25   thorpej 	KASSERT(pc->pc_intr_evcnt != NULL);
    493  1.25   thorpej 	return pc->pc_intr_evcnt(pc, ih);
    494  1.25   thorpej }
    495  1.25   thorpej 
    496  1.25   thorpej void *
    497  1.25   thorpej pci_intr_establish(pci_chipset_tag_t const pc, pci_intr_handle_t const ih,
    498  1.25   thorpej     int const ipl, int (*func)(void *), void *arg)
    499  1.25   thorpej {
    500  1.25   thorpej 	KASSERT(pc->pc_intr_establish != NULL);
    501  1.25   thorpej 	return pc->pc_intr_establish(pc, ih, ipl, func, arg);
    502  1.25   thorpej }
    503  1.25   thorpej 
    504  1.25   thorpej void
    505  1.25   thorpej pci_intr_disestablish(pci_chipset_tag_t const pc, void * const cookie)
    506  1.25   thorpej {
    507  1.25   thorpej 	KASSERT(pc->pc_intr_disestablish != NULL);
    508  1.25   thorpej 	pc->pc_intr_disestablish(pc, cookie);
    509  1.25   thorpej }
    510  1.25   thorpej 
    511  1.25   thorpej int
    512  1.25   thorpej pci_intr_setattr(pci_chipset_tag_t const pc __unused,
    513  1.25   thorpej     pci_intr_handle_t * const ihp, int const attr, uint64_t const data)
    514  1.25   thorpej {
    515  1.25   thorpej 	u_int flags = alpha_pci_intr_handle_get_flags(ihp);
    516  1.25   thorpej 
    517  1.25   thorpej 	switch (attr) {
    518  1.25   thorpej 	case PCI_INTR_MPSAFE:
    519  1.25   thorpej 		if (data)
    520  1.25   thorpej 			flags |= ALPHA_INTR_MPSAFE;
    521  1.25   thorpej 		else
    522  1.25   thorpej 			flags &= ~ALPHA_INTR_MPSAFE;
    523  1.25   thorpej 		break;
    524  1.25   thorpej 
    525  1.25   thorpej 	default:
    526  1.25   thorpej 		return ENODEV;
    527  1.25   thorpej 	}
    528  1.25   thorpej 
    529  1.25   thorpej 	alpha_pci_intr_handle_set_flags(ihp, flags);
    530  1.25   thorpej 	return 0;
    531  1.25   thorpej }
    532