Setting up repository
[linux-libre-firmware.git] / ath9k_htc / sboot / magpie_1_1 / sboot / inc / Magpie_api.h
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted (subject to the limitations in the
7  * disclaimer below) provided that the following conditions are met:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *  * 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
15  *    distribution.
16  *
17  *  * Neither the name of Qualcomm Atheros nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22  * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 /*
36  * @File: Magpie_api.h
37  * 
38  * @Abstract: Magpie FW api
39  * 
40  * @Notes:
41  */
42
43 #ifndef _MAGPIE_API_H
44 #define _MAGPIE_API_H
45
46 #define MAGPIE_FW_BUILD
47
48 #include "cmnos_api.h"
49 #ifdef MAGPIE_FW_BUILD
50 #include "vbuf_api.h"
51 #include "vdesc_api.h"
52 #include "usbfifo_api.h"
53 //#include "allocram_api.h"
54 #endif
55
56 #include "hif_api.h"
57 #include "htc_api.h"
58 #include "wmi_svc_api.h"
59 #include "buf_pool_api.h"
60 #include "dma_engine_api.h"
61 #include "dma_lib.h"
62 #if SYSTEM_MODULE_SFLASH 
63 #include "sflash_api.h"
64 #endif
65
66 #define A_INDIR(sym)   _A_MAGPIE_INDIRECTION_TABLE->sym
67
68 #if SYSTEM_MODULE_DBG
69 /* debug Support */
70 #define DBG_MODULE_INSTALL()            cmnos_dbg_module_install(&_A_MAGPIE_INDIRECTION_TABLE->dbg)
71 #define A_DBG_INIT()                    A_INDIR(dbg._dbg_init())
72 #define A_DBG_TASK()                    A_INDIR(dbg._dbg_task())
73 #else
74 #define A_DBG_INIT()
75 #define A_DBG_TASK()
76 #endif
77
78 /* Serial Flash support */
79 #define SFLASH_MODULE_INSTALL()                 cmnos_sflash_module_install(&_A_MAGPIE_INDIRECTION_TABLE->sflash)
80 #define A_SFLASH_INIT()                         A_INDIR(sflash._sflash_init())
81 #define A_SFLASH_ERASE(erase_type, addr)        A_INDIR(sflash._sflash_erase(erase_type, addr))
82 #define A_SFLASH_PROG(addr, len, buf)           A_INDIR(sflash._sflash_program(addr, len, buf))
83 #define A_SFLASH_READ(fast, addr, len, buf)     A_INDIR(sflash._sflash_read(fast, addr, len, buf))
84 #define A_SFLASH_RDSR()                         A_INDIR(sflash._sflash_rdsr())
85
86
87 /* DMA Engine Interface */
88 #define DMA_ENGINE_MODULE_INSTALL()                 dma_engine_module_install(&_A_MAGPIE_INDIRECTION_TABLE->dma_engine);
89 #define DMA_Engine_init()                           A_INDIR(dma_engine._init())
90 #define DMA_Engine_config_rx_queue(q, nDesc, size)  A_INDIR(dma_engine._config_rx_queue(q, nDesc, size))
91 #define DMA_Engine_xmit_buf(q, buf)                 A_INDIR(dma_engine._xmit_buf(q, buf))
92 #define DMA_Engine_flush_xmit(q)                    A_INDIR(dma_engine._flush_xmit(q))
93 #define DMA_Engine_reap_recv_buf(q)                 A_INDIR(dma_engine._reap_recv_buf(q))
94 #define DMA_Engine_return_recv_buf(q,buf)           A_INDIR(dma_engine._return_recv_buf(q, buf))
95 #define DMA_Engine_reap_xmited_buf(q)               A_INDIR(dma_engine._reap_xmited_buf(q))
96 #define DMA_Engine_swap_data(desc)                  A_INDIR(dma_engine._swap_data(desc))
97 #define DMA_Engine_init_rx_queue(q)                 A_INDIR(dma_engine._init_rx_queue(q))
98 #define DMA_Engine_init_tx_queue(q)                 A_INDIR(dma_engine._init_tx_queue(q))
99 #define DMA_Engine_has_compl_packets(q)             A_INDIR(dma_engine._has_compl_packets(q))
100 #define DMA_Engine_desc_dump(q)                     A_INDIR(dma_engine._desc_dump(q))
101 #define DMA_Engine_get_packet(q)                    A_INDIR(dma_engine._get_packet(q))
102 #define DMA_Engine_reclaim_packet(q,desc)           A_INDIR(dma_engine._reclaim_packet(q,desc))
103 #define DMA_Engine_put_packet(q,desc)               A_INDIR(dma_engine._put_packet(q,desc))
104
105 /*DMA Library support for GMAC & PCI(E)*/
106 #define DMA_LIB_MODULE_INSTALL()                    dma_lib_module_install(&_A_MAGPIE_INDIRECTION_TABLE->dma_lib)
107 #define dma_lib_tx_init(eng_no, if_type)            A_INDIR(dma_lib.tx_init(eng_no, if_type))
108 #define dma_lib_rx_init(eng_no, if_type)            A_INDIR(dma_lib.rx_init(eng_no, if_type))
109 #define dma_lib_rx_config(eng_no, desc, gran)       A_INDIR(dma_lib.rx_config(eng_no, desc, gran))
110 #define dma_lib_tx_start(eng_no)                    A_INDIR(dma_lib.tx_start(eng_no)) 
111 #define dma_lib_rx_start(eng_no)                    A_INDIR(dma_lib.rx_start(eng_no)) 
112 #define dma_lib_intr_status(if_type)                A_INDIR(dma_lib.intr_status(if_type))
113 #define dma_lib_hard_xmit(eng_no, buf)              A_INDIR(dma_lib.hard_xmit(eng_no, buf))
114 #define dma_lib_flush_xmit(eng_no)                  A_INDIR(dma_lib.flush_xmit(eng_no))
115 #define dma_lib_xmit_done(eng_no)                   A_INDIR(dma_lib.xmit_done(eng_no))
116 #define dma_lib_reap_xmitted(eng_no)                A_INDIR(dma_lib.reap_xmitted(eng_no))
117 #define dma_lib_reap_recv(eng_no)                   A_INDIR(dma_lib.reap_recv(eng_no))
118 #define dma_lib_return_recv(eng_no, buf)            A_INDIR(dma_lib.return_recv(eng_no, buf))
119 #define dma_lib_recv_pkt(eng_no)                    A_INDIR(dma_lib.recv_pkt(eng_no))
120
121 /* HIF support */
122 #define HIF_MODULE_INSTALL()                        generic_hif_module_install(&_A_MAGPIE_INDIRECTION_TABLE->hif)
123 #define HIF_init(pConfig)                           A_INDIR(hif._init(pConfig))
124 #define HIF_shutdown(h)                             A_INDIR(hif._shutdown(h))
125 #define HIF_register_callback(h, pConfig)           A_INDIR(hif._register_callback(h, pConfig))
126 #define HIF_start(h)                                A_INDIR(hif._start(h))  
127 #define HIF_config_pipe(h, pipe, desc_list)         A_INDIR(hif._config_pipe(h, pipe, desc_list)) 
128 #define HIF_send_buffer(h, pipe, buf)               A_INDIR(hif._send_buffer(h, pipe, buf)) 
129 #define HIF_return_recv_buf(h, pipe, buf)           A_INDIR(hif._return_recv_buf(h, pipe, buf)) 
130 #define HIF_isr_handler(h)                          A_INDIR(hif._isr_handler(h)) 
131 #define HIF_is_pipe_supported(h, pipe)              A_INDIR(hif._is_pipe_supported(h, pipe))
132 #define HIF_get_max_msg_len(h, pipe)                A_INDIR(hif._get_max_msg_len(h, pipe))
133 #define HIF_get_reserved_headroom(h)                A_INDIR(hif._get_reserved_headroom(h))
134 #define HIF_get_default_pipe(h,u,d)                 A_INDIR(hif._get_default_pipe(h,u,d))
135
136 /* VBUF APIs */
137 #ifdef MAGPIE_FW_BUILD
138 #define VBUF_MODULE_INSTALL()                       vbuf_module_install(&_A_MAGPIE_INDIRECTION_TABLE->vbuf)
139 #define VBUF_init(nBuf)                             A_INDIR(vbuf._init(nBuf))
140 #define VBUF_alloc_vbuf()                           A_INDIR(vbuf._alloc_vbuf())
141 #define VBUF_free_vbuf(buf)                         A_INDIR(vbuf._free_vbuf(buf))
142 #endif
143
144 /* VDESC APIs */
145 #ifdef MAGPIE_FW_BUILD
146 #define VDESC_MODULE_INSTALL()                      vdesc_module_install(&_A_MAGPIE_INDIRECTION_TABLE->vdesc)
147 #define VDESC_init(nDesc)                           A_INDIR(vdesc._init(nDesc))
148 #define VDESC_alloc_vdesc()                         A_INDIR(vdesc._alloc_vdesc())
149 #define VDESC_get_hw_desc(desc)                     A_INDIR(vdesc._get_hw_desc(desc))
150 #define VDESC_swap_vdesc(dst, src)                  A_INDIR(vdesc._swap_vdesc(dst, src))
151 #endif
152
153 #define HTC_MODULE_INSTALL()                        htc_module_install(&_A_MAGPIE_INDIRECTION_TABLE->htc)
154 #define HTC_init(SetupComplete, pConfig)            A_INDIR(htc._HTC_Init(SetupComplete, pConfig))
155 #define HTC_Shutdown(h)                             A_INDIR(htc._HTC_Shutdown(h))
156 #define HTC_RegisterService(h, s)                   A_INDIR(htc._HTC_RegisterService(h, s))
157 #define HTC_Ready(h)                                A_INDIR(htc._HTC_Ready(h))
158 #define HTC_SendMsg(h, endpt, buf)                  A_INDIR(htc._HTC_SendMsg(h, endpt, buf))
159 #define HTC_ReturnBuffers(h, endpt, buf)            A_INDIR(htc._HTC_ReturnBuffers(h, endpt, buf))
160 #define HTC_ReturnBuffersList(h, endpt, hd)         A_INDIR(htc._HTC_ReturnBuffersList(h, endpt, hd))
161 #define HTC_GetReservedHeadroom(h)                  A_INDIR(htc._HTC_GetReservedHeadroom(h))
162
163 #define HTC_NotifyTargetInserted(h)
164 #define HTC_NotifyTargetDetached(h)                   
165
166 /* WMI SVC module */
167 #define WMI_SERVICE_MODULE_INSTALL()                WMI_service_module_install(&_A_MAGPIE_INDIRECTION_TABLE->wmi_svc_api)
168 #define WMI_Init(pCfg)                              A_INDIR(wmi_svc_api._WMI_Init(pCfg))
169 #define WMI_RegisterDispatchTable(h,pT)             A_INDIR(wmi_svc_api._WMI_RegisterDispatchTable(h, pT))
170 #define WMI_AllocEvent(h,ec,len)                    A_INDIR(wmi_svc_api._WMI_AllocEvent(h, ec, len))
171 #define WMI_SendEvent(h,ev,id,seq,len)              A_INDIR(wmi_svc_api._WMI_SendEvent(h, ev, id, seq, len))
172 #define WMI_GetPendingEventsCount()                 A_INDIR(wmi_svc_api._WMI_GetPendingEventsCount())
173 #define WMI_GetControlEp()                          A_INDIR(wmi_svc_api._WMI_GetControlEp())
174 #define WMI_SendCompleteHandler(ep, buf)            A_INDIR(wmi_svc_api._WMI_SendCompleteHandler(ep, buf))
175 #define WMI_Shutdown(h)                             A_INDIR(wmi_svc_api._WMI_Shutdown(h))
176
177 /* USB FIFO module */
178 #define USBFIFO_MODULE_INSTALL()                    usbfifo_module_install(&_A_MAGPIE_INDIRECTION_TABLE->usbfifo_api)
179 #define USBFIFO_init(pConfig)                       A_INDIR(usbfifo_api._init(pConfig))
180 #define USBFIFO_enable_event_isr()                  A_INDIR(usbfifo_api._enable_event_isr())
181
182 /* BUF pool module */
183 #define BUF_POOL_MODULE_INSTALL()                       buf_pool_module_install(&_A_MAGPIE_INDIRECTION_TABLE->buf_pool)
184 #define BUF_Pool_init(h)                                A_INDIR(buf_pool._init(h))
185 #define BUF_Pool_shutdown(h)                            A_INDIR(buf_pool._shutdown(h))
186 #define BUF_Pool_create_pool(h, id, nItems, nSize)      A_INDIR(buf_pool._create_pool(h, id, nItems, nSize))
187 #define BUF_Pool_alloc_buf(h, id, reserve)              A_INDIR(buf_pool._alloc_buf(h, id, reserve))
188 #define BUF_Pool_alloc_buf_align(h, id, reserve,align)  A_INDIR(buf_pool._alloc_buf_align(h, id, reserve,align))
189 #define BUF_Pool_free_buf(h, id, buf)                   A_INDIR(buf_pool._free_buf(h, id, buf))
190
191 /*
192  * This defines the layout of the indirection table, which
193  * is used to access exported APIs of various modules.  The
194  * layout is shared across ROM and RAM code.  RAM code may
195  * call into ROM and ROM code may call into RAM.  Because
196  * of the latter, existing offsets must not change for the
197  * lifetime of a revision of ROM; but new members may be
198  * added at the end.
199  */
200 typedef struct _A_magpie_indirection_table {
201     _A_cmnos_indirection_table_t        cmnos;
202
203 //#if SYSTEM_MODULE_DBG
204     struct dbg_api                      dbg;        // move to firmware not in cmnos
205 //#endif
206     struct hif_api                      hif;
207     struct htc_apis                     htc;
208     WMI_SVC_APIS                        wmi_svc_api;     
209     struct usbfifo_api                  usbfifo_api;
210     struct buf_pool_api                 buf_pool;
211 #ifdef MAGPIE_FW_BUILD    
212     struct vbuf_api                     vbuf;
213     struct vdesc_api                    vdesc;
214     struct allocram_api                 allocram;
215 #endif        
216     struct dma_engine_api               dma_engine;
217     struct dma_lib_api                  dma_lib;
218
219 // structure to be added after this....
220     struct sflash_api                   sflash;
221 } _A_magpie_indirection_table_t;
222
223 extern _A_magpie_indirection_table_t _indir_tbl;
224 #define _A_MAGPIE_INDIRECTION_TABLE_SIZE sizeof(_A_magpie_indirection_table_t)
225 #if defined(__mips__)
226 #define _A_MAGPIE_INDIRECTION_TABLE ((_A_magpie_indirection_table_t *)0x700)
227 #else
228 #define _A_MAGPIE_INDIRECTION_TABLE (&_indir_tbl)
229 #endif
230
231 #endif