1162922Sariff/*- 2162922Sariff * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca> 3230130Smav * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org> 4162922Sariff * All rights reserved. 5162922Sariff * 6162922Sariff * Redistribution and use in source and binary forms, with or without 7162922Sariff * modification, are permitted provided that the following conditions 8162922Sariff * are met: 9162922Sariff * 1. Redistributions of source code must retain the above copyright 10162922Sariff * notice, this list of conditions and the following disclaimer. 11162922Sariff * 2. Redistributions in binary form must reproduce the above copyright 12162922Sariff * notice, this list of conditions and the following disclaimer in the 13162922Sariff * documentation and/or other materials provided with the distribution. 14162922Sariff * 15162922Sariff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16162922Sariff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17162922Sariff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18162922Sariff * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19162922Sariff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20162922Sariff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21162922Sariff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22162922Sariff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23162922Sariff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24162922Sariff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25162922Sariff * SUCH DAMAGE. 26162922Sariff * 27162922Sariff * $FreeBSD: releng/10.3/sys/dev/sound/pci/hda/hdac_private.h 230326 2012-01-19 01:55:48Z mav $ 28162922Sariff */ 29162922Sariff 30162922Sariff#ifndef _HDAC_PRIVATE_H_ 31162922Sariff#define _HDAC_PRIVATE_H_ 32162922Sariff 33162922Sariff/**************************************************************************** 34166043Sjoel * Miscellaneous defines 35162922Sariff ****************************************************************************/ 36162922Sariff#define HDAC_CODEC_MAX 16 37162922Sariff 38162922Sariff/**************************************************************************** 39162922Sariff * Helper Macros 40162922Sariff ****************************************************************************/ 41162922Sariff#define HDAC_READ_1(mem, offset) \ 42162922Sariff bus_space_read_1((mem)->mem_tag, (mem)->mem_handle, (offset)) 43162922Sariff#define HDAC_READ_2(mem, offset) \ 44162922Sariff bus_space_read_2((mem)->mem_tag, (mem)->mem_handle, (offset)) 45162922Sariff#define HDAC_READ_4(mem, offset) \ 46162922Sariff bus_space_read_4((mem)->mem_tag, (mem)->mem_handle, (offset)) 47162922Sariff#define HDAC_WRITE_1(mem, offset, value) \ 48162922Sariff bus_space_write_1((mem)->mem_tag, (mem)->mem_handle, (offset), (value)) 49162922Sariff#define HDAC_WRITE_2(mem, offset, value) \ 50162922Sariff bus_space_write_2((mem)->mem_tag, (mem)->mem_handle, (offset), (value)) 51162922Sariff#define HDAC_WRITE_4(mem, offset, value) \ 52162922Sariff bus_space_write_4((mem)->mem_tag, (mem)->mem_handle, (offset), (value)) 53162922Sariff 54162922Sariff#define HDAC_ISDCTL(sc, n) (_HDAC_ISDCTL((n), (sc)->num_iss, (sc)->num_oss)) 55162922Sariff#define HDAC_ISDSTS(sc, n) (_HDAC_ISDSTS((n), (sc)->num_iss, (sc)->num_oss)) 56162922Sariff#define HDAC_ISDPICB(sc, n) (_HDAC_ISDPICB((n), (sc)->num_iss, (sc)->num_oss)) 57162922Sariff#define HDAC_ISDCBL(sc, n) (_HDAC_ISDCBL((n), (sc)->num_iss, (sc)->num_oss)) 58162922Sariff#define HDAC_ISDLVI(sc, n) (_HDAC_ISDLVI((n), (sc)->num_iss, (sc)->num_oss)) 59162922Sariff#define HDAC_ISDFIFOD(sc, n) (_HDAC_ISDFIFOD((n), (sc)->num_iss, (sc)->num_oss)) 60162922Sariff#define HDAC_ISDFMT(sc, n) (_HDAC_ISDFMT((n), (sc)->num_iss, (sc)->num_oss)) 61162922Sariff#define HDAC_ISDBDPL(sc, n) (_HDAC_ISDBDPL((n), (sc)->num_iss, (sc)->num_oss)) 62162922Sariff#define HDAC_ISDBDPU(sc, n) (_HDAC_ISDBDPU((n), (sc)->num_iss, (sc)->num_oss)) 63162922Sariff 64162922Sariff#define HDAC_OSDCTL(sc, n) (_HDAC_OSDCTL((n), (sc)->num_iss, (sc)->num_oss)) 65162922Sariff#define HDAC_OSDSTS(sc, n) (_HDAC_OSDSTS((n), (sc)->num_iss, (sc)->num_oss)) 66162922Sariff#define HDAC_OSDPICB(sc, n) (_HDAC_OSDPICB((n), (sc)->num_iss, (sc)->num_oss)) 67162922Sariff#define HDAC_OSDCBL(sc, n) (_HDAC_OSDCBL((n), (sc)->num_iss, (sc)->num_oss)) 68162922Sariff#define HDAC_OSDLVI(sc, n) (_HDAC_OSDLVI((n), (sc)->num_iss, (sc)->num_oss)) 69162922Sariff#define HDAC_OSDFIFOD(sc, n) (_HDAC_OSDFIFOD((n), (sc)->num_iss, (sc)->num_oss)) 70162922Sariff#define HDAC_OSDBDPL(sc, n) (_HDAC_OSDBDPL((n), (sc)->num_iss, (sc)->num_oss)) 71162922Sariff#define HDAC_OSDBDPU(sc, n) (_HDAC_OSDBDPU((n), (sc)->num_iss, (sc)->num_oss)) 72162922Sariff 73162922Sariff#define HDAC_BSDCTL(sc, n) (_HDAC_BSDCTL((n), (sc)->num_iss, (sc)->num_oss)) 74162922Sariff#define HDAC_BSDSTS(sc, n) (_HDAC_BSDSTS((n), (sc)->num_iss, (sc)->num_oss)) 75162922Sariff#define HDAC_BSDPICB(sc, n) (_HDAC_BSDPICB((n), (sc)->num_iss, (sc)->num_oss)) 76162922Sariff#define HDAC_BSDCBL(sc, n) (_HDAC_BSDCBL((n), (sc)->num_iss, (sc)->num_oss)) 77162922Sariff#define HDAC_BSDLVI(sc, n) (_HDAC_BSDLVI((n), (sc)->num_iss, (sc)->num_oss)) 78162922Sariff#define HDAC_BSDFIFOD(sc, n) (_HDAC_BSDFIFOD((n), (sc)->num_iss, (sc)->num_oss)) 79162922Sariff#define HDAC_BSDBDPL(sc, n) (_HDAC_BSDBDPL((n), (sc)->num_iss, (sc)->num_oss)) 80162922Sariff#define HDAC_BSDBDPU(sc, n) (_HDAC_BSDBDPU((n), (sc)->num_iss, (sc)->num_oss)) 81162922Sariff 82162922Sariff/**************************************************************************** 83162922Sariff * Custom hdac malloc type 84162922Sariff ****************************************************************************/ 85162922SariffMALLOC_DECLARE(M_HDAC); 86162922Sariff 87162922Sariff/**************************************************************************** 88162922Sariff * struct hdac_mem 89162922Sariff * 90162922Sariff * Holds the resources necessary to describe the physical memory associated 91162922Sariff * with the device. 92162922Sariff ****************************************************************************/ 93162922Sariffstruct hdac_mem { 94162922Sariff struct resource *mem_res; 95162922Sariff int mem_rid; 96162922Sariff bus_space_tag_t mem_tag; 97162922Sariff bus_space_handle_t mem_handle; 98162922Sariff}; 99162922Sariff 100162922Sariff/**************************************************************************** 101162922Sariff * struct hdac_irq 102162922Sariff * 103162922Sariff * Holds the resources necessary to describe the irq associated with the 104162922Sariff * device. 105162922Sariff ****************************************************************************/ 106162922Sariffstruct hdac_irq { 107162922Sariff struct resource *irq_res; 108162922Sariff int irq_rid; 109162922Sariff void *irq_handle; 110162922Sariff}; 111162922Sariff 112162922Sariff/**************************************************************************** 113162922Sariff * struct hdac_dma 114162922Sariff * 115162922Sariff * This structure is used to hold all the information to manage the dma 116162922Sariff * states. 117162922Sariff ****************************************************************************/ 118162922Sariffstruct hdac_dma { 119162922Sariff bus_dma_tag_t dma_tag; 120162922Sariff bus_dmamap_t dma_map; 121162922Sariff bus_addr_t dma_paddr; 122167738Sariff bus_size_t dma_size; 123162922Sariff caddr_t dma_vaddr; 124162922Sariff}; 125162922Sariff 126162922Sariff/**************************************************************************** 127162922Sariff * struct hdac_rirb 128162922Sariff * 129162922Sariff * Hold a response from a verb sent to a codec received via the rirb. 130162922Sariff ****************************************************************************/ 131162922Sariffstruct hdac_rirb { 132162922Sariff uint32_t response; 133162922Sariff uint32_t response_ex; 134162922Sariff}; 135162922Sariff 136162922Sariff#define HDAC_RIRB_RESPONSE_EX_SDATA_IN_MASK 0x0000000f 137162922Sariff#define HDAC_RIRB_RESPONSE_EX_SDATA_IN_OFFSET 0 138162922Sariff#define HDAC_RIRB_RESPONSE_EX_UNSOLICITED 0x00000010 139162922Sariff 140162922Sariff#define HDAC_RIRB_RESPONSE_EX_SDATA_IN(response_ex) \ 141162922Sariff (((response_ex) & HDAC_RIRB_RESPONSE_EX_SDATA_IN_MASK) >> \ 142162922Sariff HDAC_RIRB_RESPONSE_EX_SDATA_IN_OFFSET) 143162922Sariff 144162922Sariffstruct hdac_bdle { 145162922Sariff volatile uint32_t addrl; 146162922Sariff volatile uint32_t addrh; 147162922Sariff volatile uint32_t len; 148162922Sariff volatile uint32_t ioc; 149162922Sariff} __packed; 150162922Sariff 151230130Smavstruct hdac_stream { 152230130Smav device_t dev; 153230130Smav struct hdac_dma bdl; 154230130Smav int dir; 155230130Smav int stream; 156230130Smav int blksz; 157230130Smav int running; 158230326Smav int bw; 159230326Smav int stripe; 160230130Smav uint16_t format; 161162922Sariff}; 162162922Sariff 163162922Sariffstruct hdac_softc { 164162922Sariff device_t dev; 165162922Sariff struct mtx *lock; 166162922Sariff 167162922Sariff struct intr_config_hook intrhook; 168162922Sariff 169162922Sariff struct hdac_mem mem; 170162922Sariff struct hdac_irq irq; 171162922Sariff 172230130Smav uint32_t quirks_on; 173230130Smav uint32_t quirks_off; 174171330Sariff uint32_t flags; 175230130Smav#define HDAC_F_DMA_NOCACHE 0x00000001 176162922Sariff 177162922Sariff int num_iss; 178162922Sariff int num_oss; 179162922Sariff int num_bss; 180230130Smav int num_ss; 181196762Smav int num_sdo; 182162922Sariff int support_64bit; 183162922Sariff 184162922Sariff int corb_size; 185162922Sariff struct hdac_dma corb_dma; 186162922Sariff int corb_wp; 187162922Sariff 188162922Sariff int rirb_size; 189162922Sariff struct hdac_dma rirb_dma; 190162922Sariff int rirb_rp; 191162922Sariff 192169277Sariff struct hdac_dma pos_dma; 193169277Sariff 194162922Sariff bus_dma_tag_t chan_dmat; 195162922Sariff 196230130Smav /* Polling */ 197164614Sariff int polling; 198169277Sariff int poll_ival; 199230130Smav struct callout poll_callout; 200164614Sariff 201230130Smav int unsol_registered; 202171141Sariff struct task unsolq_task; 203162922Sariff#define HDAC_UNSOLQ_MAX 64 204162922Sariff#define HDAC_UNSOLQ_READY 0 205162922Sariff#define HDAC_UNSOLQ_BUSY 1 206162922Sariff int unsolq_rp; 207162922Sariff int unsolq_wp; 208162922Sariff int unsolq_st; 209162922Sariff uint32_t unsolq[HDAC_UNSOLQ_MAX]; 210162922Sariff 211230326Smav int sdo_bw_used; 212230326Smav 213230130Smav struct hdac_stream *streams; 214230130Smav 215230130Smav struct { 216230130Smav device_t dev; 217230130Smav uint16_t vendor_id; 218230130Smav uint16_t device_id; 219230130Smav uint8_t revision_id; 220230130Smav uint8_t stepping_id; 221230130Smav int pending; 222230130Smav uint32_t response; 223230326Smav int sdi_bw_used; 224230130Smav } codecs[HDAC_CODEC_MAX]; 225162922Sariff}; 226162922Sariff 227162922Sariff#endif 228