132580301SAttilio Rao /*-
24d846d26SWarner Losh * SPDX-License-Identifier: (BSD-2-Clause AND ISC)
3ebf5747bSPedro F. Giffuni *
432580301SAttilio Rao * Copyright (c) 1998 Doug Rabson
532580301SAttilio Rao * All rights reserved.
632580301SAttilio Rao *
732580301SAttilio Rao * Redistribution and use in source and binary forms, with or without
832580301SAttilio Rao * modification, are permitted provided that the following conditions
932580301SAttilio Rao * are met:
1032580301SAttilio Rao * 1. Redistributions of source code must retain the above copyright
1132580301SAttilio Rao * notice, this list of conditions and the following disclaimer.
1232580301SAttilio Rao * 2. Redistributions in binary form must reproduce the above copyright
1332580301SAttilio Rao * notice, this list of conditions and the following disclaimer in the
1432580301SAttilio Rao * documentation and/or other materials provided with the distribution.
1532580301SAttilio Rao *
1632580301SAttilio Rao * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1732580301SAttilio Rao * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1832580301SAttilio Rao * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1932580301SAttilio Rao * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2032580301SAttilio Rao * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2132580301SAttilio Rao * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2232580301SAttilio Rao * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2332580301SAttilio Rao * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2432580301SAttilio Rao * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2532580301SAttilio Rao * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2632580301SAttilio Rao * SUCH DAMAGE.
2732580301SAttilio Rao */
2832580301SAttilio Rao
2932580301SAttilio Rao #include <sys/cdefs.h>
3032580301SAttilio Rao /*-
3132580301SAttilio Rao * Modifications for Intel architecture by Garrett A. Wollman.
3232580301SAttilio Rao * Copyright 1998 Massachusetts Institute of Technology
3332580301SAttilio Rao *
3432580301SAttilio Rao * Permission to use, copy, modify, and distribute this software and
3532580301SAttilio Rao * its documentation for any purpose and without fee is hereby
3632580301SAttilio Rao * granted, provided that both the above copyright notice and this
3732580301SAttilio Rao * permission notice appear in all copies, that both the above
3832580301SAttilio Rao * copyright notice and this permission notice appear in all
3932580301SAttilio Rao * supporting documentation, and that the name of M.I.T. not be used
4032580301SAttilio Rao * in advertising or publicity pertaining to distribution of the
4132580301SAttilio Rao * software without specific, written prior permission. M.I.T. makes
4232580301SAttilio Rao * no representations about the suitability of this software for any
4332580301SAttilio Rao * purpose. It is provided "as is" without express or implied
4432580301SAttilio Rao * warranty.
4532580301SAttilio Rao *
4632580301SAttilio Rao * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
4732580301SAttilio Rao * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
4832580301SAttilio Rao * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
4932580301SAttilio Rao * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
5032580301SAttilio Rao * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5132580301SAttilio Rao * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5232580301SAttilio Rao * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
5332580301SAttilio Rao * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5432580301SAttilio Rao * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5532580301SAttilio Rao * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
5632580301SAttilio Rao * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5732580301SAttilio Rao * SUCH DAMAGE.
5832580301SAttilio Rao */
5932580301SAttilio Rao
6032580301SAttilio Rao #include <sys/param.h>
6132580301SAttilio Rao #include <sys/bus.h>
6232580301SAttilio Rao #include <sys/kernel.h>
6332580301SAttilio Rao #include <sys/malloc.h>
6432580301SAttilio Rao #include <sys/module.h>
6532580301SAttilio Rao #include <machine/bus.h>
6632580301SAttilio Rao #include <sys/rman.h>
6732580301SAttilio Rao
6832580301SAttilio Rao #include <machine/resource.h>
6932580301SAttilio Rao
7032580301SAttilio Rao #include <isa/isavar.h>
7132580301SAttilio Rao #include <isa/isa_common.h>
7232580301SAttilio Rao
7332580301SAttilio Rao void
isa_init(device_t dev)7432580301SAttilio Rao isa_init(device_t dev)
7532580301SAttilio Rao {
7632580301SAttilio Rao }
7732580301SAttilio Rao
7832580301SAttilio Rao /*
7932580301SAttilio Rao * This implementation simply passes the request up to the parent
8032580301SAttilio Rao * bus, which in our case is the special i386 nexus, substituting any
8132580301SAttilio Rao * configured values if the caller defaulted. We can get away with
8232580301SAttilio Rao * this because there is no special mapping for ISA resources on an Intel
8332580301SAttilio Rao * platform. When porting this code to another architecture, it may be
8432580301SAttilio Rao * necessary to interpose a mapping layer here.
8532580301SAttilio Rao */
8632580301SAttilio Rao struct resource *
isa_alloc_resource(device_t bus,device_t child,int type,int * rid,rman_res_t start,rman_res_t end,rman_res_t count,u_int flags)8732580301SAttilio Rao isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
882dd1bdf1SJustin Hibbits rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
8932580301SAttilio Rao {
9032580301SAttilio Rao /*
9132580301SAttilio Rao * Consider adding a resource definition.
9232580301SAttilio Rao */
9332580301SAttilio Rao int passthrough = (device_get_parent(child) != bus);
947915adb5SJustin Hibbits int isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
9532580301SAttilio Rao struct isa_device* idev = DEVTOISA(child);
9632580301SAttilio Rao struct resource_list *rl = &idev->id_resources;
9732580301SAttilio Rao struct resource_list_entry *rle;
9832580301SAttilio Rao
9932580301SAttilio Rao if (!passthrough && !isdefault) {
10032580301SAttilio Rao rle = resource_list_find(rl, type, *rid);
10132580301SAttilio Rao if (!rle) {
10232580301SAttilio Rao if (*rid < 0)
10332580301SAttilio Rao return 0;
10432580301SAttilio Rao switch (type) {
10532580301SAttilio Rao case SYS_RES_IRQ:
10632580301SAttilio Rao if (*rid >= ISA_NIRQ)
10732580301SAttilio Rao return 0;
10832580301SAttilio Rao break;
10932580301SAttilio Rao case SYS_RES_DRQ:
11032580301SAttilio Rao if (*rid >= ISA_NDRQ)
11132580301SAttilio Rao return 0;
11232580301SAttilio Rao break;
11332580301SAttilio Rao case SYS_RES_MEMORY:
11432580301SAttilio Rao if (*rid >= ISA_NMEM)
11532580301SAttilio Rao return 0;
11632580301SAttilio Rao break;
11732580301SAttilio Rao case SYS_RES_IOPORT:
11832580301SAttilio Rao if (*rid >= ISA_NPORT)
11932580301SAttilio Rao return 0;
12032580301SAttilio Rao break;
12132580301SAttilio Rao default:
12232580301SAttilio Rao return 0;
12332580301SAttilio Rao }
12432580301SAttilio Rao resource_list_add(rl, type, *rid, start, end, count);
12532580301SAttilio Rao }
12632580301SAttilio Rao }
12732580301SAttilio Rao
12832580301SAttilio Rao return resource_list_alloc(rl, bus, child, type, rid,
12932580301SAttilio Rao start, end, count, flags);
13032580301SAttilio Rao }
13132580301SAttilio Rao
13232580301SAttilio Rao int
isa_release_resource(device_t bus,device_t child,struct resource * r)133*9dbf5b0eSJohn Baldwin isa_release_resource(device_t bus, device_t child, struct resource *r)
13432580301SAttilio Rao {
13532580301SAttilio Rao struct isa_device* idev = DEVTOISA(child);
13632580301SAttilio Rao struct resource_list *rl = &idev->id_resources;
13732580301SAttilio Rao
138*9dbf5b0eSJohn Baldwin return resource_list_release(rl, bus, child, r);
13932580301SAttilio Rao }
14032580301SAttilio Rao
14132580301SAttilio Rao /*
14232580301SAttilio Rao * On this platform, isa can also attach to the legacy bus.
14332580301SAttilio Rao */
14409fd3b43SJohn Baldwin DRIVER_MODULE(isa, legacy, isa_driver, 0, 0);
14579cd455eSRoger Pau Monné
14679cd455eSRoger Pau Monné /*
14779cd455eSRoger Pau Monné * Attach the ISA bus to the xenpv bus in order to get syscons.
14879cd455eSRoger Pau Monné */
14909fd3b43SJohn Baldwin DRIVER_MODULE(isa, xenpv, isa_driver, 0, 0);
150