xref: /haiku/src/add-ons/kernel/drivers/audio/cmedia/cm_private.h (revision 5ea01a50c2b62a3f587166c4df12527a7919f600)
1 /*
2 	Copyright 1999, Be Incorporated.   All Rights Reserved.
3 	This file may be used under the terms of the Be Sample Code License.
4 */
5 
6 #if !defined(_CM_PRIVATE_H)
7 #define _CM_PRIVATE_H
8 
9 #include "cmedia_pci.h"
10 
11 #include <KernelExport.h>
12 #include <PCI.h>
13 
14 #if !defined(DEBUG)
15 #define DEBUG 0
16 #endif
17 
18 
19 #define NUM_CARDS 3
20 #define DEVNAME 32
21 
22 
23 #define EXPORT __attribute__((visibility("default")))
24 
25 #if defined(__POWERPC__)
26 #define EIEIO() __eieio()
27 #else
28 #define EIEIO()
29 #endif
30 
31 #if DEBUG
32 #define ddprintf(x) dprintf x
33 #define KTRACE() kprintf("%s %d\n", __FILE__, __LINE__)
34 #else
35 #define ddprintf(x)
36 #define KTRACE()
37 #endif
38 
39 /* neither value may be larger than 65536 */
40 #define PLAYBACK_BUF_SIZE 2048
41 #define RECORD_BUF_SIZE PLAYBACK_BUF_SIZE
42 /* always create this much, so larger buffers can be requested */
43 #define MIN_MEMORY_SIZE 32768
44 
45 /* clock crystal frequency */
46 #define F_REF 24576000
47 /* data book says 80 MHz ... */
48 #define MIN_FREQ 80000000
49 /* tolerance for sample rate clock derivation - book has this at 0.005 */
50 #define TOLERANCE 0.001
51 
52 /* there are five logical devices: midi, joystick, pcm, mux and mixer */
53 
54 typedef struct _midi_dev
55 {
56 	struct _cmedia_pci_dev *card;
57 	void *		driver;
58 	void *		cookie;
59 	int32		count;
60 	char		name[64];
61 } midi_dev;
62 
63 typedef struct _joy_dev
64 {
65 	void *		driver;
66 	char		name1[64];
67 } joy_dev;
68 
69 typedef cmedia_pci_audio_format pcm_cfg;
70 typedef cmedia_pci_audio_buf_header pcm_buf_hdr;
71 
72 enum
73 {	/* these map to the mode enable bits in the CMX13 register */
74 	kPlayback = 1,
75 	kRecord = 2
76 };
77 
78 typedef struct
79 {
80 	struct _cmedia_pci_dev * card;
81 	char		name[DEVNAME];
82 	char		oldname[DEVNAME];
83 	sem_id		init_sem;
84 	int32		open_count;
85 	int32		open_mode;
86 
87 /* playback from a cyclic, small-ish buffer */
88 
89 	spinlock	wr_lock;
90 	int			dma_a;
91 	vuchar *	wr_1;
92 	vuchar *	wr_2;
93 	vuchar *	wr_cur;
94 	size_t		wr_size;
95 	int			wr_silence;
96 	int32		write_waiting;
97 	sem_id		write_sem;
98 	size_t		was_written;
99 	uint32		wr_skipped;
100 	sem_id		wr_entry;
101 	bigtime_t	wr_time;
102 	uint64		wr_total;
103 	sem_id		wr_time_sem;
104 	int32		wr_time_wait;
105 
106 /* recording into a cyclic, somewhat larger buffer */
107 
108 	spinlock	rd_lock;
109 	int			dma_c;
110 	vuchar *	rd_1;
111 	vuchar *	rd_2;
112 	vuchar *	rd_cur;
113 	size_t		rd_size;
114 	int32		read_waiting;
115 	sem_id		read_sem;
116 	size_t		was_read;
117 	bigtime_t	next_rd_time;
118 	bigtime_t	rd_time;
119 	uint32		rd_skipped;	/* count of misses */
120 	sem_id		rd_entry;
121 	uint64		rd_total;
122 	sem_id		rd_time_sem;
123 	int32		rd_time_wait;
124 
125 /* buffers are owned by the device record (because of allocation) */
126 
127 	pcm_cfg		config;
128 
129 	sem_id		old_cap_sem;
130 	sem_id		old_play_sem;
131 } pcm_dev;
132 
133 typedef struct
134 {
135 	struct _cmedia_pci_dev * card;
136 	char		name[DEVNAME];
137 	int32		open_count;
138 } mux_dev;
139 
140 typedef struct
141 {
142 	struct _cmedia_pci_dev * card;
143 	char		name[DEVNAME];
144 	int32		open_count;
145 } mixer_dev;
146 
147 typedef struct _cmedia_pci_dev
148 {
149 	char		name[DEVNAME];	/* used for resources */
150 	spinlock	hardware;
151 	int			enhanced;		/* offset to port */
152 	int32		inth_count;
153 	int			dma_base;
154 	size_t		low_size;		/* size of low memory */
155 	vuchar *	low_mem;
156 	phys_addr_t	low_phys;		/* physical address */
157 	area_id		map_low;		/* area pointing to low memory */
158 	pci_info	info;
159 	midi_dev	midi;
160 	joy_dev		joy;
161 	pcm_dev		pcm;
162 	mux_dev		mux;
163 	mixer_dev	mixer;
164 } cmedia_pci_dev;
165 
166 
167 extern int32 num_cards;
168 extern cmedia_pci_dev cards[NUM_CARDS];
169 
170 
171 extern void set_direct(cmedia_pci_dev *, int, uchar, uchar);
172 extern uchar get_direct(cmedia_pci_dev *, int);
173 extern void set_indirect(cmedia_pci_dev *, int, uchar, uchar);
174 extern uchar get_indirect(cmedia_pci_dev *, int);
175 extern void increment_interrupt_handler(cmedia_pci_dev *);
176 extern void decrement_interrupt_handler(cmedia_pci_dev *);
177 
178 
179 extern bool midi_interrupt(cmedia_pci_dev *);
180 extern void midi_interrupt_op(int32 op, void * data);
181 extern bool dma_a_interrupt(cmedia_pci_dev *);
182 extern bool dma_c_interrupt(cmedia_pci_dev *);
183 
184 extern void PCI_IO_WR(int offset, uint8 val);
185 extern uint8 PCI_IO_RD(int offset);
186 extern uint32 PCI_IO_RD_32(int offset);
187 
188 extern generic_gameport_module * gameport;
189 
190 #endif	/*	_CM_PRIVATE_H	*/
191 
192