xref: /openbsd-src/sys/arch/alpha/pci/pci_machdep.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: pci_machdep.c,v 1.20 2015/07/26 05:09:44 miod Exp $	*/
2 /*	$NetBSD: pci_machdep.c,v 1.7 1996/11/19 04:57:32 cgd Exp $	*/
3 
4 /*
5  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
6  * All rights reserved.
7  *
8  * Author: Chris G. Demetriou
9  *
10  * Permission to use, copy, modify and distribute this software and
11  * its documentation is hereby granted, provided that both the copyright
12  * notice and this permission notice appear in all copies of the
13  * software, derivative works or modified versions, and any portions
14  * thereof, and that both notices appear in supporting documentation.
15  *
16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19  *
20  * Carnegie Mellon requests users of this software to return to
21  *
22  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23  *  School of Computer Science
24  *  Carnegie Mellon University
25  *  Pittsburgh PA 15213-3890
26  *
27  * any improvements or extensions that they make and grant Carnegie the
28  * rights to redistribute these changes.
29  */
30 
31 /*
32  * Machine-specific functions for PCI autoconfiguration.
33  */
34 
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/time.h>
38 #include <sys/systm.h>
39 #include <sys/proc.h>
40 #include <sys/sysctl.h>
41 #include <sys/errno.h>
42 #include <sys/device.h>
43 #include <uvm/uvm_extern.h>
44 #include <machine/cpu.h>
45 
46 #include <dev/isa/isavar.h>
47 #include <dev/pci/pcireg.h>
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pcidevs.h>
50 #include <dev/pci/ppbreg.h>
51 
52 #include "vga.h"
53 #if NVGA_PCI
54 #include <dev/pci/vga_pcivar.h>
55 #endif
56 
57 #include "tga.h"
58 #if NTGA
59 #include <dev/pci/tgavar.h>
60 #endif
61 
62 struct alpha_pci_chipset *alpha_pci_chipset;
63 
64 void
65 pci_display_console(iot, memt, pc, bus, device, function)
66 	bus_space_tag_t iot, memt;
67 	pci_chipset_tag_t pc;
68 	int bus, device, function;
69 {
70 	pcitag_t tag;
71 	pcireg_t id, class;
72 	int match;
73 #if NVGA_PCI || NTGA
74 	int nmatch;
75 #endif
76 	int (*fn)(bus_space_tag_t, bus_space_tag_t, pci_chipset_tag_t,
77 	    int, int, int);
78 
79 	tag = pci_make_tag(pc, bus, device, function);
80 	id = pci_conf_read(pc, tag, PCI_ID_REG);
81 	if (id == 0 || id == 0xffffffff)
82 		panic("pci_display_console: no device at %d/%d/%d",
83 		    bus, device, function);
84 	class = pci_conf_read(pc, tag, PCI_CLASS_REG);
85 
86 	match = 0;
87 	fn = NULL;
88 
89 #if NVGA_PCI
90 	nmatch = DEVICE_IS_VGA_PCI(class);
91 	if (nmatch > match) {
92 		match = nmatch;
93 		fn = vga_pci_cnattach;
94 	}
95 #endif
96 #if NTGA
97 	nmatch = DEVICE_IS_TGA(class, id);
98 	if (nmatch > match) {
99 		match = nmatch;
100 		fn = tga_cnattach;
101 	}
102 #endif
103 
104 	if (fn != NULL)
105 		(*fn)(iot, memt, pc, bus, device, function);
106 	else
107 		panic("pci_display_console: unconfigured device at %d/%d/%d",
108 		    bus, device, function);
109 }
110 
111 int
112 alpha_sysctl_chipset(int *name, u_int namelen, char *where, size_t *sizep)
113 {
114 	if (namelen != 1)
115 		return (ENOTDIR);
116 
117 	if (alpha_pci_chipset == NULL)
118 		return (EOPNOTSUPP);
119 
120 	switch (name[0]) {
121 	case CPU_CHIPSET_TYPE:
122 		return (sysctl_rdstring(where, sizep, NULL,
123 		    alpha_pci_chipset->pc_name));
124 	case CPU_CHIPSET_BWX:
125 		return (sysctl_rdint(where, sizep, NULL,
126 		    alpha_pci_chipset->pc_bwx));
127 	case CPU_CHIPSET_MEM:
128 		return (sysctl_rdquad(where, sizep, NULL,
129 		    alpha_pci_chipset->pc_mem));
130 	case CPU_CHIPSET_DENSE:
131 		return (sysctl_rdquad(where, sizep, NULL,
132 		    alpha_pci_chipset->pc_dense));
133 	case CPU_CHIPSET_PORTS:
134 		return (sysctl_rdquad(where, sizep, NULL,
135 		    alpha_pci_chipset->pc_ports));
136 	case CPU_CHIPSET_HAE_MASK:
137 		return (sysctl_rdquad(where, sizep, NULL,
138 		    alpha_pci_chipset->pc_hae_mask));
139 	default:
140 		return (EOPNOTSUPP);
141 	}
142 	/* NOTREACHED */
143 }
144 
145 int
146 pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
147 {
148 	if (pa->pa_intrpin == 0)	/* No IRQ used. */
149 		return 1;
150 
151 	if (!(1 <= pa->pa_intrpin && pa->pa_intrpin <= 4))
152 		return 1;
153 
154 	return (*(pa->pa_pc)->pc_intr_map)(pa, ihp);
155 }
156