KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
asic.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  dc/asic.h
4  Copyright (C) 2001-2002 Dan Potter
5 
6 */
7 
8 /** \file dc/asic.h
9  \brief Dreamcast ASIC event handling support.
10 
11  This file provides definitions of the events that the ASIC (a part of the
12  PVR) in the Dreamcast can trigger as IRQs, and ways to set responders for
13  those events. Pretty much, this covers all IRQs that aren't generated
14  internally in the SH4 (SCIF and the SH4 DMAC can generate their own IRQs,
15  as well as the trapa instruction, and various exceptions -- those are not
16  dealt with here).
17 
18  \author Dan Potter
19 */
20 
21 #ifndef __DC_ASIC_H
22 #define __DC_ASIC_H
23 
24 #include <sys/cdefs.h>
25 __BEGIN_DECLS
26 
27 #include <arch/types.h>
28 
29 /* All event codes are two 8-bit integers; the top integer is the event code
30  register to look in to check the event (and to acknolwedge it). The
31  register to check is 0xa05f6900+4*regnum. The bottom integer is the
32  bit index within that register. */
33 
34 /** \defgroup asic_events ASIC event codes
35  @{
36 */
37 
38 /** \defgroup asic_pvr_evts Event codes for the PVR chip
39 
40  These are events that the PVR itself generates that can be hooked.
41  @{
42 */
43 #define ASIC_EVT_PVR_RENDERDONE 0x0002 /**< \brief Render completed */
44 #define ASIC_EVT_PVR_SCANINT1 0x0003 /**< \brief Scanline interrupt 1 */
45 #define ASIC_EVT_PVR_SCANINT2 0x0004 /**< \brief Scanline interrupt 2 */
46 #define ASIC_EVT_PVR_VBLINT 0x0005 /**< \brief VBL interrupt */
47 #define ASIC_EVT_PVR_OPAQUEDONE 0x0007 /**< \brief Opaque list completed */
48 #define ASIC_EVT_PVR_OPAQUEMODDONE 0x0008 /**< \brief Opaque modifiers completed */
49 #define ASIC_EVT_PVR_TRANSDONE 0x0009 /**< \brief Transparent list completed */
50 #define ASIC_EVT_PVR_TRANSMODDONE 0x000a /**< \brief Transparent modifiers completed */
51 #define ASIC_EVT_PVR_DMA 0x0013 /**< \brief PVR DMA complete */
52 #define ASIC_EVT_PVR_PTDONE 0x0015 /**< \brief Punch-thrus completed */
53 #define ASIC_EVT_PVR_PRIMOUTOFMEM 0x0202 /**< \brief Out of primitive memory */
54 #define ASIC_EVT_PVR_MATOUTOFMEM 0x0203 /**< \brief Out of matrix memory */
55 /** @} */
56 
57 /** \defgroup asic_gd_evts Event codes for the GD controller
58 
59  These are events that the GD-ROM drive generates that can be hooked.
60  @{
61 */
62 #define ASIC_EVT_GD_COMMAND 0x0100 /**< \brief GD-Rom Command Status */
63 #define ASIC_EVT_GD_DMA 0x000e /**< \brief GD-Rom DMA complete */
64 #define ASIC_EVT_GD_DMA_OVERRUN 0x020d /**< \brief GD-Rom DMA overrun */
65 #define ASIC_EVT_GD_DMA_ILLADDR 0x020c /**< \brief GD-Rom DMA illegal address */
66 /** @} */
67 
68 /** \defgroup asic_maple_evts Event codes for the Maple controller
69 
70  These are events that Maple generates that can be hooked.
71  @{
72 */
73 #define ASIC_EVT_MAPLE_DMA 0x000c /**< \brief Maple DMA complete */
74 #define ASIC_EVT_MAPLE_ERROR 0x000d /**< \brief Maple error (?) */
75 /** @} */
76 
77 /** \defgroup asic_spu_evts Event codes for the SPU
78 
79  These are events that the SPU (AICA) generates that can be hooked.
80  @{
81 */
82 #define ASIC_EVT_SPU_DMA 0x000f /**< \brief SPU (G2 channel 0) DMA complete */
83 #define ASIC_EVT_SPU_IRQ 0x0101 /**< \brief SPU interrupt */
84 /** @} */
85 
86 /** \defgroup asic_g2dma_evts Event codes for G2 bus DMA
87 
88  These are events that G2 bus DMA generates that can be hooked.
89  @{
90 */
91 #define ASIC_EVT_G2_DMA0 0x000f /**< \brief G2 DMA channel 0 complete */
92 #define ASIC_EVT_G2_DMA1 0x0010 /**< \brief G2 DMA channel 1 complete */
93 #define ASIC_EVT_G2_DMA2 0x0011 /**< \brief G2 DMA channel 2 complete */
94 #define ASIC_EVT_G2_DMA3 0x0012 /**< \brief G2 DMA channel 3 complete */
95 /** @} */
96 
97 /** \defgroup asic_ext_evts Event codes for the external port
98 
99  These are events that external devices generate that can be hooked.
100  @{
101 */
102 #define ASIC_EVT_EXP_8BIT 0x0102 /**< \brief Modem / Lan Adapter */
103 #define ASIC_EVT_EXP_PCI 0x0103 /**< \brief BBA IRQ */
104 /** @}
105  @} */
106 
107 /** \defgroup asic_regs ASIC registers
108 
109  These are the locations in memory where the ASIC registers sit.
110  @{
111 */
112 #define ASIC_IRQD_A (*(vuint32*)0xa05f6910) /**< \brief IRQD first register */
113 #define ASIC_IRQD_B (*(vuint32*)0xa05f6914) /**< \brief IRQD second register */
114 #define ASIC_IRQD_C (*(vuint32*)0xa05f6918) /**< \brief IRQD third register */
115 #define ASIC_IRQB_A (*(vuint32*)0xa05f6920) /**< \brief IRQB first register */
116 #define ASIC_IRQB_B (*(vuint32*)0xa05f6924) /**< \brief IRQB second register */
117 #define ASIC_IRQB_C (*(vuint32*)0xa05f6928) /**< \brief IRQB third register */
118 #define ASIC_IRQ9_A (*(vuint32*)0xa05f6930) /**< \brief IRQ9 first register */
119 #define ASIC_IRQ9_B (*(vuint32*)0xa05f6934) /**< \brief IRQ9 second register */
120 #define ASIC_IRQ9_C (*(vuint32*)0xa05f6938) /**< \brief IRQ9 third register */
122 #define ASIC_ACK_A (*(vuint32*)0xa05f6900) /**< \brief IRQD ACK register */
123 #define ASIC_ACK_B (*(vuint32*)0xa05f6904) /**< \brief IRQB ACK register */
124 #define ASIC_ACK_C (*(vuint32*)0xa05f6908) /**< \brief IRQ9 ACK register */
125 /** @} */
126 
127 /** \defgroup asic_irq_lv ASIC IRQ levels
128 
129  You can pick one at hook time, or don't choose anything and the default will
130  be used instead.
131  @{
132 */
133 #define ASIC_IRQ9 1 /**< \brief IRQ level 9 */
134 #define ASIC_IRQB 2 /**< \brief IRQ level B (11) */
135 #define ASIC_IRQD 3 /**< \brief IRQ level D (13) */
136 #define ASIC_IRQ_DEFAULT 0 /**< \brief Pick an IRQ level for me! */
137 /** @} */
138 
139 /** \brief ASIC event handler type.
140 
141  Any event handlers registered must be of this type. These will be run in an
142  interrupt context, so don't try anything funny.
143 
144  \param code The ASIC event code that generated this event.
145  \see asic_events
146 */
147 typedef void (*asic_evt_handler)(uint32 code);
148 
149 /** \brief Set or remove an ASIC handler.
150 
151  This function will register an event handler for a given event code, or if
152  the handler is NULL, unregister any that is currently registered.
153 
154  \param code The ASIC event code to hook (see \ref asic_events).
155  \param handler The function to call when the event happens.
156  \retval 0 On success.
157  \retval -1 If an invalid code is specified.
158 */
159 int asic_evt_set_handler(uint32 code, asic_evt_handler handler);
160 
161 /** \brief Disable all ASIC events.
162 
163  This function will disable hooks for every event that has been hooked. In
164  order to reinstate them, you must individually re-enable them. Not a very
165  good idea to be doing this normally.
166 */
167 void asic_evt_disable_all();
168 
169 /** \brief Disable one ASIC event.
170 
171  This function will disable the hook for a specified code that was registered
172  at the given IRQ level. Generally, you will never have to do this yourself
173  unless you're adding in some new functionality.
174 
175  \param code The ASIC event code to unhook (see
176  \ref asic_events).
177  \param irqlevel The IRQ level it was hooked on (see
178  \ref asic_irq_lv).
179 */
180 void asic_evt_disable(uint32 code, int irqlevel);
181 
182 /** \brief Enable an ASIC event.
183 
184  This function will enable the hook for a specified code and register it at
185  the given IRQ level. You should only register each event at a max of one
186  IRQ level (this will not check that for you), and this does not actually set
187  the hook function for the event, you must do that separately with
188  asic_evt_set_handler(). Generally, unless you're adding in new
189  functionality, you'll never have to do this.
190 
191  \param code The ASIC event code to hook (see \ref asic_events).
192  \param irqlevel The IRQ level to hook on (see \ref asic_irq_lv).
193  */
194 void asic_evt_enable(uint32 code, int irqlevel);
195 
196 /** \brief Init ASIC events. */
197 void asic_init();
198 
199 /** \brief Shutdown ASIC events, disabling all hooks. */
200 void asic_shutdown();
201 
202 __END_DECLS
203 
204 #endif /* __DC_ASIC_H */
Common integer types.
void asic_evt_disable_all()
Disable all ASIC events.
int asic_evt_set_handler(uint32 code, asic_evt_handler handler)
Set or remove an ASIC handler.
void asic_shutdown()
Shutdown ASIC events, disabling all hooks.
void asic_evt_enable(uint32 code, int irqlevel)
Enable an ASIC event.
void asic_evt_disable(uint32 code, int irqlevel)
Disable one ASIC event.
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28
void asic_init()
Init ASIC events.
void(* asic_evt_handler)(uint32 code)
ASIC event handler type.
Definition: asic.h:146