xref: /freebsd/sys/dev/sound/pci/hda/hdac_private.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
11f0387f7SAriff Abdullah /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro 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 
301f0387f7SAriff Abdullah #ifndef _HDAC_PRIVATE_H_
311f0387f7SAriff Abdullah #define _HDAC_PRIVATE_H_
321f0387f7SAriff Abdullah 
331f0387f7SAriff Abdullah /****************************************************************************
345c924050SJoel Dahl  * Miscellaneous defines
351f0387f7SAriff Abdullah  ****************************************************************************/
361f0387f7SAriff Abdullah #define HDAC_CODEC_MAX		16
371f0387f7SAriff Abdullah 
381f0387f7SAriff Abdullah /****************************************************************************
391f0387f7SAriff Abdullah  * Helper Macros
401f0387f7SAriff Abdullah  ****************************************************************************/
411f0387f7SAriff Abdullah #define HDAC_READ_1(mem, offset)					\
421f0387f7SAriff Abdullah 	bus_space_read_1((mem)->mem_tag, (mem)->mem_handle, (offset))
431f0387f7SAriff Abdullah #define HDAC_READ_2(mem, offset)					\
441f0387f7SAriff Abdullah 	bus_space_read_2((mem)->mem_tag, (mem)->mem_handle, (offset))
451f0387f7SAriff Abdullah #define HDAC_READ_4(mem, offset)					\
461f0387f7SAriff Abdullah 	bus_space_read_4((mem)->mem_tag, (mem)->mem_handle, (offset))
471f0387f7SAriff Abdullah #define HDAC_WRITE_1(mem, offset, value)				\
481f0387f7SAriff Abdullah 	bus_space_write_1((mem)->mem_tag, (mem)->mem_handle, (offset), (value))
491f0387f7SAriff Abdullah #define HDAC_WRITE_2(mem, offset, value)				\
501f0387f7SAriff Abdullah 	bus_space_write_2((mem)->mem_tag, (mem)->mem_handle, (offset), (value))
511f0387f7SAriff Abdullah #define HDAC_WRITE_4(mem, offset, value)				\
521f0387f7SAriff Abdullah 	bus_space_write_4((mem)->mem_tag, (mem)->mem_handle, (offset), (value))
531f0387f7SAriff Abdullah 
541f0387f7SAriff Abdullah #define HDAC_ISDCTL(sc, n)	(_HDAC_ISDCTL((n), (sc)->num_iss, (sc)->num_oss))
551f0387f7SAriff Abdullah #define HDAC_ISDSTS(sc, n)	(_HDAC_ISDSTS((n), (sc)->num_iss, (sc)->num_oss))
561f0387f7SAriff Abdullah #define HDAC_ISDPICB(sc, n)	(_HDAC_ISDPICB((n), (sc)->num_iss, (sc)->num_oss))
571f0387f7SAriff Abdullah #define HDAC_ISDCBL(sc, n)	(_HDAC_ISDCBL((n), (sc)->num_iss, (sc)->num_oss))
581f0387f7SAriff Abdullah #define HDAC_ISDLVI(sc, n)	(_HDAC_ISDLVI((n), (sc)->num_iss, (sc)->num_oss))
591f0387f7SAriff Abdullah #define HDAC_ISDFIFOD(sc, n)	(_HDAC_ISDFIFOD((n), (sc)->num_iss, (sc)->num_oss))
601f0387f7SAriff Abdullah #define HDAC_ISDFMT(sc, n)	(_HDAC_ISDFMT((n), (sc)->num_iss, (sc)->num_oss))
611f0387f7SAriff Abdullah #define HDAC_ISDBDPL(sc, n)	(_HDAC_ISDBDPL((n), (sc)->num_iss, (sc)->num_oss))
621f0387f7SAriff Abdullah #define HDAC_ISDBDPU(sc, n)	(_HDAC_ISDBDPU((n), (sc)->num_iss, (sc)->num_oss))
631f0387f7SAriff Abdullah 
641f0387f7SAriff Abdullah #define HDAC_OSDCTL(sc, n)	(_HDAC_OSDCTL((n), (sc)->num_iss, (sc)->num_oss))
651f0387f7SAriff Abdullah #define HDAC_OSDSTS(sc, n)	(_HDAC_OSDSTS((n), (sc)->num_iss, (sc)->num_oss))
661f0387f7SAriff Abdullah #define HDAC_OSDPICB(sc, n)	(_HDAC_OSDPICB((n), (sc)->num_iss, (sc)->num_oss))
671f0387f7SAriff Abdullah #define HDAC_OSDCBL(sc, n)	(_HDAC_OSDCBL((n), (sc)->num_iss, (sc)->num_oss))
681f0387f7SAriff Abdullah #define HDAC_OSDLVI(sc, n)	(_HDAC_OSDLVI((n), (sc)->num_iss, (sc)->num_oss))
691f0387f7SAriff Abdullah #define HDAC_OSDFIFOD(sc, n)	(_HDAC_OSDFIFOD((n), (sc)->num_iss, (sc)->num_oss))
701f0387f7SAriff Abdullah #define HDAC_OSDBDPL(sc, n)	(_HDAC_OSDBDPL((n), (sc)->num_iss, (sc)->num_oss))
711f0387f7SAriff Abdullah #define HDAC_OSDBDPU(sc, n)	(_HDAC_OSDBDPU((n), (sc)->num_iss, (sc)->num_oss))
721f0387f7SAriff Abdullah 
731f0387f7SAriff Abdullah #define HDAC_BSDCTL(sc, n)	(_HDAC_BSDCTL((n), (sc)->num_iss, (sc)->num_oss))
741f0387f7SAriff Abdullah #define HDAC_BSDSTS(sc, n)	(_HDAC_BSDSTS((n), (sc)->num_iss, (sc)->num_oss))
751f0387f7SAriff Abdullah #define HDAC_BSDPICB(sc, n)	(_HDAC_BSDPICB((n), (sc)->num_iss, (sc)->num_oss))
761f0387f7SAriff Abdullah #define HDAC_BSDCBL(sc, n)	(_HDAC_BSDCBL((n), (sc)->num_iss, (sc)->num_oss))
771f0387f7SAriff Abdullah #define HDAC_BSDLVI(sc, n)	(_HDAC_BSDLVI((n), (sc)->num_iss, (sc)->num_oss))
781f0387f7SAriff Abdullah #define HDAC_BSDFIFOD(sc, n)	(_HDAC_BSDFIFOD((n), (sc)->num_iss, (sc)->num_oss))
791f0387f7SAriff Abdullah #define HDAC_BSDBDPL(sc, n)	(_HDAC_BSDBDPL((n), (sc)->num_iss, (sc)->num_oss))
801f0387f7SAriff Abdullah #define HDAC_BSDBDPU(sc, n)	(_HDAC_BSDBDPU((n), (sc)->num_iss, (sc)->num_oss))
811f0387f7SAriff Abdullah 
821f0387f7SAriff Abdullah /****************************************************************************
831f0387f7SAriff Abdullah  * Custom hdac malloc type
841f0387f7SAriff Abdullah  ****************************************************************************/
851f0387f7SAriff Abdullah MALLOC_DECLARE(M_HDAC);
861f0387f7SAriff Abdullah 
871f0387f7SAriff Abdullah /****************************************************************************
881f0387f7SAriff Abdullah  * struct hdac_mem
891f0387f7SAriff Abdullah  *
901f0387f7SAriff Abdullah  * Holds the resources necessary to describe the physical memory associated
911f0387f7SAriff Abdullah  * with the device.
921f0387f7SAriff Abdullah  ****************************************************************************/
931f0387f7SAriff Abdullah struct hdac_mem {
941f0387f7SAriff Abdullah 	struct resource		*mem_res;
951f0387f7SAriff Abdullah 	int			mem_rid;
961f0387f7SAriff Abdullah 	bus_space_tag_t		mem_tag;
971f0387f7SAriff Abdullah 	bus_space_handle_t	mem_handle;
981f0387f7SAriff Abdullah };
991f0387f7SAriff Abdullah 
1001f0387f7SAriff Abdullah /****************************************************************************
1011f0387f7SAriff Abdullah  * struct hdac_irq
1021f0387f7SAriff Abdullah  *
1031f0387f7SAriff Abdullah  * Holds the resources necessary to describe the irq associated with the
1041f0387f7SAriff Abdullah  * device.
1051f0387f7SAriff Abdullah  ****************************************************************************/
1061f0387f7SAriff Abdullah struct hdac_irq {
1071f0387f7SAriff Abdullah 	struct resource		*irq_res;
1081f0387f7SAriff Abdullah 	int			irq_rid;
1091f0387f7SAriff Abdullah 	void			*irq_handle;
1101f0387f7SAriff Abdullah };
1111f0387f7SAriff Abdullah 
1121f0387f7SAriff Abdullah /****************************************************************************
1131f0387f7SAriff Abdullah  * struct hdac_dma
1141f0387f7SAriff Abdullah  *
1151f0387f7SAriff Abdullah  * This structure is used to hold all the information to manage the dma
1161f0387f7SAriff Abdullah  * states.
1171f0387f7SAriff Abdullah  ****************************************************************************/
1181f0387f7SAriff Abdullah struct hdac_dma {
1191f0387f7SAriff Abdullah 	bus_dma_tag_t	dma_tag;
1201f0387f7SAriff Abdullah 	bus_dmamap_t	dma_map;
1211f0387f7SAriff Abdullah 	bus_addr_t	dma_paddr;
12294d36aa2SAriff Abdullah 	bus_size_t	dma_size;
1231f0387f7SAriff Abdullah 	caddr_t		dma_vaddr;
1241f0387f7SAriff Abdullah };
1251f0387f7SAriff Abdullah 
1261f0387f7SAriff Abdullah /****************************************************************************
1271f0387f7SAriff Abdullah  * struct hdac_rirb
1281f0387f7SAriff Abdullah  *
1291f0387f7SAriff Abdullah  * Hold a response from a verb sent to a codec received via the rirb.
1301f0387f7SAriff Abdullah  ****************************************************************************/
1311f0387f7SAriff Abdullah struct hdac_rirb {
1321f0387f7SAriff Abdullah 	uint32_t	response;
1331f0387f7SAriff Abdullah 	uint32_t	response_ex;
1341f0387f7SAriff Abdullah };
1351f0387f7SAriff Abdullah 
1361f0387f7SAriff Abdullah #define HDAC_RIRB_RESPONSE_EX_SDATA_IN_MASK	0x0000000f
1371f0387f7SAriff Abdullah #define HDAC_RIRB_RESPONSE_EX_SDATA_IN_OFFSET	0
1381f0387f7SAriff Abdullah #define HDAC_RIRB_RESPONSE_EX_UNSOLICITED	0x00000010
1391f0387f7SAriff Abdullah 
1401f0387f7SAriff Abdullah #define HDAC_RIRB_RESPONSE_EX_SDATA_IN(response_ex)			\
1411f0387f7SAriff Abdullah     (((response_ex) & HDAC_RIRB_RESPONSE_EX_SDATA_IN_MASK) >>		\
1421f0387f7SAriff Abdullah     HDAC_RIRB_RESPONSE_EX_SDATA_IN_OFFSET)
1431f0387f7SAriff Abdullah 
1441f0387f7SAriff Abdullah struct hdac_bdle {
1451f0387f7SAriff Abdullah 	volatile uint32_t addrl;
1461f0387f7SAriff Abdullah 	volatile uint32_t addrh;
1471f0387f7SAriff Abdullah 	volatile uint32_t len;
1481f0387f7SAriff Abdullah 	volatile uint32_t ioc;
1491f0387f7SAriff Abdullah } __packed;
1501f0387f7SAriff Abdullah 
1517c6b05d2SAlexander Motin struct hdac_stream {
152859159d1SAlexander Motin 	device_t	dev;
1537c6b05d2SAlexander Motin 	struct hdac_dma	bdl;
1541f0387f7SAriff Abdullah 	int		dir;
1557c6b05d2SAlexander Motin 	int		stream;
1567c6b05d2SAlexander Motin 	int		blksz;
1577c6b05d2SAlexander Motin 	int		running;
1586fa8e691SAlexander Motin 	int		bw;
1596fa8e691SAlexander Motin 	int		stripe;
1607c6b05d2SAlexander Motin 	uint16_t	format;
1611f0387f7SAriff Abdullah };
1621f0387f7SAriff Abdullah 
1631f0387f7SAriff Abdullah struct hdac_softc {
1641f0387f7SAriff Abdullah 	device_t	dev;
1651f0387f7SAriff Abdullah 	struct mtx	*lock;
1661f0387f7SAriff Abdullah 
1671f0387f7SAriff Abdullah 	struct intr_config_hook intrhook;
1681f0387f7SAriff Abdullah 
1691f0387f7SAriff Abdullah 	struct hdac_mem	mem;
1701f0387f7SAriff Abdullah 	struct hdac_irq	irq;
1711f0387f7SAriff Abdullah 
1727c6b05d2SAlexander Motin 	uint32_t	quirks_on;
1737c6b05d2SAlexander Motin 	uint32_t	quirks_off;
1740937dd1eSAriff Abdullah 	uint32_t	flags;
1757c6b05d2SAlexander Motin #define HDAC_F_DMA_NOCACHE	0x00000001
1761f0387f7SAriff Abdullah 
1771f0387f7SAriff Abdullah 	int		num_iss;
1781f0387f7SAriff Abdullah 	int		num_oss;
1791f0387f7SAriff Abdullah 	int		num_bss;
1807c6b05d2SAlexander Motin 	int		num_ss;
18146681d6eSAlexander Motin 	int		num_sdo;
1821f0387f7SAriff Abdullah 	int		support_64bit;
1831f0387f7SAriff Abdullah 
1841f0387f7SAriff Abdullah 	int		corb_size;
1851f0387f7SAriff Abdullah 	struct hdac_dma corb_dma;
1861f0387f7SAriff Abdullah 	int		corb_wp;
1871f0387f7SAriff Abdullah 
1881f0387f7SAriff Abdullah 	int		rirb_size;
1891f0387f7SAriff Abdullah 	struct hdac_dma	rirb_dma;
1901f0387f7SAriff Abdullah 	int		rirb_rp;
1911f0387f7SAriff Abdullah 
19271e3af01SAriff Abdullah 	struct hdac_dma	pos_dma;
19371e3af01SAriff Abdullah 
1941f0387f7SAriff Abdullah 	bus_dma_tag_t		chan_dmat;
1951f0387f7SAriff Abdullah 
1967c6b05d2SAlexander Motin 	/* Polling */
197a580b31aSAriff Abdullah 	int			polling;
19871e3af01SAriff Abdullah 	int			poll_ival;
1997c6b05d2SAlexander Motin 	struct callout		poll_callout;
200a580b31aSAriff Abdullah 
2017c6b05d2SAlexander Motin 	int			unsol_registered;
202e5ad83a7SAriff Abdullah 	struct task		unsolq_task;
2031f0387f7SAriff Abdullah #define HDAC_UNSOLQ_MAX		64
2041f0387f7SAriff Abdullah #define HDAC_UNSOLQ_READY	0
2051f0387f7SAriff Abdullah #define HDAC_UNSOLQ_BUSY	1
2061f0387f7SAriff Abdullah 	int		unsolq_rp;
2071f0387f7SAriff Abdullah 	int		unsolq_wp;
2081f0387f7SAriff Abdullah 	int		unsolq_st;
2091f0387f7SAriff Abdullah 	uint32_t	unsolq[HDAC_UNSOLQ_MAX];
2101f0387f7SAriff Abdullah 
2116fa8e691SAlexander Motin 	int			sdo_bw_used;
2126fa8e691SAlexander Motin 
2137c6b05d2SAlexander Motin 	struct hdac_stream	*streams;
2141f0387f7SAriff Abdullah 
2157c6b05d2SAlexander Motin 	struct {
2167c6b05d2SAlexander Motin 		device_t	dev;
2177c6b05d2SAlexander Motin 		uint16_t	vendor_id;
2187c6b05d2SAlexander Motin 		uint16_t	device_id;
2197c6b05d2SAlexander Motin 		uint8_t		revision_id;
2207c6b05d2SAlexander Motin 		uint8_t		stepping_id;
2217c6b05d2SAlexander Motin 		int		pending;
2227c6b05d2SAlexander Motin 		uint32_t	response;
2236fa8e691SAlexander Motin 		int		sdi_bw_used;
2247c6b05d2SAlexander Motin 	} codecs[HDAC_CODEC_MAX];
2257c6b05d2SAlexander Motin };
2261f0387f7SAriff Abdullah 
2271f0387f7SAriff Abdullah #endif
228