pci_machdep.c revision 1.19.6.2 1 /* $NetBSD: pci_machdep.c,v 1.19.6.2 2017/12/03 11:35:46 jdolecek Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 /*
31 * Machine-specific functions for PCI autoconfiguration.
32 */
33
34 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
35
36 __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.19.6.2 2017/12/03 11:35:46 jdolecek Exp $");
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/time.h>
41 #include <sys/systm.h>
42 #include <sys/errno.h>
43 #include <sys/device.h>
44
45 #include <dev/isa/isavar.h>
46 #include <dev/pci/pcireg.h>
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/pcidevs.h>
49
50 #include "vga_pci.h"
51 #if NVGA_PCI
52 #include <dev/ic/mc6845reg.h>
53 #include <dev/ic/pcdisplayvar.h>
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 #include <machine/rpb.h>
63
64 void
65 pci_display_console(bus_space_tag_t iot, bus_space_tag_t memt, pci_chipset_tag_t pc, int bus, int device, int function)
66 {
67 #if NVGA_PCI || NTGA
68 pcitag_t tag;
69 pcireg_t id, class;
70 int match, nmatch;
71 #endif
72 int (*fn)(bus_space_tag_t, bus_space_tag_t, pci_chipset_tag_t,
73 int, int, int);
74
75 #if NVGA_PCI || NTGA
76 tag = pci_make_tag(pc, bus, device, function);
77 id = pci_conf_read(pc, tag, PCI_ID_REG);
78 if (id == 0 || id == 0xffffffff)
79 panic("pci_display_console: no device at %d/%d/%d",
80 bus, device, function);
81 class = pci_conf_read(pc, tag, PCI_CLASS_REG);
82
83 match = 0;
84 #endif
85 fn = NULL;
86
87 #if NVGA_PCI
88 nmatch = DEVICE_IS_VGA_PCI(class, id);
89 if (nmatch > match) {
90 match = nmatch;
91 fn = vga_pci_cnattach;
92 }
93 #endif
94 #if NTGA
95 nmatch = DEVICE_IS_TGA(class, id);
96 if (nmatch > match)
97 nmatch = tga_cnmatch(iot, memt, pc, tag);
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 void
112 device_pci_register(device_t dev, void *aux)
113 {
114 struct pci_attach_args *pa = aux;
115 struct ctb *ctb;
116 prop_dictionary_t dict;
117
118 /* set properties for PCI framebuffers */
119 ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off);
120 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
121 ctb->ctb_term_type == CTB_GRAPHICS) {
122 /* XXX should consider multiple displays? */
123 dict = device_properties(dev);
124 prop_dictionary_set_bool(dict, "is_console", true);
125 }
126 }
127