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