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