freebsd-skq/sys/i386/isa/isa.c

261 lines
7.9 KiB
C
Raw Normal View History

1993-06-12 14:58:17 +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.
*
* 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
* 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.
*
1999-08-28 01:08:13 +00:00
* $FreeBSD$
1993-06-12 14:58:17 +00:00
*/
/*
* Modifications for Intel architecture by Garrett A. Wollman.
* Copyright 1998 Massachusetts Institute of Technology
1993-06-12 14:58:17 +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
*/
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/malloc.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
1993-06-12 14:58:17 +00:00
#include <isa/isavar.h>
#include <isa/isa_common.h>
1993-06-12 14:58:17 +00:00
void
isa_init(void)
{
1993-06-12 14:58:17 +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
*/
struct resource *
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)
{
/*
* Consider adding a resource definition. We allow rid 0-1 for
* irq and drq, 0-3 for memory and 0-7 for ports which is
* sufficient for isapnp.
*/
int passthrough = (device_get_parent(child) != bus);
int isdefault = (start == 0UL && end == ~0UL);
struct isa_device* idev = DEVTOISA(child);
struct resource_list *rl = &idev->id_resources;
struct resource_list_entry *rle;
if (!passthrough && !isdefault) {
rle = resource_list_find(rl, type, *rid);
if (!rle) {
if (*rid < 0)
return 0;
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:
return 0;
}
resource_list_add(rl, type, *rid, start, end, count);
}
1993-06-12 14:58:17 +00:00
}
return resource_list_alloc(rl, bus, child, type, rid,
start, end, count, flags);
1993-06-12 14:58:17 +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);
bus_addr_t ioport;
struct resource *re;
struct resource **bsre;
int i, j, k, linear_cnt, ressz, bsrid;
ioport = bus_get_resource_start(child, SYS_RES_IOPORT, 0);
linear_cnt = count;
ressz = 1;
for (i = 1; i < count; ++i) {
if (res[i] != res[i - 1] + 1) {
if (i < linear_cnt)
linear_cnt = i;
++ressz;
}
}
re = isa_alloc_resource(bus, child, type, rid, ioport + res[0],
ioport + res[linear_cnt - 1], linear_cnt, flags);
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++) {
if (res[j] != res[j - 1] + 1)
break;
}
bsrid = *rid + k;
bsre[k] = isa_alloc_resource(bus, child, type, &bsrid,
ioport + res[i], ioport + res[j - 1], j - i, flags);
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;
}
}
re->r_bushandle->bsh_res = bsre;
re->r_bushandle->bsh_ressz = ressz;
return re;
}
int
isa_load_resourcev(struct resource *re, bus_addr_t *res, bus_size_t count)
{
bus_addr_t *addr;
int i;
addr = malloc(sizeof (bus_addr_t) * count, M_DEVBUF, M_NOWAIT);
if (addr == NULL)
return 1;
for (i = 0; i < count; i++)
addr[i] = rman_get_start(re) + res[i];
rman_set_bustag(re, I386_BUS_SPACE_IO_IND);
re->r_bushandle->bsh_iat = addr;
re->r_bushandle->bsh_iatsz = count;
return 0;
}
#endif /* PC98 */
int
isa_release_resource(device_t bus, device_t child, int type, int rid,
struct resource *r)
{
struct isa_device* idev = DEVTOISA(child);
struct resource_list *rl = &idev->id_resources;
#ifdef PC98
/*
* Indirection support. The type of bus_space_handle_t is
* defined in sys/i386/include/bus_pc98.h.
*/
int i;
for (i = 1; i < r->r_bushandle->bsh_ressz; i++)
resource_list_release(rl, bus, child, type, rid + i,
r->r_bushandle->bsh_res[i]);
if (r->r_bushandle->bsh_res != NULL)
free(r->r_bushandle->bsh_res, M_DEVBUF);
if (r->r_bushandle->bsh_iat != NULL)
free(r->r_bushandle->bsh_iat, M_DEVBUF);
#endif
return resource_list_release(rl, bus, child, type, rid, r);
}
/*
* We can't use the bus_generic_* versions of these methods because those
* methods always pass the bus param as the requesting device, and we need
* to pass the child (the i386 nexus knows about this and is prepared to
* deal).
*/
int
isa_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
void (*ihand)(void *), void *arg, void **cookiep)
{
return (BUS_SETUP_INTR(device_get_parent(bus), child, r, flags,
ihand, arg, cookiep));
}
int
isa_teardown_intr(device_t bus, device_t child, struct resource *r,
void *cookie)
Make pcvt and syscons live in the same kernel. If both are enabled, then the first one in the config has priority. They can be switched using userconfig(). i386/i386/conf.c: Initialize the shared syscons/pcvt cdevsw entry to `nx'. Add cdevsw registration functions. Use devsw functions of the correct type if they exist. i386/i386/cons.c: Add renamed syscons entry points to constab. i386/i386/cons.h: Declare the renamed syscons entry points. i386/i386/machdep.c: Repeat console initialization after userconfig() in case the current console has become wrong. This depends on cn functions not wiring down anything important. sys/conf.h: Declare new functions. i386/isa/isa.[ch]: Add a function to decide which display driver has priority. Should be done better. i386/isa/syscons.c: Rename pccn* -> sccn*. Initialize CRTC start address in case the previous driver has moved it. i386/isa/syscons.c, i386/isa/pcvt/* Initialize the bogusly shared variable Crtat dynamically in case the stored value was changed by the previous driver. Initialize cdevsw table from a template. Don't grab the console if another display driver has priority. i386/isa/syscons.h, i386/isa/pcvt/pcvt_hdr.h: Don't externally declare now-static cdevsw functions. i386/isa/pcvt/pcvt_hdr.h: Set the sensitive hardware flag so that pcvt doesn't always have lower priority than syscons. This also fixes the "stupid" detection of the display after filling the display with text. i386/isa/pcvt/pcvt_out.c: Don't be confused the off-screen cursor offset 0xffff set by syscons. kern/subr_xxx.c: Add enough nxio/nodev/null devsw functions of the correct type for syscons and pcvt.
1995-09-10 21:36:12 +00:00
{
return (BUS_TEARDOWN_INTR(device_get_parent(bus), child, r, cookie));
Make pcvt and syscons live in the same kernel. If both are enabled, then the first one in the config has priority. They can be switched using userconfig(). i386/i386/conf.c: Initialize the shared syscons/pcvt cdevsw entry to `nx'. Add cdevsw registration functions. Use devsw functions of the correct type if they exist. i386/i386/cons.c: Add renamed syscons entry points to constab. i386/i386/cons.h: Declare the renamed syscons entry points. i386/i386/machdep.c: Repeat console initialization after userconfig() in case the current console has become wrong. This depends on cn functions not wiring down anything important. sys/conf.h: Declare new functions. i386/isa/isa.[ch]: Add a function to decide which display driver has priority. Should be done better. i386/isa/syscons.c: Rename pccn* -> sccn*. Initialize CRTC start address in case the previous driver has moved it. i386/isa/syscons.c, i386/isa/pcvt/* Initialize the bogusly shared variable Crtat dynamically in case the stored value was changed by the previous driver. Initialize cdevsw table from a template. Don't grab the console if another display driver has priority. i386/isa/syscons.h, i386/isa/pcvt/pcvt_hdr.h: Don't externally declare now-static cdevsw functions. i386/isa/pcvt/pcvt_hdr.h: Set the sensitive hardware flag so that pcvt doesn't always have lower priority than syscons. This also fixes the "stupid" detection of the display after filling the display with text. i386/isa/pcvt/pcvt_out.c: Don't be confused the off-screen cursor offset 0xffff set by syscons. kern/subr_xxx.c: Add enough nxio/nodev/null devsw functions of the correct type for syscons and pcvt.
1995-09-10 21:36:12 +00:00
}