1/* $NetBSD: vga_isa.c,v 1.22 2022/09/25 17:09:36 thorpej 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@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#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: vga_isa.c,v 1.22 2022/09/25 17:09:36 thorpej Exp $");
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/device.h>
37
38#include <dev/isa/isavar.h>
39
40#include <dev/ic/mc6845reg.h>
41#include <dev/ic/pcdisplayvar.h>
42#include <dev/ic/vgareg.h>
43#include <dev/ic/vgavar.h>
44#include <dev/isa/vga_isavar.h>
45
46#include <dev/wscons/wsconsio.h>
47#include <dev/wscons/wsdisplayvar.h>
48
49int	vga_isa_match(device_t, cfdata_t, void *);
50void	vga_isa_attach(device_t, device_t, void *);
51
52CFATTACH_DECL_NEW(vga_isa, sizeof(struct vga_softc),
53    vga_isa_match, vga_isa_attach, NULL, NULL);
54
55int
56vga_isa_match(device_t parent, cfdata_t match, void *aux)
57{
58	struct isa_attach_args *ia = aux;
59
60	if (ISA_DIRECT_CONFIG(ia))
61		return (0);
62
63	/* If values are hardwired to something that they can't be, punt. */
64	if (ia->ia_nio < 1 ||
65	    (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
66	     ia->ia_io[0].ir_addr != 0x3b0))
67		return (0);
68
69	if (ia->ia_niomem < 1 ||
70	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM &&
71	     ia->ia_iomem[0].ir_addr != 0xa0000))
72		return (0);
73	if (ia->ia_iomem[0].ir_size != 0 &&
74	    ia->ia_iomem[0].ir_size != 0x20000)
75		return (0);
76
77	if (ia->ia_nirq > 0 &&
78	    ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ)
79		return (0);
80
81	if (ia->ia_ndrq > 0 &&
82	    ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ)
83		return (0);
84
85	if (!vga_is_console(ia->ia_iot, WSDISPLAY_TYPE_ISAVGA) &&
86	    !vga_common_probe(ia->ia_iot, ia->ia_memt))
87		return (0);
88
89	ia->ia_nio = 1;
90	ia->ia_io[0].ir_addr = 0x3b0;	/* XXX mono 0x3b0 color 0x3c0 */
91	ia->ia_io[0].ir_size = 0x30;	/* XXX 0x20 */
92
93	ia->ia_niomem = 1;
94	ia->ia_iomem[0].ir_addr = 0xa0000;
95	ia->ia_iomem[0].ir_size = 0x20000;
96
97	ia->ia_nirq = 0;
98	ia->ia_ndrq = 0;
99
100	return (2);	/* more than generic pcdisplay */
101}
102
103void
104vga_isa_attach(device_t parent, device_t self, void *aux)
105{
106	struct vga_softc *sc = device_private(self);
107	struct isa_attach_args *ia = aux;
108
109	sc->sc_dev = self;
110	aprint_normal("\n");
111
112	vga_common_attach(sc, ia->ia_iot, ia->ia_memt, WSDISPLAY_TYPE_ISAVGA,
113	    0, NULL);
114}
115
116int
117vga_isa_cnattach(bus_space_tag_t iot, bus_space_tag_t memt)
118{
119
120	return (vga_cnattach(iot, memt, WSDISPLAY_TYPE_ISAVGA, 1));
121}
122