1 /* $NetBSD: cc.h,v 1.14 2002/04/25 09:20:26 aymeric Exp $ */ 2 3 /* 4 * Copyright (c) 1994 Christian E. Hopps 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Christian E. Hopps. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #if ! defined (_CC_H) 34 #define _CC_H 35 36 #include <sys/queue.h> 37 #include <amiga/amiga/cc_registers.h> 38 39 #ifndef __powerpc__ 40 #include "opt_lev6_defer.h" 41 #endif /* __powerpc__ */ 42 43 #if ! defined (HIADDR) 44 #define HIADDR(x) (u_short)((((unsigned long)(x))>>16)&0xffff) 45 #endif 46 #if ! defined (LOADDR) 47 #define LOADDR(x) (u_short)(((unsigned long)(x))&0xffff) 48 #endif 49 50 51 /* 52 * Audio stuff 53 */ 54 struct audio_channel { 55 u_short play_count; 56 short isaudio; 57 void (*handler)(int); 58 }; 59 60 #ifdef LEV6_DEFER 61 #define AUCC_MAXINT 3 62 #define AUCC_ALLINTF (INTF_AUD0|INTF_AUD1|INTF_AUD2) 63 #else 64 #define AUCC_MAXINT 4 65 #define AUCC_ALLINTF (INTF_AUD0|INTF_AUD1|INTF_AUD2|INTF_AUD3) 66 #endif 67 /* 68 * Define this one unconditionally; we may use AUD3 as slave channel 69 * with LEV6_DEFER 70 */ 71 #define AUCC_ALLDMAF (DMAF_AUD0|DMAF_AUD1|DMAF_AUD2|DMAF_AUD3) 72 73 /* 74 * Vertical blank iterrupt sever chains. 75 */ 76 77 struct vbl_node { 78 LIST_ENTRY(vbl_node) link; 79 short priority; /* Private. */ 80 short flags; /* Private. */ 81 void (*function)(register void *); /* put function pointer here */ 82 void *data; /* functions data. */ 83 }; 84 85 enum vbl_node_bits { 86 VBLNB_OFF, /* don't call me right now. */ 87 VBLNB_TURNOFF, /* turn function off. */ 88 }; 89 90 enum vlb_node_flags { 91 VBLNF_OFF = 1 << VBLNB_OFF, 92 VBLNF_TURNOFF = 1 << VBLNB_TURNOFF, 93 }; 94 95 /* 96 * Blitter stuff. 97 */ 98 99 #define BLT_SHIFT_MASK(shift) (0xf&shift) 100 101 #define MAKEBOOL(val) (val ? 1 : 0) 102 103 #define DMAADDR(lng) (u_long)(((0x7 & lng) << 16)|(lng & 0xffff)) 104 105 #define MAKE_BLTCON0(shift_a, use_a, use_b, use_c, use_d, minterm) \ 106 ((0x0000) | (BLT_SHIFT_MASK(shift_a) << 12) | \ 107 (use_a << 11) | (use_b << 10) | (use_c << 9) | (use_d << 8) | \ 108 (minterm)) 109 110 #define MAKE_BLTCON1(shift_b, efe, ife, fc, desc) \ 111 ((0x0000) | (BLT_SHIFT_MASK(shift_b) << 12) | (efe << 4) | \ 112 (ife << 3) | (fc << 2) | (desc << 1)) 113 114 /* 115 * Copper stuff. 116 */ 117 118 typedef struct copper_list { 119 union j { 120 struct k { 121 u_short opcode; 122 u_short operand; 123 } inst; 124 u_long data; 125 } cp; 126 } cop_t; 127 128 #define CI_MOVE(x) (0x7ffe & x) 129 #define CI_WAIT(h,v) (((0x7f&v)<<8)|(0xfe&h)|(0x0001)) 130 #define CI_SKIP(x) (((0x7f&v)<<8)|(0xfe&h)|(0x0001)) 131 132 #define CD_MOVE(x) (x) 133 #define CD_WAIT(x) (x & 0xfffe) 134 #define CD_SKIP(x) (x|0x0001) 135 136 #define CBUMP(c) (c++) 137 138 #define CMOVE(c,r,v) do { \ 139 c->cp.data=((CI_MOVE(r)<<16)|(CD_MOVE(v))); \ 140 CBUMP (c); \ 141 } while(0) 142 #define CWAIT(c,h,v) do { \ 143 c->cp.data=((CI_WAIT(h,v) << 16)|CD_WAIT(0xfffe)); \ 144 CBUMP (c); \ 145 } while(0) 146 #define CSKIP(c,h,v) do { \ 147 c->cp.data=((CI_SKIP(h,v)<<16)|CD_SKIP(0xffff)); \ 148 CBUMP (c); \ 149 } while(0) 150 #define CEND(c) do { \ 151 c->cp.data=0xfffffffe; \ 152 CBUMP (c); \ 153 } while(0) 154 155 /* 156 * Chipmem allocator stuff. 157 */ 158 159 struct mem_node { 160 CIRCLEQ_ENTRY(mem_node) link; 161 CIRCLEQ_ENTRY(mem_node) free_link; 162 u_long size; /* size of memory following node. */ 163 }; 164 165 #define CM_BLOCKSIZE 0x4 166 #define CM_BLOCKMASK (~(CM_BLOCKSIZE - 1)) 167 #define MNODES_MEM(mn) ((u_char *)(&mn[1])) 168 #define PREP_DMA_MEM(mem) (void *)((caddr_t)mem - CHIPMEMADDR) 169 170 extern vaddr_t CHIPMEMADDR; 171 extern vaddr_t chipmem_start; 172 extern vaddr_t chipmem_end; 173 #define CHIPMEMBASE (0x00000000) 174 #define CHIPMEMTOP (0x00200000) 175 #define NCHIPMEMPG btoc(CHIPMEMTOP - CHIPMEMBASE) 176 177 /* 178 * Prototypes. 179 */ 180 void custom_chips_init(void); 181 /* vertical blank server chain */ 182 void cc_init_vbl(void); 183 void add_vbl_function(struct vbl_node *, short, void *); 184 void remove_vbl_function(struct vbl_node *); 185 void turn_vbl_function_off(struct vbl_node *); 186 void turn_vbl_function_on(struct vbl_node *); 187 /* blitter */ 188 void cc_init_blitter(void); 189 int is_blitter_busy(void); 190 void wait_blit(void); 191 void blitter_handler(void); 192 void do_blit(u_short); 193 void set_blitter_control(u_short, u_short); 194 void set_blitter_mods(u_short, u_short, u_short, u_short); 195 void set_blitter_masks(u_short, u_short); 196 void set_blitter_data(u_short, u_short, u_short); 197 void set_blitter_pointers(void *, void *, void *, void *); 198 /* copper */ 199 void install_copper_list(cop_t *); 200 cop_t *find_copper_inst(cop_t *, u_short); 201 void cc_init_copper(void); 202 void copper_handler(void); 203 /* audio */ 204 void cc_init_audio(void); 205 void play_sample(u_short, u_short *, u_short, u_short, u_short, u_long); 206 void audio_handler(void); 207 /* chipmem */ 208 void cc_init_chipmem(void); 209 void * alloc_chipmem(u_long); 210 void free_chipmem(void *); 211 u_long avail_chipmem(int); 212 u_long sizeof_chipmem(void *); 213 214 void wait_tof(void); 215 void vbl_handler(void); 216 void *chipmem_steal(long); 217 218 #endif /* _CC_H */ 219