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