Setting up repository
[linux-libre-firmware.git] / ath9k_htc / sboot / magpie_1_1 / sboot / inc / athos_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 #ifndef __ATHOS_API_H__
36 #define __ATHOS_API_H__
37
38 /*
39  * This file contains wrappers to OS operating system functions
40  * that are available in the Athos version of the operating system.
41  *
42  * Target software must always use these wrappers to access OS
43  * services -- it may not access any OS services directly.
44  *
45  * These wrappers are intended to provide OS-independence for applications.
46  * Using this header file, an application should be able to compile and
47  * fully link without any other OS header files, source files, or
48  * binary files.
49  */
50
51 #include <osapi.h>
52 #include "dt_defs.h"
53 #include "cmnos_api.h"
54 //#include "HIF_api.h"
55 //#include "vbuf_api.h"
56 //#include "vdesc_api.h"
57 //#include "htc_api.h"
58 #include "Magpie_api.h"
59
60 /* ROM Patch API */
61
62
63 /* HTC API */
64
65
66 /* WMI Adaptive API - required for WMI SVCs as they refer some of them*/
67
68
69 /* WLAN WMI API - required for WMI SVCs  and others...*/
70
71 #if 0
72 #define A_INDIR(sym)   _A_OS_INDIRECTION_TABLE->sym
73
74 /* HIF support */
75 #define HIF_MODULE_INSTALL() hif_module_install(&_A_OS_INDIRECTION_TABLE->hif)
76 #define HIF_init(pConfig)                 A_INDIR(hif._init(pConfig))
77 #define HIF_start()                       A_INDIR(hif._start())  
78 #define HIF_config_pipe(pipe, desc_list)  A_INDIR(hif._config_pipe(pipe, desc_list)) 
79 #define HIF_send_buffer(pipe, buf)        A_INDIR(hif._send_buffer(pipe, buf)) 
80 #define HIF_return_recv_buf(pipe, buf)    A_INDIR(hif._return_recv_buf(pipe, buf)) 
81 #define HIF_isr_handler()                 A_INDIR(hif._isr_handler()) 
82 #define HIF_is_pipe_supported(pipe)       A_INDIR(hif._is_pipe_supported(pipe))
83
84 /* VBUF APIs */
85 #define VBUF_MODULE_INSTALL() vbuf_module_install(&_A_OS_INDIRECTION_TABLE->vbuf)
86 #define VBUF_init(dataAddr, nBuf)        A_INDIR(vbuf._init(dataAddr, nBuf))
87 #define VBUF_alloc_vbuf()                A_INDIR(vbuf._alloc_vbuf())
88 #define VBUF_free_vbuf(buf)              A_INDIR(vbuf._free_vbuf(buf))
89
90 /* VDESC APIs */
91 #define VDESC_MODULE_INSTALL() vdesc_module_install(&_A_OS_INDIRECTION_TABLE->vdesc)
92 #define VDESC_init(dataAddr, nTxDesc, nRxDesc)        A_INDIR(vdesc._init(dataAddr, nTxDesc, nRxDesc))
93 #define VDESC_alloc_vdesc(type)                       A_INDIR(vdesc._alloc_vdesc(type))
94 #define VDESC_get_hw_desc(type, desc)                 A_INDIR(vdesc._get_hw_desc(type, desc))
95 //#define VDESC_free_vdesc(buf)                         A_INDIR(vdesc._free_vdesc(buf))
96
97 #define HTC_MODULE_INSTALL()                          htc_module_install(&_A_OS_INDIRECTION_TABLE->htc)
98 //#define HTC_init(dataAddr, SetupComplete, RecvBufferSize)        A_INDIR(htc._HTC_Init(dataAddr, SetupComplete, RecvBufferSize))
99 #define HTC_init(dataAddr, SetupComplete, pConfig)        A_INDIR(htc._HTC_Init(dataAddr, SetupComplete, pConfig))
100 #define HTC_RegisterService(s)                        A_INDIR(htc._HTC_RegisterService(s))
101 #define HTC_Ready()                                   A_INDIR(htc._HTC_Ready())
102 #define HTC_SendMsg(endpt, buf)                       A_INDIR(htc._HTC_SendMsg(endpt, buf))
103 #define HTC_ReturnBuffers(endpt, buf)                 A_INDIR(htc._HTC_ReturnBuffers(endpt, buf))
104
105 #if 0
106 /* WMI SVC module */
107 #define WMI_SERVICE_MODULE_INSTALL()    WMI_service_module_install(&_A_OS_INDIRECTION_TABLE->wmi_svc_api)
108 #define WMI_Init(dataAddr, pCfg)        A_INDIR(wmi_svc_api._WMI_Init(dataAddr, pCfg))
109 #define WMI_RegisterDispatchTable(pT)   A_INDIR(wmi_svc_api._WMI_RegisterDispatchTable(pT))
110 #define WMI_AllocEvent(ec,len)          A_INDIR(wmi_svc_api._WMI_AllocEvent(ec, len))
111 #define WMI_SendEvent(ev,id,seq,len)    A_INDIR(wmi_svc_api._WMI_SendEvent(ev, id, seq, len))
112 #define WMI_GetPendingEventsCount()     A_INDIR(wmi_svc_api._WMI_GetPendingEventsCount())
113 #define WMI_GetControlEp()              A_INDIR(wmi_svc_api._WMI_GetControlEp())
114 #define WMI_SendCompleteHandler(ep, buf) A_INDIR(wmi_svc_api._WMI_SendCompleteHandler(ep, buf))
115 #endif
116
117 /*
118  * This defines the layout of the indirection table, which
119  * is used to access exported APIs of various modules.  The
120  * layout is shared across ROM and RAM code.  RAM code may
121  * call into ROM and ROM code may call into RAM.  Because
122  * of the latter, existing offsets must not change for the
123  * lifetime of a revision of ROM; but new members may be
124  * added at the end.
125  */
126 typedef struct _A_athos_indirection_table {
127     _A_cmnos_indirection_table_t        cmnos;
128     
129     /* TBD: to be added */
130     struct hif_api                      hif;
131     struct vbuf_api                     vbuf;
132     struct vdesc_api                    vdesc;
133     struct htc_apis                     htc;
134     //WMI_SVC_APIS                        wmi_svc_api;    
135 } _A_athos_indirection_table_t;
136
137 #if 1
138 extern _A_athos_indirection_table_t _indir_tbl;
139 #define _A_OS_INDIRECTION_TABLE_SIZE sizeof(_A_athos_indirection_table_t)
140 #define _A_OS_INDIRECTION_TABLE (&_indir_tbl)
141 #endif
142 #endif
143
144 extern unsigned int _data_start_in_rom;
145 extern unsigned int _data_start;
146 extern unsigned int _data_end;
147 extern unsigned int _bss_start;
148 extern unsigned int _bss_end;
149 extern unsigned int _stack_sentry;
150 extern unsigned int __stack;
151 extern unsigned int _fw_image_end;
152
153 #if defined(__XTENSA__)
154 #define START_DATA      _data_start
155 #define END_DATA        _data_end
156 #define START_BSS       _bss_start
157 #define END_BSS         _bss_end
158
159 #define STACK_START _stack_sentry
160 #define STACK_END    __stack
161 #endif
162
163
164 struct _A_os_linkage_check {
165     int version;
166     int table;
167 };
168
169
170 /* 
171  * A_INIT() handles any initialization needed by the OS abstraction,
172  * and it clears the application's BSS, if necessary.  (Application BSS
173  * is not cleared if the application is linked into a single image that
174  * includes AthOS.)
175  *
176  * A_INIT() must be called first thing in the application (from app_start)
177  * in order to guarantee that BSS has been cleared properly.
178  */
179 static INLINE int
180 A_INIT(void)
181 {
182     struct _A_os_linkage_check link_check;
183     unsigned int *clrptr;
184     
185     if (&START_BSS != _A_MAGPIE_INDIRECTION_TABLE->cmnos.start_bss) {
186         /* Clear BSS */
187         for (clrptr = &START_BSS; clrptr < &END_BSS; clrptr++) {
188             *clrptr = 0;
189         }
190     }
191
192     {
193         /* Copy writable data from flash to RAM.  */
194         unsigned int *srcptr, *destptr;
195
196         /*
197          * The _data_start symbol points to the start of data IN FLASH.
198          * It is defined by flash.ld at application link time.  If flash.ld
199          * is not used, it is defined (on the link line) as 0.
200          */
201         static int *data_start_addr = &_data_start;
202
203         if (data_start_addr != 0) {
204             for (srcptr = &_data_start, destptr = &START_DATA;
205                  destptr < &END_DATA;
206                  srcptr++, destptr++)
207             {
208                 *destptr = *srcptr;
209             }
210         }
211     }
212
213 #define OS_LINKAGE_VERSION 4
214     link_check.version = OS_LINKAGE_VERSION;
215     link_check.table = _A_MAGPIE_INDIRECTION_TABLE_SIZE;
216
217     return A_CMN(hal_linkage_check(sizeof(link_check), &link_check));
218 }
219
220
221 #endif /* __ATHOS_API_H__ */
222