11f0387f7SAriff Abdullah /*- 2*718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*718cf2ccSPedro F. Giffuni * 41f0387f7SAriff Abdullah * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca> 57c6b05d2SAlexander Motin * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org> 61f0387f7SAriff Abdullah * All rights reserved. 71f0387f7SAriff Abdullah * 81f0387f7SAriff Abdullah * Redistribution and use in source and binary forms, with or without 91f0387f7SAriff Abdullah * modification, are permitted provided that the following conditions 101f0387f7SAriff Abdullah * are met: 111f0387f7SAriff Abdullah * 1. Redistributions of source code must retain the above copyright 121f0387f7SAriff Abdullah * notice, this list of conditions and the following disclaimer. 131f0387f7SAriff Abdullah * 2. Redistributions in binary form must reproduce the above copyright 141f0387f7SAriff Abdullah * notice, this list of conditions and the following disclaimer in the 151f0387f7SAriff Abdullah * documentation and/or other materials provided with the distribution. 161f0387f7SAriff Abdullah * 171f0387f7SAriff Abdullah * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 181f0387f7SAriff Abdullah * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191f0387f7SAriff Abdullah * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201f0387f7SAriff Abdullah * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 211f0387f7SAriff Abdullah * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221f0387f7SAriff Abdullah * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231f0387f7SAriff Abdullah * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241f0387f7SAriff Abdullah * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251f0387f7SAriff Abdullah * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261f0387f7SAriff Abdullah * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271f0387f7SAriff Abdullah * SUCH DAMAGE. 281f0387f7SAriff Abdullah * 291f0387f7SAriff Abdullah * $FreeBSD$ 301f0387f7SAriff Abdullah */ 311f0387f7SAriff Abdullah 321f0387f7SAriff Abdullah #ifndef _HDAC_PRIVATE_H_ 331f0387f7SAriff Abdullah #define _HDAC_PRIVATE_H_ 341f0387f7SAriff Abdullah 351f0387f7SAriff Abdullah /**************************************************************************** 365c924050SJoel Dahl * Miscellaneous defines 371f0387f7SAriff Abdullah ****************************************************************************/ 381f0387f7SAriff Abdullah #define HDAC_CODEC_MAX 16 391f0387f7SAriff Abdullah 401f0387f7SAriff Abdullah /**************************************************************************** 411f0387f7SAriff Abdullah * Helper Macros 421f0387f7SAriff Abdullah ****************************************************************************/ 431f0387f7SAriff Abdullah #define HDAC_READ_1(mem, offset) \ 441f0387f7SAriff Abdullah bus_space_read_1((mem)->mem_tag, (mem)->mem_handle, (offset)) 451f0387f7SAriff Abdullah #define HDAC_READ_2(mem, offset) \ 461f0387f7SAriff Abdullah bus_space_read_2((mem)->mem_tag, (mem)->mem_handle, (offset)) 471f0387f7SAriff Abdullah #define HDAC_READ_4(mem, offset) \ 481f0387f7SAriff Abdullah bus_space_read_4((mem)->mem_tag, (mem)->mem_handle, (offset)) 491f0387f7SAriff Abdullah #define HDAC_WRITE_1(mem, offset, value) \ 501f0387f7SAriff Abdullah bus_space_write_1((mem)->mem_tag, (mem)->mem_handle, (offset), (value)) 511f0387f7SAriff Abdullah #define HDAC_WRITE_2(mem, offset, value) \ 521f0387f7SAriff Abdullah bus_space_write_2((mem)->mem_tag, (mem)->mem_handle, (offset), (value)) 531f0387f7SAriff Abdullah #define HDAC_WRITE_4(mem, offset, value) \ 541f0387f7SAriff Abdullah bus_space_write_4((mem)->mem_tag, (mem)->mem_handle, (offset), (value)) 551f0387f7SAriff Abdullah 561f0387f7SAriff Abdullah #define HDAC_ISDCTL(sc, n) (_HDAC_ISDCTL((n), (sc)->num_iss, (sc)->num_oss)) 571f0387f7SAriff Abdullah #define HDAC_ISDSTS(sc, n) (_HDAC_ISDSTS((n), (sc)->num_iss, (sc)->num_oss)) 581f0387f7SAriff Abdullah #define HDAC_ISDPICB(sc, n) (_HDAC_ISDPICB((n), (sc)->num_iss, (sc)->num_oss)) 591f0387f7SAriff Abdullah #define HDAC_ISDCBL(sc, n) (_HDAC_ISDCBL((n), (sc)->num_iss, (sc)->num_oss)) 601f0387f7SAriff Abdullah #define HDAC_ISDLVI(sc, n) (_HDAC_ISDLVI((n), (sc)->num_iss, (sc)->num_oss)) 611f0387f7SAriff Abdullah #define HDAC_ISDFIFOD(sc, n) (_HDAC_ISDFIFOD((n), (sc)->num_iss, (sc)->num_oss)) 621f0387f7SAriff Abdullah #define HDAC_ISDFMT(sc, n) (_HDAC_ISDFMT((n), (sc)->num_iss, (sc)->num_oss)) 631f0387f7SAriff Abdullah #define HDAC_ISDBDPL(sc, n) (_HDAC_ISDBDPL((n), (sc)->num_iss, (sc)->num_oss)) 641f0387f7SAriff Abdullah #define HDAC_ISDBDPU(sc, n) (_HDAC_ISDBDPU((n), (sc)->num_iss, (sc)->num_oss)) 651f0387f7SAriff Abdullah 661f0387f7SAriff Abdullah #define HDAC_OSDCTL(sc, n) (_HDAC_OSDCTL((n), (sc)->num_iss, (sc)->num_oss)) 671f0387f7SAriff Abdullah #define HDAC_OSDSTS(sc, n) (_HDAC_OSDSTS((n), (sc)->num_iss, (sc)->num_oss)) 681f0387f7SAriff Abdullah #define HDAC_OSDPICB(sc, n) (_HDAC_OSDPICB((n), (sc)->num_iss, (sc)->num_oss)) 691f0387f7SAriff Abdullah #define HDAC_OSDCBL(sc, n) (_HDAC_OSDCBL((n), (sc)->num_iss, (sc)->num_oss)) 701f0387f7SAriff Abdullah #define HDAC_OSDLVI(sc, n) (_HDAC_OSDLVI((n), (sc)->num_iss, (sc)->num_oss)) 711f0387f7SAriff Abdullah #define HDAC_OSDFIFOD(sc, n) (_HDAC_OSDFIFOD((n), (sc)->num_iss, (sc)->num_oss)) 721f0387f7SAriff Abdullah #define HDAC_OSDBDPL(sc, n) (_HDAC_OSDBDPL((n), (sc)->num_iss, (sc)->num_oss)) 731f0387f7SAriff Abdullah #define HDAC_OSDBDPU(sc, n) (_HDAC_OSDBDPU((n), (sc)->num_iss, (sc)->num_oss)) 741f0387f7SAriff Abdullah 751f0387f7SAriff Abdullah #define HDAC_BSDCTL(sc, n) (_HDAC_BSDCTL((n), (sc)->num_iss, (sc)->num_oss)) 761f0387f7SAriff Abdullah #define HDAC_BSDSTS(sc, n) (_HDAC_BSDSTS((n), (sc)->num_iss, (sc)->num_oss)) 771f0387f7SAriff Abdullah #define HDAC_BSDPICB(sc, n) (_HDAC_BSDPICB((n), (sc)->num_iss, (sc)->num_oss)) 781f0387f7SAriff Abdullah #define HDAC_BSDCBL(sc, n) (_HDAC_BSDCBL((n), (sc)->num_iss, (sc)->num_oss)) 791f0387f7SAriff Abdullah #define HDAC_BSDLVI(sc, n) (_HDAC_BSDLVI((n), (sc)->num_iss, (sc)->num_oss)) 801f0387f7SAriff Abdullah #define HDAC_BSDFIFOD(sc, n) (_HDAC_BSDFIFOD((n), (sc)->num_iss, (sc)->num_oss)) 811f0387f7SAriff Abdullah #define HDAC_BSDBDPL(sc, n) (_HDAC_BSDBDPL((n), (sc)->num_iss, (sc)->num_oss)) 821f0387f7SAriff Abdullah #define HDAC_BSDBDPU(sc, n) (_HDAC_BSDBDPU((n), (sc)->num_iss, (sc)->num_oss)) 831f0387f7SAriff Abdullah 841f0387f7SAriff Abdullah /**************************************************************************** 851f0387f7SAriff Abdullah * Custom hdac malloc type 861f0387f7SAriff Abdullah ****************************************************************************/ 871f0387f7SAriff Abdullah MALLOC_DECLARE(M_HDAC); 881f0387f7SAriff Abdullah 891f0387f7SAriff Abdullah /**************************************************************************** 901f0387f7SAriff Abdullah * struct hdac_mem 911f0387f7SAriff Abdullah * 921f0387f7SAriff Abdullah * Holds the resources necessary to describe the physical memory associated 931f0387f7SAriff Abdullah * with the device. 941f0387f7SAriff Abdullah ****************************************************************************/ 951f0387f7SAriff Abdullah struct hdac_mem { 961f0387f7SAriff Abdullah struct resource *mem_res; 971f0387f7SAriff Abdullah int mem_rid; 981f0387f7SAriff Abdullah bus_space_tag_t mem_tag; 991f0387f7SAriff Abdullah bus_space_handle_t mem_handle; 1001f0387f7SAriff Abdullah }; 1011f0387f7SAriff Abdullah 1021f0387f7SAriff Abdullah /**************************************************************************** 1031f0387f7SAriff Abdullah * struct hdac_irq 1041f0387f7SAriff Abdullah * 1051f0387f7SAriff Abdullah * Holds the resources necessary to describe the irq associated with the 1061f0387f7SAriff Abdullah * device. 1071f0387f7SAriff Abdullah ****************************************************************************/ 1081f0387f7SAriff Abdullah struct hdac_irq { 1091f0387f7SAriff Abdullah struct resource *irq_res; 1101f0387f7SAriff Abdullah int irq_rid; 1111f0387f7SAriff Abdullah void *irq_handle; 1121f0387f7SAriff Abdullah }; 1131f0387f7SAriff Abdullah 1141f0387f7SAriff Abdullah /**************************************************************************** 1151f0387f7SAriff Abdullah * struct hdac_dma 1161f0387f7SAriff Abdullah * 1171f0387f7SAriff Abdullah * This structure is used to hold all the information to manage the dma 1181f0387f7SAriff Abdullah * states. 1191f0387f7SAriff Abdullah ****************************************************************************/ 1201f0387f7SAriff Abdullah struct hdac_dma { 1211f0387f7SAriff Abdullah bus_dma_tag_t dma_tag; 1221f0387f7SAriff Abdullah bus_dmamap_t dma_map; 1231f0387f7SAriff Abdullah bus_addr_t dma_paddr; 12494d36aa2SAriff Abdullah bus_size_t dma_size; 1251f0387f7SAriff Abdullah caddr_t dma_vaddr; 1261f0387f7SAriff Abdullah }; 1271f0387f7SAriff Abdullah 1281f0387f7SAriff Abdullah /**************************************************************************** 1291f0387f7SAriff Abdullah * struct hdac_rirb 1301f0387f7SAriff Abdullah * 1311f0387f7SAriff Abdullah * Hold a response from a verb sent to a codec received via the rirb. 1321f0387f7SAriff Abdullah ****************************************************************************/ 1331f0387f7SAriff Abdullah struct hdac_rirb { 1341f0387f7SAriff Abdullah uint32_t response; 1351f0387f7SAriff Abdullah uint32_t response_ex; 1361f0387f7SAriff Abdullah }; 1371f0387f7SAriff Abdullah 1381f0387f7SAriff Abdullah #define HDAC_RIRB_RESPONSE_EX_SDATA_IN_MASK 0x0000000f 1391f0387f7SAriff Abdullah #define HDAC_RIRB_RESPONSE_EX_SDATA_IN_OFFSET 0 1401f0387f7SAriff Abdullah #define HDAC_RIRB_RESPONSE_EX_UNSOLICITED 0x00000010 1411f0387f7SAriff Abdullah 1421f0387f7SAriff Abdullah #define HDAC_RIRB_RESPONSE_EX_SDATA_IN(response_ex) \ 1431f0387f7SAriff Abdullah (((response_ex) & HDAC_RIRB_RESPONSE_EX_SDATA_IN_MASK) >> \ 1441f0387f7SAriff Abdullah HDAC_RIRB_RESPONSE_EX_SDATA_IN_OFFSET) 1451f0387f7SAriff Abdullah 1461f0387f7SAriff Abdullah struct hdac_bdle { 1471f0387f7SAriff Abdullah volatile uint32_t addrl; 1481f0387f7SAriff Abdullah volatile uint32_t addrh; 1491f0387f7SAriff Abdullah volatile uint32_t len; 1501f0387f7SAriff Abdullah volatile uint32_t ioc; 1511f0387f7SAriff Abdullah } __packed; 1521f0387f7SAriff Abdullah 1537c6b05d2SAlexander Motin struct hdac_stream { 154859159d1SAlexander Motin device_t dev; 1557c6b05d2SAlexander Motin struct hdac_dma bdl; 1561f0387f7SAriff Abdullah int dir; 1577c6b05d2SAlexander Motin int stream; 1587c6b05d2SAlexander Motin int blksz; 1597c6b05d2SAlexander Motin int running; 1606fa8e691SAlexander Motin int bw; 1616fa8e691SAlexander Motin int stripe; 1627c6b05d2SAlexander Motin uint16_t format; 1631f0387f7SAriff Abdullah }; 1641f0387f7SAriff Abdullah 1651f0387f7SAriff Abdullah struct hdac_softc { 1661f0387f7SAriff Abdullah device_t dev; 1671f0387f7SAriff Abdullah struct mtx *lock; 1681f0387f7SAriff Abdullah 1691f0387f7SAriff Abdullah struct intr_config_hook intrhook; 1701f0387f7SAriff Abdullah 1711f0387f7SAriff Abdullah struct hdac_mem mem; 1721f0387f7SAriff Abdullah struct hdac_irq irq; 1731f0387f7SAriff Abdullah 1747c6b05d2SAlexander Motin uint32_t quirks_on; 1757c6b05d2SAlexander Motin uint32_t quirks_off; 1760937dd1eSAriff Abdullah uint32_t flags; 1777c6b05d2SAlexander Motin #define HDAC_F_DMA_NOCACHE 0x00000001 1781f0387f7SAriff Abdullah 1791f0387f7SAriff Abdullah int num_iss; 1801f0387f7SAriff Abdullah int num_oss; 1811f0387f7SAriff Abdullah int num_bss; 1827c6b05d2SAlexander Motin int num_ss; 18346681d6eSAlexander Motin int num_sdo; 1841f0387f7SAriff Abdullah int support_64bit; 1851f0387f7SAriff Abdullah 1861f0387f7SAriff Abdullah int corb_size; 1871f0387f7SAriff Abdullah struct hdac_dma corb_dma; 1881f0387f7SAriff Abdullah int corb_wp; 1891f0387f7SAriff Abdullah 1901f0387f7SAriff Abdullah int rirb_size; 1911f0387f7SAriff Abdullah struct hdac_dma rirb_dma; 1921f0387f7SAriff Abdullah int rirb_rp; 1931f0387f7SAriff Abdullah 19471e3af01SAriff Abdullah struct hdac_dma pos_dma; 19571e3af01SAriff Abdullah 1961f0387f7SAriff Abdullah bus_dma_tag_t chan_dmat; 1971f0387f7SAriff Abdullah 1987c6b05d2SAlexander Motin /* Polling */ 199a580b31aSAriff Abdullah int polling; 20071e3af01SAriff Abdullah int poll_ival; 2017c6b05d2SAlexander Motin struct callout poll_callout; 202a580b31aSAriff Abdullah 2037c6b05d2SAlexander Motin int unsol_registered; 204e5ad83a7SAriff Abdullah struct task unsolq_task; 2051f0387f7SAriff Abdullah #define HDAC_UNSOLQ_MAX 64 2061f0387f7SAriff Abdullah #define HDAC_UNSOLQ_READY 0 2071f0387f7SAriff Abdullah #define HDAC_UNSOLQ_BUSY 1 2081f0387f7SAriff Abdullah int unsolq_rp; 2091f0387f7SAriff Abdullah int unsolq_wp; 2101f0387f7SAriff Abdullah int unsolq_st; 2111f0387f7SAriff Abdullah uint32_t unsolq[HDAC_UNSOLQ_MAX]; 2121f0387f7SAriff Abdullah 2136fa8e691SAlexander Motin int sdo_bw_used; 2146fa8e691SAlexander Motin 2157c6b05d2SAlexander Motin struct hdac_stream *streams; 2161f0387f7SAriff Abdullah 2177c6b05d2SAlexander Motin struct { 2187c6b05d2SAlexander Motin device_t dev; 2197c6b05d2SAlexander Motin uint16_t vendor_id; 2207c6b05d2SAlexander Motin uint16_t device_id; 2217c6b05d2SAlexander Motin uint8_t revision_id; 2227c6b05d2SAlexander Motin uint8_t stepping_id; 2237c6b05d2SAlexander Motin int pending; 2247c6b05d2SAlexander Motin uint32_t response; 2256fa8e691SAlexander Motin int sdi_bw_used; 2267c6b05d2SAlexander Motin } codecs[HDAC_CODEC_MAX]; 2277c6b05d2SAlexander Motin }; 2281f0387f7SAriff Abdullah 2291f0387f7SAriff Abdullah #endif 230