Home | History | Annotate | Line # | Download | only in pci
emuxkivar.h revision 1.15
      1  1.15   khorben /*	$NetBSD: emuxkivar.h,v 1.15 2022/09/07 01:00:37 khorben Exp $	*/
      2   1.1  jdolecek 
      3   1.1  jdolecek /*-
      4  1.15   khorben  * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
      5   1.1  jdolecek  * All rights reserved.
      6   1.1  jdolecek  *
      7   1.1  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8  1.15   khorben  * by Yannick Montulet, and by Andrew Doran.
      9   1.1  jdolecek  *
     10   1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     11   1.1  jdolecek  * modification, are permitted provided that the following conditions
     12   1.1  jdolecek  * are met:
     13   1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14   1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15   1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     18   1.1  jdolecek  *
     19   1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1  jdolecek  */
     31   1.1  jdolecek 
     32  1.15   khorben #ifndef _DEV_PCI_EMUXKIVAR_H_
     33  1.15   khorben #define _DEV_PCI_EMUXKIVAR_H_
     34   1.1  jdolecek 
     35  1.15   khorben #include <sys/device.h>
     36  1.15   khorben #include <sys/audioio.h>
     37  1.15   khorben #include <sys/mutex.h>
     38   1.1  jdolecek 
     39  1.15   khorben #include <sys/bus.h>
     40  1.15   khorben 
     41  1.15   khorben #include <dev/audio/audio_if.h>
     42   1.1  jdolecek 
     43  1.15   khorben #include <dev/ic/ac97reg.h>
     44  1.15   khorben #include <dev/ic/ac97var.h>
     45   1.1  jdolecek 
     46  1.15   khorben #include <dev/pci/pcidevs.h>
     47  1.15   khorben #include <dev/pci/pcireg.h>
     48  1.15   khorben #include <dev/pci/pcivar.h>
     49   1.1  jdolecek 
     50  1.15   khorben #define EMU_PTESIZE		(4096)
     51  1.15   khorben #define EMU_MINPTE		(3)
     52   1.1  jdolecek /*
     53  1.15   khorben  * Hardware limit of PTE is 4096 entry but it's too big for single voice.
     54  1.15   khorben  * Reasonable candidate is:
     55  1.15   khorben  *  48kHz * 2ch * 2byte * 1sec * 3buf/EMU_PTESIZE = 141
     56  1.15   khorben  * and then round it up to 2^n.
     57   1.1  jdolecek  */
     58  1.15   khorben #define EMU_MAXPTE		(256)
     59  1.15   khorben #define EMU_NUMCHAN		(64)
     60   1.1  jdolecek 
     61   1.1  jdolecek /*
     62  1.15   khorben  * Internal recording DMA buffer
     63   1.1  jdolecek  */
     64  1.15   khorben /* Recommend the same size as EMU_PTESIZE to be symmetrical for play/rec */
     65  1.15   khorben #define EMU_REC_DMABLKSIZE	(4096)
     66  1.15   khorben /* must be EMU_REC_DMABLKSIZE * 2 */
     67  1.15   khorben #define EMU_REC_DMASIZE		(8192)
     68  1.15   khorben /* must be EMU_RECBS_BUFSIZE_(EMU_REC_DMASIZE) */
     69  1.15   khorben #define EMU_REC_BUFSIZE_RECBS	EMU_RECBS_BUFSIZE_8192
     70   1.1  jdolecek 
     71   1.1  jdolecek /*
     72  1.15   khorben  * DMA memory management
     73   1.1  jdolecek  */
     74   1.1  jdolecek 
     75  1.15   khorben #define EMU_DMA_ALIGN		(4096)
     76  1.15   khorben #define EMU_DMA_NSEGS		(1)
     77   1.1  jdolecek 
     78  1.15   khorben struct dmamem {
     79  1.15   khorben 	bus_dma_tag_t		dmat;
     80  1.15   khorben 	bus_size_t		size;
     81  1.15   khorben 	bus_size_t		align;
     82  1.15   khorben 	bus_size_t		bound;
     83  1.15   khorben 	bus_dma_segment_t	*segs;
     84  1.15   khorben 	int			nsegs;
     85  1.15   khorben 	int			rsegs;
     86  1.15   khorben 	void *			kaddr;
     87  1.15   khorben 	bus_dmamap_t		map;
     88   1.1  jdolecek };
     89   1.1  jdolecek 
     90  1.15   khorben #define KERNADDR(ptr)		((void *)((ptr)->kaddr))
     91   1.1  jdolecek /*
     92  1.15   khorben  * (ptr)->segs[] is CPU's PA translated by CPU's MMU.
     93  1.15   khorben  * (ptr)->map->dm_segs[] is PCI device's PA translated by PCI's MMU.
     94   1.1  jdolecek  */
     95  1.15   khorben #define DMASEGADDR(ptr, segno)	((ptr)->map->dm_segs[segno].ds_addr)
     96  1.15   khorben #define DMAADDR(ptr)		DMASEGADDR(ptr, 0)
     97  1.15   khorben #define DMASIZE(ptr)		((ptr)->size)
     98   1.1  jdolecek 
     99   1.1  jdolecek struct emuxki_softc {
    100  1.15   khorben 	device_t		sc_dev;
    101  1.15   khorben 	device_t		sc_audev;
    102   1.8      kent 	enum {
    103  1.15   khorben 		EMUXKI_SBLIVE = 0x00,
    104  1.15   khorben 		EMUXKI_AUDIGY = 0x01,
    105  1.15   khorben 		EMUXKI_AUDIGY2 = 0x02,
    106  1.15   khorben 		EMUXKI_AUDIGY2_VALUE = 0x04,
    107  1.15   khorben 		EMUXKI_LIVE_5_1 = 0x08,
    108  1.15   khorben 		EMUXKI_APS = 0x10
    109   1.8      kent 	} sc_type;
    110  1.15   khorben 	audio_device_t		sc_audv;	/* for GETDEV */
    111   1.1  jdolecek 
    112   1.1  jdolecek 	/* Autoconfig parameters */
    113   1.8      kent 	bus_space_tag_t		sc_iot;
    114   1.1  jdolecek 	bus_space_handle_t	sc_ioh;
    115   1.1  jdolecek 	bus_addr_t		sc_iob;
    116   1.1  jdolecek 	bus_size_t		sc_ios;
    117   1.1  jdolecek 	pci_chipset_tag_t	sc_pc;		/* PCI tag */
    118   1.1  jdolecek 	bus_dma_tag_t		sc_dmat;
    119   1.1  jdolecek 	void			*sc_ih;		/* interrupt handler */
    120  1.13  jmcneill 	kmutex_t		sc_intr_lock;
    121  1.13  jmcneill 	kmutex_t		sc_lock;
    122  1.13  jmcneill 	kmutex_t		sc_index_lock;
    123   1.1  jdolecek 
    124  1.15   khorben 	/* register parameters */
    125  1.15   khorben 	struct dmamem		*ptb;		/* page table */
    126   1.1  jdolecek 
    127  1.15   khorben 	struct dmamem		*pmem;		/* play memory */
    128  1.15   khorben 	void			(*pintr)(void *);
    129  1.15   khorben 	void			*pintrarg;
    130  1.15   khorben 	audio_params_t		play;
    131  1.15   khorben 	uint32_t		pframesize;
    132  1.15   khorben 	uint32_t		pblksize;
    133  1.15   khorben 	uint32_t		plength;
    134  1.15   khorben 	uint32_t		poffset;
    135  1.15   khorben 
    136  1.15   khorben 	struct dmamem		*rmem;		/* rec internal memory */
    137  1.15   khorben 	void			(*rintr)(void *);
    138  1.15   khorben 	void			*rintrarg;
    139  1.15   khorben 	audio_params_t		rec;
    140  1.15   khorben 	void			*rptr;		/* rec MI ptr */
    141  1.15   khorben 	int			rcurrent;	/* rec software trans count */
    142  1.15   khorben 	int			rframesize;
    143  1.15   khorben 	int			rblksize;
    144  1.15   khorben 	int			rlength;
    145  1.15   khorben 	int			roffset;
    146   1.1  jdolecek 
    147  1.15   khorben 	/* others */
    148   1.1  jdolecek 
    149   1.1  jdolecek 	struct ac97_host_if	hostif;
    150   1.1  jdolecek 	struct ac97_codec_if	*codecif;
    151   1.1  jdolecek };
    152   1.1  jdolecek 
    153  1.15   khorben #endif /* _DEV_PCI_EMUXKIVAR_H_ */
    154