xref: /freebsd/sys/x86/isa/isa.c (revision 4fe1295c964fa712dd763e3852187da8724ef79a)
1 /*-
2  * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND ISC)
3  *
4  * Copyright (c) 1998 Doug Rabson
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 
32 /*-
33  * Modifications for Intel architecture by Garrett A. Wollman.
34  * Copyright 1998 Massachusetts Institute of Technology
35  *
36  * Permission to use, copy, modify, and distribute this software and
37  * its documentation for any purpose and without fee is hereby
38  * granted, provided that both the above copyright notice and this
39  * permission notice appear in all copies, that both the above
40  * copyright notice and this permission notice appear in all
41  * supporting documentation, and that the name of M.I.T. not be used
42  * in advertising or publicity pertaining to distribution of the
43  * software without specific, written prior permission.  M.I.T. makes
44  * no representations about the suitability of this software for any
45  * purpose.  It is provided "as is" without express or implied
46  * warranty.
47  *
48  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
49  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
50  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
51  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
52  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
55  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
56  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
57  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
58  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59  * SUCH DAMAGE.
60  */
61 
62 #include <sys/param.h>
63 #include <sys/bus.h>
64 #include <sys/kernel.h>
65 #include <sys/malloc.h>
66 #include <sys/module.h>
67 #include <machine/bus.h>
68 #include <sys/rman.h>
69 
70 #include <machine/resource.h>
71 
72 #include <isa/isavar.h>
73 #include <isa/isa_common.h>
74 
75 void
76 isa_init(device_t dev)
77 {
78 }
79 
80 /*
81  * This implementation simply passes the request up to the parent
82  * bus, which in our case is the special i386 nexus, substituting any
83  * configured values if the caller defaulted.  We can get away with
84  * this because there is no special mapping for ISA resources on an Intel
85  * platform.  When porting this code to another architecture, it may be
86  * necessary to interpose a mapping layer here.
87  */
88 struct resource *
89 isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
90 		   rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
91 {
92 	/*
93 	 * Consider adding a resource definition.
94 	 */
95 	int passthrough = (device_get_parent(child) != bus);
96 	int isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
97 	struct isa_device* idev = DEVTOISA(child);
98 	struct resource_list *rl = &idev->id_resources;
99 	struct resource_list_entry *rle;
100 
101 	if (!passthrough && !isdefault) {
102 		rle = resource_list_find(rl, type, *rid);
103 		if (!rle) {
104 			if (*rid < 0)
105 				return 0;
106 			switch (type) {
107 			case SYS_RES_IRQ:
108 				if (*rid >= ISA_NIRQ)
109 					return 0;
110 				break;
111 			case SYS_RES_DRQ:
112 				if (*rid >= ISA_NDRQ)
113 					return 0;
114 				break;
115 			case SYS_RES_MEMORY:
116 				if (*rid >= ISA_NMEM)
117 					return 0;
118 				break;
119 			case SYS_RES_IOPORT:
120 				if (*rid >= ISA_NPORT)
121 					return 0;
122 				break;
123 			default:
124 				return 0;
125 			}
126 			resource_list_add(rl, type, *rid, start, end, count);
127 		}
128 	}
129 
130 	return resource_list_alloc(rl, bus, child, type, rid,
131 				   start, end, count, flags);
132 }
133 
134 int
135 isa_release_resource(device_t bus, device_t child, int type, int rid,
136 		     struct resource *r)
137 {
138 	struct isa_device* idev = DEVTOISA(child);
139 	struct resource_list *rl = &idev->id_resources;
140 
141 	return resource_list_release(rl, bus, child, type, rid, r);
142 }
143 
144 /*
145  * On this platform, isa can also attach to the legacy bus.
146  */
147 DRIVER_MODULE(isa, legacy, isa_driver, 0, 0);
148 
149 /*
150  * Attach the ISA bus to the xenpv bus in order to get syscons.
151  */
152 DRIVER_MODULE(isa, xenpv, isa_driver, 0, 0);
153