Home | History | Annotate | Line # | Download | only in pci
agpvar.h revision 1.2.2.3
      1  1.2.2.3  thorpej /*	$NetBSD: agpvar.h,v 1.2.2.3 2002/01/10 19:56:25 thorpej Exp $	*/
      2  1.2.2.2  thorpej 
      3  1.2.2.2  thorpej /*-
      4  1.2.2.2  thorpej  * Copyright (c) 2000 Doug Rabson
      5  1.2.2.2  thorpej  * All rights reserved.
      6  1.2.2.2  thorpej  *
      7  1.2.2.2  thorpej  * Redistribution and use in source and binary forms, with or without
      8  1.2.2.2  thorpej  * modification, are permitted provided that the following conditions
      9  1.2.2.2  thorpej  * are met:
     10  1.2.2.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     11  1.2.2.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     12  1.2.2.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.2.2.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     14  1.2.2.2  thorpej  *    documentation and/or other materials provided with the distribution.
     15  1.2.2.2  thorpej  *
     16  1.2.2.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.2.2.2  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.2.2.2  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.2.2.2  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.2.2.2  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.2.2.2  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.2.2.2  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.2.2.2  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.2.2.2  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.2.2.2  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.2.2.2  thorpej  * SUCH DAMAGE.
     27  1.2.2.2  thorpej  *
     28  1.2.2.2  thorpej  *	$FreeBSD: src/sys/pci/agppriv.h,v 1.3 2000/07/12 10:13:04 dfr Exp $
     29  1.2.2.2  thorpej  */
     30  1.2.2.2  thorpej 
     31  1.2.2.2  thorpej #ifndef _PCI_AGPVAR_H_
     32  1.2.2.2  thorpej #define _PCI_AGPVAR_H_
     33  1.2.2.2  thorpej 
     34  1.2.2.2  thorpej #include <sys/lock.h>
     35  1.2.2.2  thorpej 
     36  1.2.2.3  thorpej struct agpbus_attach_args {
     37  1.2.2.3  thorpej 	char	*apa_busname;
     38  1.2.2.2  thorpej 	struct pci_attach_args apa_pci_args;
     39  1.2.2.2  thorpej };
     40  1.2.2.2  thorpej 
     41  1.2.2.2  thorpej /*
     42  1.2.2.2  thorpej  * The AGP chipset can be acquired by user or kernel code. If the
     43  1.2.2.2  thorpej  * chipset has already been acquired, it cannot be acquired by another
     44  1.2.2.2  thorpej  * user until the previous user has released it.
     45  1.2.2.2  thorpej  */
     46  1.2.2.2  thorpej enum agp_acquire_state {
     47  1.2.2.2  thorpej 	AGP_ACQUIRE_FREE,
     48  1.2.2.2  thorpej 	AGP_ACQUIRE_USER,
     49  1.2.2.2  thorpej 	AGP_ACQUIRE_KERNEL
     50  1.2.2.2  thorpej };
     51  1.2.2.2  thorpej 
     52  1.2.2.2  thorpej /*
     53  1.2.2.2  thorpej  * This structure is used to query the state of the AGP system.
     54  1.2.2.2  thorpej  */
     55  1.2.2.2  thorpej struct agp_info {
     56  1.2.2.2  thorpej 	u_int32_t	ai_mode;
     57  1.2.2.2  thorpej 	bus_addr_t	ai_aperture_base;
     58  1.2.2.2  thorpej 	bus_size_t	ai_aperture_size;
     59  1.2.2.2  thorpej 	vsize_t		ai_memory_allowed;
     60  1.2.2.2  thorpej 	vsize_t		ai_memory_used;
     61  1.2.2.2  thorpej 	u_int32_t	ai_devid;
     62  1.2.2.2  thorpej };
     63  1.2.2.2  thorpej 
     64  1.2.2.2  thorpej struct agp_memory_info {
     65  1.2.2.2  thorpej 	vsize_t		ami_size;	/* size in bytes */
     66  1.2.2.2  thorpej 	bus_addr_t	ami_physical;	/* bogus hack for i810 */
     67  1.2.2.2  thorpej 	off_t		ami_offset;	/* page offset if bound */
     68  1.2.2.2  thorpej 	int		ami_is_bound;	/* non-zero if bound */
     69  1.2.2.2  thorpej };
     70  1.2.2.2  thorpej 
     71  1.2.2.2  thorpej #define AGP_DEBUGxx
     72  1.2.2.2  thorpej 
     73  1.2.2.2  thorpej #ifdef AGP_DEBUG
     74  1.2.2.2  thorpej #define AGP_DPF(x...) do {			\
     75  1.2.2.2  thorpej     printf("agp: ");				\
     76  1.2.2.2  thorpej     printf(##x);				\
     77  1.2.2.2  thorpej } while (0)
     78  1.2.2.2  thorpej #else
     79  1.2.2.2  thorpej #define AGP_DPF(x...) do {} while (0)
     80  1.2.2.2  thorpej #endif
     81  1.2.2.2  thorpej 
     82  1.2.2.2  thorpej #define AGPUNIT(x)	minor(x)
     83  1.2.2.2  thorpej 
     84  1.2.2.2  thorpej /*
     85  1.2.2.2  thorpej  * Data structure to describe an AGP memory allocation.
     86  1.2.2.2  thorpej  */
     87  1.2.2.2  thorpej TAILQ_HEAD(agp_memory_list, agp_memory);
     88  1.2.2.2  thorpej struct agp_memory {
     89  1.2.2.2  thorpej 	TAILQ_ENTRY(agp_memory) am_link;	/* wiring for the tailq */
     90  1.2.2.2  thorpej 	int		am_id;			/* unique id for block */
     91  1.2.2.2  thorpej 	vsize_t		am_size;		/* number of bytes allocated */
     92  1.2.2.2  thorpej 	int		am_type;		/* chipset specific type */
     93  1.2.2.2  thorpej 	off_t		am_offset;		/* page offset if bound */
     94  1.2.2.2  thorpej 	int		am_is_bound;		/* non-zero if bound */
     95  1.2.2.2  thorpej 	bus_addr_t	  am_physical;
     96  1.2.2.2  thorpej 	caddr_t		  am_virtual;
     97  1.2.2.2  thorpej 	bus_dmamap_t	  am_dmamap;
     98  1.2.2.2  thorpej 	bus_dma_segment_t *am_dmaseg;
     99  1.2.2.2  thorpej 	int		  am_nseg;
    100  1.2.2.2  thorpej };
    101  1.2.2.2  thorpej 
    102  1.2.2.2  thorpej struct agp_softc;
    103  1.2.2.2  thorpej 
    104  1.2.2.2  thorpej struct agp_methods {
    105  1.2.2.2  thorpej 	u_int32_t (*get_aperture)(struct agp_softc *);
    106  1.2.2.2  thorpej 	int (*set_aperture)(struct agp_softc *, u_int32_t);
    107  1.2.2.2  thorpej 	int (*bind_page)(struct agp_softc *, off_t, bus_addr_t);
    108  1.2.2.2  thorpej 	int (*unbind_page)(struct agp_softc *, off_t);
    109  1.2.2.2  thorpej 	void (*flush_tlb)(struct agp_softc *);
    110  1.2.2.2  thorpej 	int (*enable)(struct agp_softc *, u_int32_t mode);
    111  1.2.2.2  thorpej 	struct agp_memory *(*alloc_memory)(struct agp_softc *, int, vsize_t);
    112  1.2.2.2  thorpej 	int (*free_memory)(struct agp_softc *, struct agp_memory *);
    113  1.2.2.2  thorpej 	int (*bind_memory)(struct agp_softc *, struct agp_memory *, off_t);
    114  1.2.2.2  thorpej 	int (*unbind_memory)(struct agp_softc *, struct agp_memory *);
    115  1.2.2.2  thorpej };
    116  1.2.2.2  thorpej 
    117  1.2.2.2  thorpej #define AGP_GET_APERTURE(sc)	 ((sc)->as_methods->get_aperture(sc))
    118  1.2.2.2  thorpej #define AGP_SET_APERTURE(sc,a)	 ((sc)->as_methods->set_aperture((sc),(a)))
    119  1.2.2.2  thorpej #define AGP_BIND_PAGE(sc,o,p)	 ((sc)->as_methods->bind_page((sc),(o),(p)))
    120  1.2.2.2  thorpej #define AGP_UNBIND_PAGE(sc,o)	 ((sc)->as_methods->unbind_page((sc), (o)))
    121  1.2.2.2  thorpej #define AGP_FLUSH_TLB(sc)	 ((sc)->as_methods->flush_tlb(sc))
    122  1.2.2.2  thorpej #define AGP_ENABLE(sc,m)	 ((sc)->as_methods->enable((sc),(m)))
    123  1.2.2.2  thorpej #define AGP_ALLOC_MEMORY(sc,t,s) ((sc)->as_methods->alloc_memory((sc),(t),(s)))
    124  1.2.2.2  thorpej #define AGP_FREE_MEMORY(sc,m)	 ((sc)->as_methods->free_memory((sc),(m)))
    125  1.2.2.2  thorpej #define AGP_BIND_MEMORY(sc,m,o)	 ((sc)->as_methods->bind_memory((sc),(m),(o)))
    126  1.2.2.2  thorpej #define AGP_UNBIND_MEMORY(sc,m)	 ((sc)->as_methods->unbind_memory((sc),(m)))
    127  1.2.2.2  thorpej 
    128  1.2.2.2  thorpej /*
    129  1.2.2.2  thorpej  * All chipset drivers must have this at the start of their softc.
    130  1.2.2.2  thorpej  */
    131  1.2.2.2  thorpej struct agp_softc {
    132  1.2.2.2  thorpej 	struct device		as_dev;
    133  1.2.2.2  thorpej 	bus_space_tag_t		as_apt;
    134  1.2.2.2  thorpej 	int			as_capoff;
    135  1.2.2.2  thorpej 	bus_addr_t		as_apaddr;
    136  1.2.2.2  thorpej 	bus_size_t		as_apsize;
    137  1.2.2.3  thorpej 	int			as_apflags;
    138  1.2.2.2  thorpej 	bus_dma_tag_t		as_dmat;
    139  1.2.2.2  thorpej 	u_int32_t		as_maxmem;	/* allocation upper bound */
    140  1.2.2.2  thorpej 	u_int32_t		as_allocated;	/* amount allocated */
    141  1.2.2.2  thorpej 	enum agp_acquire_state	as_state;
    142  1.2.2.2  thorpej 	struct agp_memory_list	as_memory;	/* list of allocated memory */
    143  1.2.2.2  thorpej 	int			as_nextid;	/* next memory block id */
    144  1.2.2.2  thorpej 	int			as_isopen;	/* user device is open */
    145  1.2.2.2  thorpej #if 0
    146  1.2.2.2  thorpej 	dev_t			as_devnode;	/* from make_dev */
    147  1.2.2.2  thorpej #endif
    148  1.2.2.2  thorpej 	struct lock		as_lock;	/* lock for access to GATT */
    149  1.2.2.2  thorpej 	struct agp_methods	*as_methods;	/* chipset-dependent API */
    150  1.2.2.2  thorpej 	void			*as_chipc;	/* chipset-dependent state */
    151  1.2.2.2  thorpej 	pci_chipset_tag_t	as_pc;
    152  1.2.2.2  thorpej 	pcitag_t		as_tag;
    153  1.2.2.2  thorpej 	pcireg_t		as_id;
    154  1.2.2.2  thorpej };
    155  1.2.2.2  thorpej 
    156  1.2.2.2  thorpej struct agp_gatt {
    157  1.2.2.2  thorpej 	u_int32_t	  ag_entries;
    158  1.2.2.2  thorpej 	u_int32_t        *ag_virtual;
    159  1.2.2.2  thorpej 	bus_addr_t	  ag_physical;
    160  1.2.2.2  thorpej 	bus_dmamap_t	  ag_dmamap;
    161  1.2.2.2  thorpej 	bus_dma_segment_t ag_dmaseg;
    162  1.2.2.2  thorpej 	size_t		  ag_size;
    163  1.2.2.2  thorpej };
    164  1.2.2.2  thorpej 
    165  1.2.2.2  thorpej /*
    166  1.2.2.2  thorpej  * Functions private to the AGP code.
    167  1.2.2.2  thorpej  */
    168  1.2.2.2  thorpej void agp_flush_cache(void);
    169  1.2.2.2  thorpej int agp_find_caps(pci_chipset_tag_t pct, pcitag_t pt);
    170  1.2.2.2  thorpej int agp_map_aperture(struct pci_attach_args *pa, struct agp_softc *sc);
    171  1.2.2.2  thorpej struct agp_gatt *agp_alloc_gatt(struct agp_softc *sc);
    172  1.2.2.2  thorpej void agp_free_gatt(struct agp_softc *sc, struct agp_gatt *gatt);
    173  1.2.2.2  thorpej int agp_generic_attach(struct agp_softc *sc);
    174  1.2.2.2  thorpej int agp_generic_detach(struct agp_softc *sc);
    175  1.2.2.2  thorpej int agp_generic_enable(struct agp_softc *sc, u_int32_t mode);
    176  1.2.2.2  thorpej struct agp_memory *agp_generic_alloc_memory(struct agp_softc *sc, int type,
    177  1.2.2.2  thorpej 						 vsize_t size);
    178  1.2.2.2  thorpej int agp_generic_free_memory(struct agp_softc *sc, struct agp_memory *mem);
    179  1.2.2.2  thorpej int agp_generic_bind_memory(struct agp_softc *sc, struct agp_memory *mem,
    180  1.2.2.2  thorpej 						off_t offset);
    181  1.2.2.2  thorpej int agp_generic_unbind_memory(struct agp_softc *sc, struct agp_memory *mem);
    182  1.2.2.2  thorpej 
    183  1.2.2.2  thorpej /* The vendor has already been matched when these functions are called */
    184  1.2.2.3  thorpej int agp_amd_match(const struct pci_attach_args *);
    185  1.2.2.2  thorpej 
    186  1.2.2.2  thorpej int agp_ali_attach(struct device *parent, struct device *self, void *aux);
    187  1.2.2.2  thorpej int agp_amd_attach(struct device *parent, struct device *self, void *aux);
    188  1.2.2.2  thorpej int agp_i810_attach(struct device *parent, struct device *self, void *aux);
    189  1.2.2.2  thorpej int agp_intel_attach(struct device *parent, struct device *self, void *aux);
    190  1.2.2.2  thorpej int agp_via_attach(struct device *parent, struct device *self, void *aux);
    191  1.2.2.2  thorpej int agp_sis_attach(struct device *parent, struct device *self, void *aux);
    192  1.2.2.2  thorpej 
    193  1.2.2.2  thorpej int agp_alloc_dmamem(bus_dma_tag_t, size_t, int, bus_dmamap_t *, caddr_t *,
    194  1.2.2.2  thorpej 		     bus_addr_t *, bus_dma_segment_t *, int, int *);
    195  1.2.2.2  thorpej void agp_free_dmamem(bus_dma_tag_t tag, size_t size, bus_dmamap_t map,
    196  1.2.2.2  thorpej 		     caddr_t vaddr, bus_dma_segment_t *seg, int nseg) ;
    197  1.2.2.2  thorpej 
    198  1.2.2.2  thorpej /*
    199  1.2.2.2  thorpej  * Kernel API
    200  1.2.2.2  thorpej  */
    201  1.2.2.2  thorpej /*
    202  1.2.2.2  thorpej  * Find the AGP device and return it.
    203  1.2.2.2  thorpej  */
    204  1.2.2.2  thorpej void *agp_find_device(int);
    205  1.2.2.2  thorpej 
    206  1.2.2.2  thorpej /*
    207  1.2.2.2  thorpej  * Return the current owner of the AGP chipset.
    208  1.2.2.2  thorpej  */
    209  1.2.2.2  thorpej enum agp_acquire_state agp_state(void *devcookie);
    210  1.2.2.2  thorpej 
    211  1.2.2.2  thorpej /*
    212  1.2.2.2  thorpej  * Query the state of the AGP system.
    213  1.2.2.2  thorpej  */
    214  1.2.2.2  thorpej void agp_get_info(void *devhandle, struct agp_info *info);
    215  1.2.2.2  thorpej 
    216  1.2.2.2  thorpej /*
    217  1.2.2.2  thorpej  * Acquire the AGP chipset for use by the kernel. Returns EBUSY if the
    218  1.2.2.2  thorpej  * AGP chipset is already acquired by another user.
    219  1.2.2.2  thorpej  */
    220  1.2.2.2  thorpej int agp_acquire(void *devhandle);
    221  1.2.2.2  thorpej 
    222  1.2.2.2  thorpej /*
    223  1.2.2.2  thorpej  * Release the AGP chipset.
    224  1.2.2.2  thorpej  */
    225  1.2.2.2  thorpej int agp_release(void *devhandle);
    226  1.2.2.2  thorpej 
    227  1.2.2.2  thorpej /*
    228  1.2.2.2  thorpej  * Enable the agp hardware with the relavent mode. The mode bits are
    229  1.2.2.2  thorpej  * defined in <dev/pci/agpreg.h>
    230  1.2.2.2  thorpej  */
    231  1.2.2.2  thorpej int agp_enable(void *devhandle, u_int32_t mode);
    232  1.2.2.2  thorpej 
    233  1.2.2.2  thorpej /*
    234  1.2.2.2  thorpej  * Allocate physical memory suitable for mapping into the AGP
    235  1.2.2.2  thorpej  * aperture.  The value returned is an opaque handle which can be
    236  1.2.2.2  thorpej  * passed to agp_bind(), agp_unbind() or agp_deallocate().
    237  1.2.2.2  thorpej  */
    238  1.2.2.2  thorpej void *agp_alloc_memory(void *devhandle, int type, vsize_t bytes);
    239  1.2.2.2  thorpej 
    240  1.2.2.2  thorpej /*
    241  1.2.2.2  thorpej  * Free memory which was allocated with agp_allocate().
    242  1.2.2.2  thorpej  */
    243  1.2.2.2  thorpej void agp_free_memory(void *devhandle, void *handle);
    244  1.2.2.2  thorpej 
    245  1.2.2.2  thorpej /*
    246  1.2.2.2  thorpej  * Bind memory allocated with agp_allocate() at a given offset within
    247  1.2.2.2  thorpej  * the AGP aperture. Returns EINVAL if the memory is already bound or
    248  1.2.2.2  thorpej  * the offset is not at an AGP page boundary.
    249  1.2.2.2  thorpej  */
    250  1.2.2.2  thorpej int agp_bind_memory(void *devhandle, void *handle, off_t offset);
    251  1.2.2.2  thorpej 
    252  1.2.2.2  thorpej /*
    253  1.2.2.2  thorpej  * Unbind memory from the AGP aperture. Returns EINVAL if the memory
    254  1.2.2.2  thorpej  * is not bound.
    255  1.2.2.2  thorpej  */
    256  1.2.2.2  thorpej int agp_unbind_memory(void *devhandle, void *handle);
    257  1.2.2.2  thorpej 
    258  1.2.2.2  thorpej /*
    259  1.2.2.2  thorpej  * Retrieve information about a memory block allocated with
    260  1.2.2.2  thorpej  * agp_alloc_memory().
    261  1.2.2.2  thorpej  */
    262  1.2.2.2  thorpej void agp_memory_info(void *devhandle, void *handle, struct agp_memory_info *mi);
    263  1.2.2.2  thorpej 
    264  1.2.2.2  thorpej #endif /* !_PCI_AGPPRIV_H_ */
    265