1993-06-12 14:58:17 +00:00
|
|
|
/*-
|
1999-04-16 21:22:55 +00:00
|
|
|
* Copyright (c) 1998 Doug Rabson
|
1993-06-12 14:58:17 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
1999-04-16 21:22:55 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
1993-06-12 14:58:17 +00:00
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
1999-04-16 21:22:55 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1993-06-12 14:58:17 +00:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-02 16:32:55 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2005-01-06 22:18:23 +00:00
|
|
|
/*-
|
1999-04-16 21:22:55 +00:00
|
|
|
* Modifications for Intel architecture by Garrett A. Wollman.
|
|
|
|
* Copyright 1998 Massachusetts Institute of Technology
|
1993-06-12 14:58:17 +00:00
|
|
|
*
|
1999-04-16 21:22:55 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software and
|
|
|
|
* its documentation for any purpose and without fee is hereby
|
|
|
|
* granted, provided that both the above copyright notice and this
|
|
|
|
* permission notice appear in all copies, that both the above
|
|
|
|
* copyright notice and this permission notice appear in all
|
|
|
|
* supporting documentation, and that the name of M.I.T. not be used
|
|
|
|
* in advertising or publicity pertaining to distribution of the
|
|
|
|
* software without specific, written prior permission. M.I.T. makes
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied
|
|
|
|
* warranty.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
|
|
|
|
* ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
|
|
|
|
* SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/param.h>
|
1999-04-16 21:22:55 +00:00
|
|
|
#include <sys/bus.h>
|
2004-12-24 23:03:17 +00:00
|
|
|
#include <sys/kernel.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/malloc.h>
|
2004-12-24 23:03:17 +00:00
|
|
|
#include <sys/module.h>
|
1999-04-16 21:22:55 +00:00
|
|
|
#include <machine/bus.h>
|
2000-03-29 03:15:22 +00:00
|
|
|
#include <sys/rman.h>
|
2002-02-10 10:16:22 +00:00
|
|
|
#ifdef PC98
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#endif
|
1997-09-19 15:20:25 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
#include <machine/resource.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
#include <isa/isavar.h>
|
1999-05-22 15:18:28 +00:00
|
|
|
#include <isa/isa_common.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1999-05-22 15:18:28 +00:00
|
|
|
void
|
2001-12-21 21:54:56 +00:00
|
|
|
isa_init(device_t dev)
|
1996-01-27 02:33:48 +00:00
|
|
|
{
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-04-16 21:22:55 +00:00
|
|
|
* This implementation simply passes the request up to the parent
|
|
|
|
* bus, which in our case is the special i386 nexus, substituting any
|
|
|
|
* configured values if the caller defaulted. We can get away with
|
|
|
|
* this because there is no special mapping for ISA resources on an Intel
|
|
|
|
* platform. When porting this code to another architecture, it may be
|
|
|
|
* necessary to interpose a mapping layer here.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
1999-05-22 15:18:28 +00:00
|
|
|
struct resource *
|
1999-04-16 21:22:55 +00:00
|
|
|
isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
1996-04-08 19:38:57 +00:00
|
|
|
{
|
1999-04-16 21:22:55 +00:00
|
|
|
/*
|
2004-03-17 19:04:58 +00:00
|
|
|
* Consider adding a resource definition.
|
1999-04-16 21:22:55 +00:00
|
|
|
*/
|
1999-05-22 15:18:28 +00:00
|
|
|
int passthrough = (device_get_parent(child) != bus);
|
|
|
|
int isdefault = (start == 0UL && end == ~0UL);
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
struct isa_device* idev = DEVTOISA(child);
|
|
|
|
struct resource_list *rl = &idev->id_resources;
|
1999-05-22 15:18:28 +00:00
|
|
|
struct resource_list_entry *rle;
|
|
|
|
|
|
|
|
if (!passthrough && !isdefault) {
|
|
|
|
rle = resource_list_find(rl, type, *rid);
|
|
|
|
if (!rle) {
|
|
|
|
if (*rid < 0)
|
|
|
|
return 0;
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
switch (type) {
|
|
|
|
case SYS_RES_IRQ:
|
|
|
|
if (*rid >= ISA_NIRQ)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case SYS_RES_DRQ:
|
|
|
|
if (*rid >= ISA_NDRQ)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case SYS_RES_MEMORY:
|
|
|
|
if (*rid >= ISA_NMEM)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case SYS_RES_IOPORT:
|
|
|
|
if (*rid >= ISA_NPORT)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
default:
|
1999-05-22 15:18:28 +00:00
|
|
|
return 0;
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
}
|
1999-05-22 15:18:28 +00:00
|
|
|
resource_list_add(rl, type, *rid, start, end, count);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1999-05-22 15:18:28 +00:00
|
|
|
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
return resource_list_alloc(rl, bus, child, type, rid,
|
1999-05-22 15:18:28 +00:00
|
|
|
start, end, count, flags);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
2000-03-29 03:15:22 +00:00
|
|
|
#ifdef PC98
|
|
|
|
/*
|
|
|
|
* Indirection support. The type of bus_space_handle_t is
|
|
|
|
* defined in sys/i386/include/bus_pc98.h.
|
|
|
|
*/
|
|
|
|
struct resource *
|
|
|
|
isa_alloc_resourcev(device_t child, int type, int *rid,
|
|
|
|
bus_addr_t *res, bus_size_t count, u_int flags)
|
|
|
|
{
|
|
|
|
struct isa_device* idev = DEVTOISA(child);
|
|
|
|
struct resource_list *rl = &idev->id_resources;
|
|
|
|
|
|
|
|
device_t bus = device_get_parent(child);
|
2001-06-17 13:33:59 +00:00
|
|
|
bus_addr_t start;
|
2004-07-03 20:11:49 +00:00
|
|
|
bus_space_handle_t bh;
|
2000-03-29 03:15:22 +00:00
|
|
|
struct resource *re;
|
|
|
|
struct resource **bsre;
|
|
|
|
int i, j, k, linear_cnt, ressz, bsrid;
|
|
|
|
|
2001-06-17 13:33:59 +00:00
|
|
|
start = bus_get_resource_start(child, type, *rid);
|
2000-03-29 03:15:22 +00:00
|
|
|
|
|
|
|
linear_cnt = count;
|
|
|
|
ressz = 1;
|
|
|
|
for (i = 1; i < count; ++i) {
|
2000-09-07 14:43:00 +00:00
|
|
|
if (res[i] != res[i - 1] + 1) {
|
2000-03-29 03:15:22 +00:00
|
|
|
if (i < linear_cnt)
|
|
|
|
linear_cnt = i;
|
|
|
|
++ressz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-17 13:33:59 +00:00
|
|
|
re = isa_alloc_resource(bus, child, type, rid,
|
|
|
|
start + res[0], start + res[linear_cnt - 1],
|
|
|
|
linear_cnt, flags);
|
2000-03-29 03:15:22 +00:00
|
|
|
if (re == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
bsre = malloc(sizeof (struct resource *) * ressz, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (bsre == NULL) {
|
|
|
|
resource_list_release(rl, bus, child, type, *rid, re);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bsre[0] = re;
|
|
|
|
|
|
|
|
for (i = linear_cnt, k = 1; i < count; i = j, k++) {
|
|
|
|
for (j = i + 1; j < count; j++) {
|
2000-09-07 14:43:00 +00:00
|
|
|
if (res[j] != res[j - 1] + 1)
|
2000-03-29 03:15:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
bsrid = *rid + k;
|
|
|
|
bsre[k] = isa_alloc_resource(bus, child, type, &bsrid,
|
2001-06-17 13:33:59 +00:00
|
|
|
start + res[i], start + res[j - 1], j - i, flags);
|
2000-03-29 03:15:22 +00:00
|
|
|
if (bsre[k] == NULL) {
|
|
|
|
for (k--; k >= 0; k--)
|
|
|
|
resource_list_release(rl, bus, child, type,
|
|
|
|
*rid + k, bsre[k]);
|
|
|
|
free(bsre, M_DEVBUF);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-03 20:11:49 +00:00
|
|
|
bh = rman_get_bushandle(re);
|
|
|
|
bh->bsh_res = bsre;
|
|
|
|
bh->bsh_ressz = ressz;
|
2000-03-29 03:15:22 +00:00
|
|
|
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
isa_load_resourcev(struct resource *re, bus_addr_t *res, bus_size_t count)
|
|
|
|
{
|
|
|
|
|
2008-09-07 04:44:24 +00:00
|
|
|
return bus_space_map_load(rman_get_bustag(re), rman_get_bushandle(re),
|
|
|
|
count, res, 0);
|
2000-03-29 03:15:22 +00:00
|
|
|
}
|
|
|
|
#endif /* PC98 */
|
|
|
|
|
1999-05-22 15:18:28 +00:00
|
|
|
int
|
1999-04-16 21:22:55 +00:00
|
|
|
isa_release_resource(device_t bus, device_t child, int type, int rid,
|
|
|
|
struct resource *r)
|
1997-11-30 09:44:28 +00:00
|
|
|
{
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
struct isa_device* idev = DEVTOISA(child);
|
|
|
|
struct resource_list *rl = &idev->id_resources;
|
2000-03-29 03:15:22 +00:00
|
|
|
#ifdef PC98
|
|
|
|
/*
|
|
|
|
* Indirection support. The type of bus_space_handle_t is
|
|
|
|
* defined in sys/i386/include/bus_pc98.h.
|
|
|
|
*/
|
|
|
|
int i;
|
2004-07-03 20:11:49 +00:00
|
|
|
bus_space_handle_t bh;
|
2000-03-29 03:15:22 +00:00
|
|
|
|
2002-02-17 09:16:45 +00:00
|
|
|
if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
|
2004-07-03 20:11:49 +00:00
|
|
|
bh = rman_get_bushandle(r);
|
2007-09-01 12:18:28 +00:00
|
|
|
if (bh != NULL) {
|
|
|
|
for (i = 1; i < bh->bsh_ressz; i++)
|
|
|
|
resource_list_release(rl, bus, child, type,
|
|
|
|
rid + i, bh->bsh_res[i]);
|
|
|
|
if (bh->bsh_res != NULL)
|
|
|
|
free(bh->bsh_res, M_DEVBUF);
|
|
|
|
}
|
2002-02-17 09:16:45 +00:00
|
|
|
}
|
2000-03-29 03:15:22 +00:00
|
|
|
#endif
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
return resource_list_release(rl, bus, child, type, rid, r);
|
1997-07-24 05:27:40 +00:00
|
|
|
}
|
|
|
|
|
2004-12-24 23:03:17 +00:00
|
|
|
/*
|
|
|
|
* On this platform, isa can also attach to the legacy bus.
|
|
|
|
*/
|
|
|
|
DRIVER_MODULE(isa, legacy, isa_driver, isa_devclass, 0, 0);
|
2014-06-16 08:49:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the ISA bus to the xenpv bus in order to get syscons.
|
|
|
|
*/
|
|
|
|
DRIVER_MODULE(isa, xenpv, isa_driver, isa_devclass, 0, 0);
|