138136Sdfr/*-
238136Sdfr * Copyright (c) 1998 Doug Rabson
338136Sdfr * All rights reserved.
438136Sdfr *
538136Sdfr * Redistribution and use in source and binary forms, with or without
638136Sdfr * modification, are permitted provided that the following conditions
738136Sdfr * are met:
838136Sdfr * 1. Redistributions of source code must retain the above copyright
938136Sdfr *    notice, this list of conditions and the following disclaimer.
1038136Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1138136Sdfr *    notice, this list of conditions and the following disclaimer in the
1238136Sdfr *    documentation and/or other materials provided with the distribution.
1338136Sdfr *
1438136Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1538136Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1638136Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1738136Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1838136Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1938136Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2038136Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2138136Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2238136Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2338136Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2438136Sdfr * SUCH DAMAGE.
2538136Sdfr *
2650477Speter * $FreeBSD$
2738136Sdfr */
2838136Sdfr
2947613Sdfr#ifndef _ISA_ISAVAR_H_
3047613Sdfr#define _ISA_ISAVAR_H_
3147613Sdfr
3250769Sdfrstruct isa_config;
3350769Sdfrstruct isa_pnp_id;
3450769Sdfrtypedef void isa_config_cb(void *arg, struct isa_config *config, int enable);
3550769Sdfr
3647398Sdfr#include "isa_if.h"
3750769Sdfr#include <isa/pnpvar.h>
3847398Sdfr
3955206Speter#ifdef _KERNEL
4047613Sdfr
4147578Sdfr/*
42138506Simp * ISA devices are partially ordered.  This is to ensure that hardwired
43138506Simp * devices the BIOS tells us are there appear first, then speculative
44138506Simp * devices that are sensitive to the probe order, then devices that
45138506Simp * are hinted to be there, then the most flexible devices which support
46138506Simp * the ISA bus PNP standard.
4747578Sdfr */
48138506Simp#define ISA_ORDER_PNPBIOS	10 /* plug-and-play BIOS inflexible hardware */
49138506Simp#define ISA_ORDER_SENSITIVE	20 /* legacy sensitive hardware */
50138506Simp#define ISA_ORDER_SPECULATIVE	30 /* legacy non-sensitive hardware */
51184564Simp#define ISA_ORDER_PNP		40 /* plug-and-play flexible hardware */
5247578Sdfr
5366840Smsmith/*
5466840Smsmith * Limits on resources that we can manage
5566840Smsmith */
5657368Sgj#define	ISA_NPORT	50
5766840Smsmith#define	ISA_NMEM	50
5866840Smsmith#define	ISA_NIRQ	50
5966840Smsmith#define	ISA_NDRQ	50
6041181Sdfr
6166840Smsmith/*
6266840Smsmith * Limits on resources the hardware can actually handle
6366840Smsmith */
6466840Smsmith#define ISA_PNP_NPORT	8
6566840Smsmith#define ISA_PNP_NMEM	4
6666840Smsmith#define ISA_PNP_NIRQ	2
6766840Smsmith#define ISA_PNP_NDRQ	2
6866840Smsmith
6957973Sphk#define ISADMA_READ	0x00100000
7057973Sphk#define ISADMA_WRITE	0
7157973Sphk#define ISADMA_RAW	0x00080000
7250769Sdfr/*
7350769Sdfr * Plug and play cards can support a range of resource
7450769Sdfr * configurations. This structure is used by the isapnp parser to
7550769Sdfr * inform the isa bus about the resource possibilities of the
7650769Sdfr * device. Each different alternative should be supplied by calling
7750769Sdfr * ISA_ADD_CONFIG().
7850769Sdfr */
7950769Sdfrstruct isa_range {
8050769Sdfr	u_int32_t		ir_start;
8150769Sdfr	u_int32_t		ir_end;
8250769Sdfr	u_int32_t		ir_size;
8350769Sdfr	u_int32_t		ir_align;
8450769Sdfr};
8550769Sdfr
8650769Sdfrstruct isa_config {
8750769Sdfr	struct isa_range	ic_mem[ISA_NMEM];
8850769Sdfr	struct isa_range	ic_port[ISA_NPORT];
8950769Sdfr	u_int32_t		ic_irqmask[ISA_NIRQ];
9050769Sdfr	u_int32_t		ic_drqmask[ISA_NDRQ];
9150769Sdfr	int			ic_nmem;
9250769Sdfr	int			ic_nport;
9350769Sdfr	int			ic_nirq;
9450769Sdfr	int			ic_ndrq;
9550769Sdfr};
9650769Sdfr
9750769Sdfr/*
9850769Sdfr * Used to build lists of IDs and description strings for PnP drivers.
9950769Sdfr */
10050769Sdfrstruct isa_pnp_id {
10150769Sdfr	u_int32_t		ip_id;
10250769Sdfr	const char		*ip_desc;
10350769Sdfr};
10450769Sdfr
10538136Sdfrenum isa_device_ivars {
10641181Sdfr	ISA_IVAR_PORT,
10741181Sdfr	ISA_IVAR_PORT_0 = ISA_IVAR_PORT,
10841181Sdfr	ISA_IVAR_PORT_1,
10941181Sdfr	ISA_IVAR_PORTSIZE,
11041181Sdfr	ISA_IVAR_PORTSIZE_0 = ISA_IVAR_PORTSIZE,
11141181Sdfr	ISA_IVAR_PORTSIZE_1,
11241181Sdfr	ISA_IVAR_MADDR,
11341181Sdfr	ISA_IVAR_MADDR_0 = ISA_IVAR_MADDR,
11441181Sdfr	ISA_IVAR_MADDR_1,
115105139Sjhb	ISA_IVAR_MEMSIZE,
116105139Sjhb	ISA_IVAR_MEMSIZE_0 = ISA_IVAR_MEMSIZE,
117105139Sjhb	ISA_IVAR_MEMSIZE_1,
11841181Sdfr	ISA_IVAR_IRQ,
11941181Sdfr	ISA_IVAR_IRQ_0 = ISA_IVAR_IRQ,
12041181Sdfr	ISA_IVAR_IRQ_1,
12141181Sdfr	ISA_IVAR_DRQ,
12241181Sdfr	ISA_IVAR_DRQ_0 = ISA_IVAR_DRQ,
12347613Sdfr	ISA_IVAR_DRQ_1,
12447613Sdfr	ISA_IVAR_VENDORID,
12547613Sdfr	ISA_IVAR_SERIAL,
12647613Sdfr	ISA_IVAR_LOGICALID,
12782863Syokota	ISA_IVAR_COMPATID,
128184564Simp	ISA_IVAR_CONFIGATTR,
129184564Simp	ISA_IVAR_PNP_CSN,
130184564Simp	ISA_IVAR_PNP_LDN,
131184564Simp	ISA_IVAR_PNPBIOS_HANDLE
13238136Sdfr};
13338136Sdfr
13438136Sdfr/*
13583051Syokota * ISA_IVAR_CONFIGATTR bits
13683051Syokota */
13783051Syokota#define ISACFGATTR_CANDISABLE	(1 << 0)	/* can be disabled */
13883051Syokota#define ISACFGATTR_DYNAMIC	(1 << 1)	/* dynamic configuration */
139144985Smdodd#define ISACFGATTR_HINTS	(1 << 3)	/* source of config is hints */
14083051Syokota
14183051Syokota/*
14238136Sdfr * Simplified accessors for isa devices
14338136Sdfr */
144105139Sjhb#define ISA_ACCESSOR(var, ivar, type)					\
145105139Sjhb	__BUS_ACCESSOR(isa, var, ISA, ivar, type)
14638136Sdfr
14738136SdfrISA_ACCESSOR(port, PORT, int)
14838136SdfrISA_ACCESSOR(portsize, PORTSIZE, int)
14938136SdfrISA_ACCESSOR(irq, IRQ, int)
15045720SpeterISA_ACCESSOR(drq, DRQ, int)
15145720SpeterISA_ACCESSOR(maddr, MADDR, int)
152105139SjhbISA_ACCESSOR(msize, MEMSIZE, int)
15347613SdfrISA_ACCESSOR(vendorid, VENDORID, int)
15447613SdfrISA_ACCESSOR(serial, SERIAL, int)
15547613SdfrISA_ACCESSOR(logicalid, LOGICALID, int)
15647613SdfrISA_ACCESSOR(compatid, COMPATID, int)
15782863SyokotaISA_ACCESSOR(configattr, CONFIGATTR, int)
158184564SimpISA_ACCESSOR(pnp_csn, PNP_CSN, int)
159184564SimpISA_ACCESSOR(pnp_ldn, PNP_LDN, int)
160184564SimpISA_ACCESSOR(pnpbios_handle, PNPBIOS_HANDLE, int)
16147613Sdfr
162117337Sjhb/* Device class for ISA bridges. */
163117337Sjhbextern devclass_t isab_devclass;
164117337Sjhb
16550769Sdfrextern intrmask_t isa_irq_pending(void);
16650769Sdfrextern void	isa_probe_children(device_t dev);
16747613Sdfr
168141391Sphkvoid	isa_dmacascade(int chan);
169141391Sphkvoid	isa_dmadone(int flags, caddr_t addr, int nbytes, int chan);
170141391Sphkint	isa_dma_init(int chan, u_int bouncebufsize, int flag);
171141391Sphkvoid	isa_dmastart(int flags, caddr_t addr, u_int nbytes, int chan);
172141391Sphkint	isa_dma_acquire(int chan);
173141391Sphkvoid	isa_dma_release(int chan);
174141391Sphkint	isa_dmastatus(int chan);
175141391Sphkint	isa_dmastop(int chan);
176141391Sphkint	isa_dmatc(int chan);
17750769Sdfr
178135262Sphk#define isa_dmainit(chan, size) do { \
179135262Sphk	if (isa_dma_init(chan, size, M_NOWAIT)) \
180135262Sphk		printf("WARNING: isa_dma_init(%d, %ju) failed\n", \
181135262Sphk		    (int)(chan), (uintmax_t)(size)); \
182135262Sphk	} while (0)
183135262Sphk
184185059Sjhbvoid	isa_hinted_child(device_t parent, const char *name, int unit);
185185059Sjhbvoid	isa_hint_device_unit(device_t bus, device_t child, const char *name,
186185059Sjhb	    int *unitp);
187117337Sjhbint	isab_attach(device_t dev);
188117337Sjhb
18967442Snyan#ifdef PC98
19067442Snyan#include <machine/bus.h>
19167442Snyan
19267442Snyan/*
19367442Snyan * Allocate discontinuous resources for ISA bus.
19467442Snyan */
19567442Snyanstruct resource *
19667442Snyanisa_alloc_resourcev(device_t child, int type, int *rid,
19767442Snyan		    bus_addr_t *res, bus_size_t count, u_int flags);
19867442Snyanint
19967442Snyanisa_load_resourcev(struct resource *re, bus_addr_t *res, bus_size_t count);
20067442Snyan#endif
20167442Snyan
20255206Speter#endif /* _KERNEL */
20347613Sdfr
20447613Sdfr#endif /* !_ISA_ISAVAR_H_ */
205