intio.c revision 1.14.58.1 1 1.14.58.1 martin /* $NetBSD: intio.c,v 1.14.58.1 2023/02/15 19:28:29 martin Exp $ */
2 1.1 dbj
3 1.1 dbj /*-
4 1.1 dbj * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 dbj * All rights reserved.
6 1.1 dbj *
7 1.1 dbj * This code is derived from software contributed to The NetBSD Foundation
8 1.1 dbj * by Jason R. Thorpe.
9 1.1 dbj *
10 1.1 dbj * Redistribution and use in source and binary forms, with or without
11 1.1 dbj * modification, are permitted provided that the following conditions
12 1.1 dbj * are met:
13 1.1 dbj * 1. Redistributions of source code must retain the above copyright
14 1.1 dbj * notice, this list of conditions and the following disclaimer.
15 1.1 dbj * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 dbj * notice, this list of conditions and the following disclaimer in the
17 1.1 dbj * documentation and/or other materials provided with the distribution.
18 1.1 dbj *
19 1.1 dbj * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 dbj * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 dbj * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 dbj * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 dbj * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 dbj * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 dbj * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 dbj * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 dbj * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 dbj * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 dbj * POSSIBILITY OF SUCH DAMAGE.
30 1.1 dbj */
31 1.1 dbj
32 1.1 dbj /*
33 1.1 dbj * Autoconfiguration support for next68k internal i/o space.
34 1.1 dbj */
35 1.8 lukem
36 1.8 lukem #include <sys/cdefs.h>
37 1.14.58.1 martin __KERNEL_RCSID(0, "$NetBSD: intio.c,v 1.14.58.1 2023/02/15 19:28:29 martin Exp $");
38 1.1 dbj
39 1.1 dbj #include <sys/param.h>
40 1.1 dbj #include <sys/systm.h>
41 1.14.58.1 martin #include <sys/device.h>
42 1.3 mycroft #include <sys/reboot.h>
43 1.3 mycroft
44 1.3 mycroft #include <machine/autoconf.h>
45 1.14.58.1 martin #include <machine/cpu.h>
46 1.3 mycroft
47 1.1 dbj #include <next68k/dev/intiovar.h>
48 1.1 dbj
49 1.14 matt int intiomatch(device_t, cfdata_t, void *);
50 1.14 matt void intioattach(device_t, device_t, void *);
51 1.9 chs int intioprint(void *, const char *);
52 1.14 matt int intiosearch(device_t, cfdata_t, const int *, void *);
53 1.1 dbj
54 1.14 matt CFATTACH_DECL_NEW(intio, 0,
55 1.6 thorpej intiomatch, intioattach, NULL, NULL);
56 1.1 dbj
57 1.14 matt static bool intio_attached;
58 1.3 mycroft
59 1.1 dbj int
60 1.14 matt intiomatch(device_t parent, cfdata_t match, void *aux)
61 1.1 dbj {
62 1.1 dbj /* Allow only one instance. */
63 1.3 mycroft if (intio_attached)
64 1.14.58.1 martin return 0;
65 1.1 dbj
66 1.14.58.1 martin return 1;
67 1.1 dbj }
68 1.1 dbj
69 1.1 dbj void
70 1.14 matt intioattach(device_t parent, device_t self, void *aux)
71 1.1 dbj {
72 1.1 dbj
73 1.1 dbj printf("\n");
74 1.1 dbj
75 1.1 dbj /* Search for and attach children. */
76 1.10 drochner config_search_ia(intiosearch, self, "intio", aux);
77 1.3 mycroft
78 1.14 matt intio_attached = true;
79 1.1 dbj }
80 1.1 dbj
81 1.1 dbj int
82 1.9 chs intioprint(void *aux, const char *pnp)
83 1.1 dbj {
84 1.1 dbj struct intio_attach_args *ia = aux;
85 1.1 dbj
86 1.7 thorpej if (ia->ia_addr)
87 1.7 thorpej aprint_normal(" addr %p", ia->ia_addr);
88 1.3 mycroft
89 1.14.58.1 martin return UNCONF;
90 1.1 dbj }
91 1.1 dbj
92 1.1 dbj int
93 1.14 matt intiosearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
94 1.1 dbj {
95 1.14.58.1 martin struct mainbus_attach_args *mba = aux;
96 1.1 dbj struct intio_attach_args ia;
97 1.1 dbj
98 1.3 mycroft do {
99 1.3 mycroft ia.ia_addr = NULL;
100 1.3 mycroft ia.ia_bst = NEXT68K_INTIO_BUS_SPACE;
101 1.3 mycroft ia.ia_dmat = mba->mba_dmat;
102 1.14.58.1 martin
103 1.4 thorpej if (config_match(parent, cf, &ia) == 0)
104 1.3 mycroft break;
105 1.2 dbj config_attach(parent, cf, &ia, intioprint);
106 1.3 mycroft } while (cf->cf_fstate == FSTATE_STAR);
107 1.3 mycroft
108 1.14.58.1 martin return 0;
109 1.14.58.1 martin }
110 1.14.58.1 martin
111 1.14.58.1 martin int
112 1.14.58.1 martin bus_space_map(bus_space_tag_t bst, bus_addr_t addr, bus_size_t size,
113 1.14.58.1 martin int flags, bus_space_handle_t *bsh)
114 1.14.58.1 martin {
115 1.14.58.1 martin
116 1.14.58.1 martin if (addr >= INTIOBASE && (addr + size) < INTIOTOP) {
117 1.14.58.1 martin *bsh = IIOV(addr);
118 1.14.58.1 martin return 0;
119 1.14.58.1 martin }
120 1.14.58.1 martin
121 1.14.58.1 martin return EINVAL;
122 1.14.58.1 martin }
123 1.14.58.1 martin
124 1.14.58.1 martin paddr_t
125 1.14.58.1 martin bus_space_mmap(bus_space_tag_t bst, bus_addr_t addr, off_t offset, int prot,
126 1.14.58.1 martin int flags)
127 1.14.58.1 martin {
128 1.14.58.1 martin
129 1.14.58.1 martin if (addr >= INTIOBASE && (addr + offset) < INTIOTOP)
130 1.14.58.1 martin return m68k_btop(addr + offset);
131 1.14.58.1 martin
132 1.14.58.1 martin return -1;
133 1.1 dbj }
134