xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/pltfm_ops_windows.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 - 2020 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #ifndef _HAL_PLTFM_WINDOWS_H_
16 #define _HAL_PLTFM_WINDOWS_H_
17 #include <ntdef.h>
18 #include <ndis.h>
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include <ntstrsafe.h>
22 #include "StatusCode.h"
23 #include "EndianFree.h"
24 #include "LinkList.h"		//for N6C_pltfmdef - _RT_TIMER_HANDLE
25 #include "N6C_pltfmdef.h" //defined u8 :: XXX_pltfmdef.h must before pltfm_def.h
26 #include "pltfm_def.h"
27 
28 #if defined(CONFIG_USB_HCI)
29 #include <wdftypes.h> //for WDFUSBPIPE
30 #include "core_util.h"
31 #include "core_usb.h"
32 #include "pltfm_usb.h"
33 #endif
34 
35 #include "phl_config.h"
36 #ifdef CONFIG_PHL_WPP
37 //#include "hal_g6\phy\rf\halrf_wpp.h"
38 #include "hal_g6\mac\halmac_wpp.h"
39 #include "hal_g6\phy\bb\halbb_wpp.h"
40 #include "phl_wpp.h"
41 #include <rtwlanwpp.h>
42 #endif
43 #include "phl_types.h"
44 #include "phl_util.h"
45 #include "phl_def.h"
46 //#include "phl_types.h"
47 //#include "PlatformDef.h"
48 
49 #define WriteLE4Byte(_ptr, _val)	WriteEF4Byte(_ptr,_val)
50 #define WriteLE2Byte(_ptr, _val)	WriteEF2Byte(_ptr,_val)
51 #define WriteLE1Byte(_ptr, _val)	WriteEF1Byte(_ptr,_val)
52 
53 #define WriteBE4Byte(_ptr, _val)	WriteEF4Byte(_ptr,H2N1BYTE(_val))
54 #define WriteBE2Byte(_ptr, _val)	WriteEF2Byte(_ptr,H2N2BYTE(_val))
55 #define WriteBE1Byte(_ptr, _val)	WriteEF1Byte(_ptr,H2N4BYTE(_val))
56 
_os_strpbrk(const char * cs,const char * ct)57 static inline char *_os_strpbrk(const char *cs, const char *ct)
58 {
59 	const char *sc1, *sc2;
60 
61 	for (sc1 = cs; *sc1 != '\0'; ++sc1) {
62 		for (sc2 = ct; *sc2 != '\0'; ++sc2) {
63 			if (*sc1 == *sc2)
64 				return (char *)sc1;
65 		}
66 	}
67 	return NULL;
68 }
69 
_os_strsep(char ** s,const char * ct)70 static inline char *_os_strsep(char **s, const char *ct)
71 {
72 	char *sbegin = *s;
73 	char *end;
74 
75 	if (sbegin == NULL)
76 		return NULL;
77 
78 	end = _os_strpbrk((const char *)sbegin, ct);
79 	if (end)
80 		*end++ = '\0';
81 	*s = end;
82 	return sbegin;
83 }
84 
85 
_os_strcmp(const char * s1,const char * s2)86 static inline int _os_strcmp(const char *s1, const char *s2)
87 {
88 	return strcmp(s1, s2);
89 }
_os_strncmp(const char * s1,const char * s2,size_t n)90 static inline int _os_strncmp(const char *s1, const char *s2, size_t n)
91 {
92 	return strncmp(s1, s2, n);
93 }
_os_strcpy(char * dest,const char * src)94 static __inline char *_os_strcpy(char *dest, const char *src)
95 {
96 	return strcpy(dest, src);
97 }
_os_strncpy(char * dest,const char * src,size_t n)98 static inline char *_os_strncpy(char *dest, const char *src, size_t n)
99 {
100 	return strncpy(dest, src, n);
101 }
_os_strchr(const char * s,int c)102 static __inline char *_os_strchr(const char *s, int c)
103 {
104 	return strchr(s, c);
105 }
106 
107 #define _os_snprintf(s, sz, fmt, ...) _snprintf(s, sz, fmt, ##__VA_ARGS__)
108 #define _os_vsnprintf(str, size, fmt, args) RtlStringCbVPrintfA(str, size, fmt, args)
109 
110 #define _os_strncat strncat
111 
_os_strlen(u8 * buf)112 static __inline u32 _os_strlen(u8 *buf)
113 {
114 	return (u32)strlen((const char *)buf);
115 }
116 
117 #define _os_sscanf(buf, fmt, ...) sscanf_s(buf, fmt, ##__VA_ARGS__)
118 
119 /* delay */
_os_delay_ms(void * drv_priv,u32 ms)120 static __inline void _os_delay_ms(void * drv_priv, u32 ms)
121 {
122 	PlatformForceStallExecution(1000 * ms);
123 }
_os_delay_us(void * h,u32 us)124 static __inline void _os_delay_us(void *h, u32 us)
125 {
126 	PlatformForceStallExecution(us);
127 }
_os_sleep_ms(void * h,u32 ms)128 static __inline void _os_sleep_ms(void *h, u32 ms)
129 {
130 	PlatformForceStallExecution(1000 * ms);
131 }
_os_sleep_us(void * h,u32 us)132 static __inline void _os_sleep_us(void *h, u32 us)
133 {
134 	PlatformForceStallExecution(us);
135 }
136 
_os_get_cur_time_us(void)137 static inline u32 _os_get_cur_time_us(void)
138 {
139 	u64 ret;
140 	ret = PlatformGetCurrentTime();
141 	return (u32)ret;
142 }
143 
_os_get_cur_time_ms(void)144 static inline u32 _os_get_cur_time_ms(void)
145 {
146 	u64 ret;
147 	ret = PlatformGetCurrentTime() / 1000;
148 	return (u32)ret;
149 }
150 
_os_modular64(u64 x,u64 y)151 static inline u64 _os_modular64(u64 x, u64 y)
152 {
153 	return x % y;
154 }
_os_division64(u64 x,u64 y)155 static inline u64 _os_division64(u64 x, u64 y)
156 {
157 	return x / y;
158 }
159 
_os_minus64(u64 x,u64 y)160 static inline u64 _os_minus64(u64 x, u64 y)
161 
162 {
163 	return x - y;
164 }
165 
_os_add64(u64 x,u64 y)166 static inline u64 _os_add64(u64 x, u64 y)
167 
168 {
169 	return x + y;
170 }
171 
_os_div_round_up(u32 x,u32 y)172 static inline u32 _os_div_round_up(u32 x, u32 y)
173 {
174 	return (x + y - 1) / y;
175 }
176 
_os_pkt_buf_unmap_rx(void * d,_dma bus_addr_l,_dma bus_addr_h,u32 buf_sz)177 static inline void *_os_pkt_buf_unmap_rx(void *d, _dma bus_addr_l, _dma bus_addr_h, u32 buf_sz)
178 {
179 	return NULL;
180 }
181 
_os_pkt_buf_map_rx(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,void * os_priv)182 static inline void *_os_pkt_buf_map_rx(void *d, _dma *bus_addr_l, _dma *bus_addr_h,
183 					u32 buf_sz, void *os_priv)
184 {
185 	return NULL;
186 }
187 
_os_pkt_buf_alloc_rx(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 cache,void ** os_priv)188 static inline void *_os_pkt_buf_alloc_rx(void *d, _dma *bus_addr_l,
189 			_dma *bus_addr_h, u32 buf_sz, u8 cache, void **os_priv)
190 {
191 	struct _SHARED_MEMORY share_mem;
192 
193 	PlatformZeroMemory(&share_mem, sizeof(share_mem));
194 
195 	if (PlatformAllocateSharedMemory(d, &share_mem, buf_sz) != RT_STATUS_SUCCESS) {
196 		share_mem.VirtualAddress = NULL;
197 		*bus_addr_l = 0;
198 		*bus_addr_h = 0;
199 		*os_priv = NULL;
200 	} else {
201 		PlatformZeroMemory(share_mem.VirtualAddress, buf_sz);
202 #ifdef CONFIG_PCI_HCI
203 		*bus_addr_l = (_dma)share_mem.PhysicalAddressLow;
204 		*bus_addr_h = (_dma)share_mem.PhysicalAddressHigh;
205 #endif
206 #if WIFICX_BASED
207 		*os_priv = share_mem.pltfm_rsvd[0];
208 #endif
209 	}
210 	return (u8 *)share_mem.VirtualAddress;
211 }
_os_pkt_buf_free_rx(void * d,u8 * vir_addr,_dma bus_addr_l,_dma bus_addr_h,u32 buf_sz,u8 cache,void * os_priv)212 static inline void _os_pkt_buf_free_rx(void *d, u8 *vir_addr, _dma bus_addr_l,
213 			_dma bus_addr_h, u32 buf_sz, u8 cache, void *os_priv)
214 {
215 	struct _SHARED_MEMORY share_mem;
216 
217 	if (NULL != vir_addr) {
218 		share_mem.VirtualAddress = (pu1Byte)vir_addr;
219 		share_mem.PhysicalAddressLow = (u4Byte)bus_addr_l;
220 		share_mem.PhysicalAddressHigh = (u4Byte)bus_addr_h;
221 		share_mem.Length = (u4Byte)buf_sz;
222 #if WIFICX_BASED
223 		share_mem.pltfm_rsvd[0] = os_priv;
224 #endif
225 		PlatformFreeSharedMemory(d, &share_mem);
226 	}
227 }
228 
229 /* phl pre-alloc network layer buffer */
_os_alloc_netbuf(void * d,u32 buf_sz,void ** os_priv)230 static inline void * _os_alloc_netbuf(void *d, u32 buf_sz, void **os_priv)
231 {
232 	return NULL; // windows never do this.
233 }
234 
235 /* Free netbuf for error case. (ex. drop rx-reorder packet) */
_os_free_netbuf(void * d,u8 * vir_addr,u32 buf_sz,void * os_priv)236 static inline void _os_free_netbuf(void *d, u8 *vir_addr, u32 buf_sz, void *os_priv)
237 {
238 }
239 
240 #ifdef CONFIG_PCI_HCI
_os_cache_inv(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 direction)241 static inline void _os_cache_inv(void *d, _dma *bus_addr_l, _dma *bus_addr_h,
242 					u32 buf_sz, u8 direction)
243 {
244 }
_os_cache_wback(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 direction)245 static inline void _os_cache_wback(void *d, _dma *bus_addr_l,
246 			_dma *bus_addr_h, u32 buf_sz, u8 direction)
247 {
248 }
249 
_os_dma_pool_create(void * d,char * name,u32 wd_page_sz)250 static inline void *_os_dma_pool_create(void *d, char *name, u32 wd_page_sz)
251 {
252 	return NULL;
253 }
254 
_os_dma_pool_destory(void * d,void * pool)255 static inline void _os_dma_pool_destory(void *d, void *pool)
256 {
257 }
258 
259 /* txbd, rxbd, wd */
_os_shmem_alloc(void * d,void * pool,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 cache,u8 direction,void ** os_rsvd)260 static inline void *_os_shmem_alloc(void *d, void *pool, _dma *bus_addr_l,
261 				    _dma *bus_addr_h, u32 buf_sz,
262 				    u8 cache, u8 direction, void **os_rsvd)
263 {
264 	struct _SHARED_MEMORY share_mem;
265 
266 	PlatformZeroMemory(&share_mem, sizeof(share_mem));
267 
268 	if (PlatformAllocateSharedMemory(d, &share_mem, buf_sz) != RT_STATUS_SUCCESS) {
269 		share_mem.VirtualAddress = NULL;
270 		*bus_addr_l = 0;
271 		*bus_addr_h = 0;
272 	} else {
273 		PlatformZeroMemory(share_mem.VirtualAddress, buf_sz);
274 		*bus_addr_l = (_dma)share_mem.PhysicalAddressLow;
275 		*bus_addr_h = (_dma)share_mem.PhysicalAddressHigh;
276 #if WIFICX_BASED
277 		*os_rsvd = share_mem.pltfm_rsvd[0];
278 #endif
279 	}
280 	return (u8 *)share_mem.VirtualAddress;
281 }
_os_shmem_free(void * d,u8 * vir_addr,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 cache,u8 direction,void * os_rsvd)282 static inline void _os_shmem_free(void *d, u8 *vir_addr, _dma *bus_addr_l,
283 				  _dma *bus_addr_h, u32 buf_sz,
284 				  u8 cache, u8 direction, void *os_rsvd)
285 {
286 	struct _SHARED_MEMORY share_mem;
287 
288 	PlatformZeroMemory(&share_mem, sizeof(share_mem));
289 
290 	if (NULL != vir_addr) {
291 		share_mem.VirtualAddress = (pu1Byte)vir_addr;
292 		share_mem.PhysicalAddressLow = (u4Byte)*bus_addr_l;
293 		share_mem.PhysicalAddressHigh = (u4Byte)*bus_addr_h;
294 		share_mem.Length = (u4Byte)buf_sz;
295 #if WIFICX_BASED
296 		share_mem.pltfm_rsvd[0] = os_rsvd;
297 #endif
298 		PlatformFreeSharedMemory(d, &share_mem);
299 	}
300 }
301 #endif /*CONFIG_PCI_HCI*/
302 
303 #define _os_mem_alloc(h, buf_sz) _os_mem_alloc_with_tag(h, GenTag(__func__), buf_sz)
304 /* memory */
_os_mem_alloc_with_tag(void * h,u32 tag,u32 buf_sz)305 static __inline void *_os_mem_alloc_with_tag(void *h, u32 tag, u32 buf_sz)
306 {
307 	PVOID ptr = NULL;
308 	if (PlatformAllocateMemoryWithTag(tag, &ptr, buf_sz) != RT_STATUS_SUCCESS)
309 		return NULL;
310 
311 	PlatformZeroMemory(ptr, buf_sz);
312 	return ptr;
313 }
_os_mem_free(void * h,void * buf,u32 buf_sz)314 static __inline void _os_mem_free(void *h, void *buf, u32 buf_sz)
315 {
316 	if(buf)
317 		PlatformFreeMemory(buf, buf_sz);
318 }
319 
320 #define _os_kmem_alloc(h, buf_sz) _os_kmem_alloc_with_tag(h, GenTag(__func__), buf_sz)
321 /*physically contiguous memory if the buffer will be accessed by a DMA device*/
_os_kmem_alloc_with_tag(void * h,u32 tag,u32 buf_sz)322 static __inline void *_os_kmem_alloc_with_tag(void *h, u32 tag, u32 buf_sz)
323 {
324 	PVOID ptr = NULL;
325 	if (PlatformAllocateMemoryWithTag(tag, &ptr, buf_sz) != RT_STATUS_SUCCESS)
326 		return NULL;
327 
328 	PlatformZeroMemory(ptr, buf_sz);
329 	return ptr;
330 }
331 
332 /*physically contiguous memory if the buffer will be accessed by a DMA device*/
_os_kmem_free(void * h,void * buf,u32 buf_sz)333 static __inline void _os_kmem_free(void *h, void *buf, u32 buf_sz)
334 {
335 	if(buf)
336 		PlatformFreeMemory(buf, buf_sz);
337 }
338 /*static __inline void *_os_aligment_mem_alloc(void *h, u32 buf_sz)
339 {
340 	PALIGNED_SHARED_MEMORY  pAlignedSharedMemory=NULL;
341 
342 	PlatformAllocateAlignedSharedMemory()
343 }*/
344 
_os_mem_set(void * h,void * buf,s8 value,u32 buf_sz)345 static __inline void _os_mem_set(void *h, void *buf, s8 value, u32 buf_sz)
346 {
347 	PlatformFillMemory(buf, buf_sz, value);
348 }
_os_mem_cpy(void * h,void * dest,void * src,u32 buf_sz)349 static __inline void _os_mem_cpy(void *h, void *dest, void *src, u32 buf_sz)
350 {
351 	PlatformMoveMemory(dest, src, buf_sz);
352 }
_os_mem_cmp(void * h,void * ptr1,void * ptr2,u32 buf_sz)353 static __inline int _os_mem_cmp(void *h, void *ptr1, void *ptr2, u32 buf_sz)
354 {
355 
356 	return PlatformCompareMemory(ptr1, ptr2, buf_sz);
357 }
358 
359 /* timer */
_os_init_timer(void * drv_priv,_os_timer * timer,void (* call_back_func)(void * context),void * context,const char * sz_id)360 static __inline void _os_init_timer(void *drv_priv, _os_timer *timer,
361 		void (*call_back_func)(void *context), void *context,
362 		const char *sz_id)
363 {
364 	PlatformInitializeTimer(drv_priv, timer, (RT_TIMER_CALL_BACK)call_back_func, context, sz_id);
365 }
_os_set_timer(void * drv_priv,_os_timer * timer,u32 ms_delay)366 static __inline void _os_set_timer(void *drv_priv, _os_timer *timer, u32 ms_delay)
367 {
368 	PlatformSetTimer(drv_priv, timer, ms_delay);
369 }
_os_cancel_timer(void * drv_priv,_os_timer * timer)370 static __inline void _os_cancel_timer(void *drv_priv, _os_timer *timer)
371 {
372 	PlatformCancelTimer(drv_priv, timer);
373 }
_os_cancel_timer_async(void * drv_priv,_os_timer * timer)374 static inline void _os_cancel_timer_async(void *drv_priv, _os_timer *timer)
375 {
376 	PlatformCancelTimer(drv_priv, timer);
377 }
_os_release_timer(void * drv_priv,_os_timer * timer)378 static __inline void _os_release_timer(void *drv_priv, _os_timer *timer)
379 {
380 	PlatformReleaseTimer(drv_priv, timer);
381 }
382 
383 
384 /* mutex */
_os_mutex_init(void * h,_os_mutex * mutex)385 static __inline void _os_mutex_init(void *h, _os_mutex *mutex)
386 {
387 	PlatformInitializeMutex(mutex);
388 }
389 
_os_mutex_deinit(void * h,_os_mutex * mutex)390 static __inline void _os_mutex_deinit(void *h, _os_mutex *mutex)
391 {
392 	PlatformFreeMutex(mutex);
393 }
394 
_os_mutex_lock(void * h,_os_mutex * mutex)395 static __inline void _os_mutex_lock(void *h, _os_mutex *mutex)
396 {
397 	PlatformAcquireMutex(mutex);
398 }
399 
_os_mutex_unlock(void * h,_os_mutex * mutex)400 static __inline void _os_mutex_unlock(void *h, _os_mutex *mutex)
401 {
402 	PlatformReleaseMutex(mutex);
403 }
404 
405 
406 /* Semaphore */
_os_sema_init(void * h,_os_sema * sema,int int_cnt)407 static inline void _os_sema_init(void *h, _os_sema *sema, int int_cnt)
408 {
409 	PlatformInitializeSemaphore(sema, int_cnt);
410 }
411 
_os_sema_free(void * h,_os_sema * sema)412 static inline void _os_sema_free(void *h, _os_sema *sema)
413 {
414 	PlatformFreeSemaphore(sema);
415 }
416 
_os_sema_up(void * h,_os_sema * sema)417 static inline void _os_sema_up(void *h, _os_sema *sema)
418 {
419 
420 	PlatformReleaseSemaphore(sema);
421 }
422 
_os_sema_down(void * h,_os_sema * sema)423 static inline u8 _os_sema_down(void *h, _os_sema *sema)
424 {
425 	if(PlatformAcquireSemaphore(sema)==RT_STATUS_SUCCESS)
426 		return 0; //// RTW_PHL_STATUS_SUCCESS
427 	else
428 		return 1;
429 
430 }
431 
432 /* event */
_os_event_init(void * h,_os_event * event)433 static __inline void _os_event_init(void *h, _os_event *event)
434 {
435 	PlatformInitializeEvent(event);
436 }
437 
_os_event_free(void * h,_os_event * event)438 static __inline void _os_event_free(void *h, _os_event *event)
439 {
440 	PlatformFreeEvent(event);
441 }
442 
_os_event_reset(void * h,_os_event * event)443 static __inline void _os_event_reset(void *h, _os_event *event)
444 {
445 	PlatformResetEvent(event);
446 }
447 
_os_event_set(void * h,_os_event * event)448 static __inline void _os_event_set(void *h, _os_event *event)
449 {
450 	PlatformSetEvent(event);
451 }
452 
453 /*
454  * m_sec
455  * 	== 0 : wait for completion
456  * 	>  0 : wait for timeout or completion
457  * return value
458  * 	0:timeout
459  * 	otherwise:success
460  */
_os_event_wait(void * h,_os_event * event,u32 m_sec)461 static __inline int _os_event_wait(void *h, _os_event *event, u32 m_sec)
462 {
463 	return PlatformWaitEvent(event, m_sec);
464 }
465 
466 
467 
468 
469 /* spinlock */
_os_spinlock_init(void * d,_os_lock * plock)470 static __inline void _os_spinlock_init(void *d, _os_lock *plock)
471 {
472 	PLATFORM_INIT_RT_SPINLOCK(*plock);
473 }
_os_spinlock_free(void * d,_os_lock * plock)474 static __inline void _os_spinlock_free(void *d, _os_lock *plock)
475 {
476 	PLATFORM_FREE_RT_SPINLOCK(*plock);
477 }
478 
_os_spinlock(void * d,_os_lock * plock,enum lock_type type,_os_spinlockfg * flags)479 static inline void _os_spinlock(void *d, _os_lock *plock,
480 					enum lock_type type, _os_spinlockfg *flags)
481 {
482 	PLATFORM_ACQUIRE_RT_SPINLOCK(*plock);
483 }
_os_spinunlock(void * d,_os_lock * plock,enum lock_type type,_os_spinlockfg * flags)484 static inline void _os_spinunlock(void *d, _os_lock *plock,
485 					enum lock_type type, _os_spinlockfg *flags)
486 {
487 	PLATFORM_RELEASE_RT_SPINLOCK(*plock);
488 }
489 
490 /* tasklet/thread */
_os_thread_init(void * drv_priv,_os_thread * thread,int (* call_back_func)(void * context),void * context,const char namefmt[])491 static __inline u8 _os_thread_init(	void *drv_priv, _os_thread *thread,
492 					int (*call_back_func)(void * context),
493 					void *context,
494 					const char namefmt[])
495 {
496 	if (PlatformInitializeThread(drv_priv,
497 			thread,
498 			(RT_THREAD_CALL_BACK)call_back_func,
499 			namefmt,
500 			0,
501 			context) == RT_STATUS_SUCCESS) //0: caller will wait for the event indefinitely.
502 		return 0;
503 	else
504 		return 1;
505 }
506 
_os_thread_deinit(void * drv_priv,_os_thread * thread)507 static __inline u8 _os_thread_deinit(void *drv_priv, _os_thread *thread)
508 {
509 	/* Terminate the thread */
510 	PlatformWaitThreadEnd(drv_priv, thread);
511 	PlatformCancelThread(drv_priv, thread);
512 	PlatformReleaseThread(drv_priv, thread);
513 	return 0;
514 }
515 
_os_thread_schedule(void * drv_priv,_os_thread * thread)516 static __inline enum rtw_phl_status _os_thread_schedule(void *drv_priv, _os_thread *thread)
517 {
518 	//PlatformSetEventTrigerThread(drv_priv, thread, PASSIVE_LEVEL, thread->pContext);
519 	PlatformRunThread(drv_priv, thread, PASSIVE_LEVEL);
520 	return RTW_PHL_STATUS_SUCCESS;
521 }
_os_thread_stop(void * drv_priv,_os_thread * thread)522 static inline void _os_thread_stop(void *drv_priv, _os_thread *thread)
523 {
524 	PlatformSetThreadEnd(drv_priv, thread);
525 }
_os_thread_check_stop(void * drv_priv,_os_thread * thread)526 static inline int _os_thread_check_stop(void *drv_priv, _os_thread *thread)
527 {
528 	return PlatformIsThreadEnd(drv_priv, thread);
529 }
530 
_os_thread_wait_stop(void * drv_priv,_os_thread * thread)531 static inline int _os_thread_wait_stop(void *drv_priv, _os_thread *thread)
532 {
533 	return RTW_PHL_STATUS_SUCCESS;
534 }
535 
536 /* Workitem */
_os_workitem_init(void * drv_priv,_os_workitem * workitem,void (* call_back_func)(void * context),void * context)537 static __inline u8 _os_workitem_init(void *drv_priv, _os_workitem *workitem, void (*call_back_func)(void* context), void *context)
538 {
539 	if (PlatformInitializeWorkItem(drv_priv, workitem, (RT_WORKITEM_CALL_BACK)call_back_func,
540 			context, "phl_workitem") == RT_STATUS_SUCCESS)
541 	{
542 		PlatformStartWorkItem(workitem);
543 		return 0; // RTW_PHL_STATUS_SUCCESS
544 	}
545 	else
546 		return 1;
547 }
_os_workitem_deinit(void * drv_priv,_os_workitem * workitem)548 static __inline u8 _os_workitem_deinit(void *drv_priv, _os_workitem *workitem)
549 {
550 	PlatformStopWorkItem(workitem);
551 	PlatformFreeWorkItem(workitem);
552 	return 0;
553 }
_os_workitem_schedule(void * drv_priv,_os_workitem * workitem)554 static __inline u8 _os_workitem_schedule(void *drv_priv, _os_workitem *workitem)
555 {
556 	if(PlatformScheduleWorkItem(workitem) == TRUE)
557 		return 0; // RTW_PHL_STATUS_SUCCESS
558 	else
559 		return 1;
560 }
561 
562 /*
563 static __inline void _os_workitem_run(void *h, hal_thread *thread)
564 {
565 	//??
566 }
567 static __inline void _os_workitem_kill(void *h, hal_thread *thread)
568 {
569 	PlatformStopWorkItem(thread);
570 }
571 static __inline void _os_workitem_pause(void *h, hal_thread *thread)
572 {
573 }
574 static __inline void _os_workitem_resume(void *h, hal_thread *thread)
575 {
576 }
577 */
578 
579 /* tasklet */
580 
phl_notify_thread_callback(void * context)581 static __inline int phl_notify_thread_callback(void *context)
582 {
583 	struct rtw_phl_handler *handler = (struct rtw_phl_handler *)context;
584 	_os_thread *thread = (_os_thread *) &(handler->os_handler.u.tasklet);
585 	do {
586 		if(_os_sema_down(handler->drv_priv, &(thread->sema)) != RTW_PHL_STATUS_SUCCESS )
587 			break;
588 		if(handler->status & RTW_PHL_HANDLER_STATUS_RELEASED)
589 			break;
590 		handler->callback(thread);
591 	} while (true);
592 	return 0;
593 }
594 
_os_tasklet_init(void * drv_priv,_os_tasklet * tasklet,void (* call_back_func)(void * context),void * context)595 static __inline u8 _os_tasklet_init(void *drv_priv, _os_tasklet *tasklet, void (*call_back_func)(void *context), void *context)
596 {
597 	_os_thread *actual_thread = (_os_thread *)tasklet;
598 	struct rtw_phl_handler *handler;
599 
600 	_os_thread_init(drv_priv, actual_thread, phl_notify_thread_callback,
601 			context, "phl_tasklet");
602 	_os_thread_schedule(drv_priv, actual_thread);
603 
604 	handler = (struct rtw_phl_handler *)actual_thread->pContext;
605 	handler->status &= RTW_PHL_HANDLER_STATUS_INITIALIZED;
606 	return 0;
607 }
608 
_os_tasklet_deinit(void * drv_priv,_os_tasklet * tasklet)609 static __inline u8 _os_tasklet_deinit(void *drv_priv, _os_tasklet *tasklet)
610 {
611 	_os_thread *actual_thread = (_os_thread *)tasklet;
612 	struct rtw_phl_handler *handler = (struct rtw_phl_handler *)actual_thread->pContext;
613 	if (handler)
614 		handler->status |= RTW_PHL_HANDLER_STATUS_RELEASED;
615 	_os_sema_up(drv_priv, &(actual_thread->sema));
616 	_os_thread_deinit(drv_priv, actual_thread);
617 	return 0;
618 }
619 
_os_tasklet_schedule(void * drv_priv,_os_tasklet * tasklet)620 static __inline enum rtw_phl_status _os_tasklet_schedule(void *drv_priv, _os_tasklet *tasklet)
621 {
622 	_os_thread *actual_thread = (_os_thread *)tasklet;
623 
624 	_os_sema_up(drv_priv, &(actual_thread->sema));
625 	return RTW_PHL_STATUS_SUCCESS;
626 }
627 
628 
_os_test_and_clear_bit(int nr,unsigned long * addr)629 static _inline int _os_test_and_clear_bit(int nr, unsigned long *addr)
630 {
631 	/*UNDO*/
632 	return 0;
633 }
_os_test_and_set_bit(int nr,unsigned long * addr)634 static _inline int _os_test_and_set_bit(int nr, unsigned long *addr)
635 {
636 	/*UNDO*/
637 	return 1;
638 }
639 
640 
641 /* Atomic integer operations */
_os_atomic_set(void * d,_os_atomic * v,int i)642 static __inline void _os_atomic_set(void *d, _os_atomic *v, int i)
643 {
644 	InterlockedExchange(v, i);
645 }
646 
_os_atomic_read(void * d,_os_atomic * v)647 static __inline int _os_atomic_read(void *d, _os_atomic *v)
648 {
649 	return *v;
650 }
651 
_os_atomic_add(void * d,_os_atomic * v,int i)652 static __inline void _os_atomic_add(void *d, _os_atomic *v, int i)
653 {
654 	InterlockedExchangeAdd(v, i);
655 }
_os_atomic_sub(void * d,_os_atomic * v,int i)656 static __inline void _os_atomic_sub(void *d, _os_atomic *v, int i)
657 {
658 }
659 
_os_atomic_inc(void * d,_os_atomic * v)660 static __inline void _os_atomic_inc(void *d, _os_atomic *v)
661 {
662 	InterlockedIncrement(v);
663 }
664 
_os_atomic_dec(void * d,_os_atomic * v)665 static __inline void _os_atomic_dec(void *d, _os_atomic *v)
666 {
667 	InterlockedDecrement(v);
668 }
669 
_os_atomic_add_return(void * d,_os_atomic * v,int i)670 static __inline int _os_atomic_add_return(void *d, _os_atomic *v, int i)
671 {
672 	return 0;
673 }
674 
_os_atomic_sub_return(void * d,_os_atomic * v,int i)675 static __inline int _os_atomic_sub_return(void *d, _os_atomic *v, int i)
676 {
677 	return 0;
678 }
679 
_os_atomic_inc_return(void * d,_os_atomic * v)680 static __inline int _os_atomic_inc_return(void *d, _os_atomic *v)
681 {
682 	return 0;
683 }
684 
_os_atomic_dec_return(void * d,_os_atomic * v)685 static __inline int _os_atomic_dec_return(void *d, _os_atomic *v)
686 {
687 	return 0;
688 }
689 
690 /* File Operation */
_os_read_file(const char * path,u8 * buf,u32 sz)691 static inline u32 _os_read_file(const char *path, u8 *buf, u32 sz)
692 {
693 	/* OS Dependent API */
694 	return platform_read_file(path, buf, sz);
695 }
696 
697 /*
698 static __inline bool _os_atomic_inc_unless(void *d, _os_atomic *v, int u)
699 {
700 	return 0;
701 }
702 */
703 
704 #ifdef CONFIG_PCI_HCI
_os_read8_pcie(void * drv_priv,u32 addr)705 static __inline u8 _os_read8_pcie(void *drv_priv, u32 addr)
706 {
707 	return PlatformEFIORead1Byte(drv_priv, addr);
708 }
_os_read16_pcie(void * drv_priv,u32 addr)709 static __inline u16 _os_read16_pcie(void *drv_priv, u32 addr)
710 {
711 	return PlatformEFIORead2Byte(drv_priv, addr);
712 }
_os_read32_pcie(void * drv_priv,u32 addr)713 static __inline u32 _os_read32_pcie(void *drv_priv, u32 addr)
714 {
715 	return PlatformEFIORead4Byte(drv_priv, addr);
716 }
717 
_os_write8_pcie(void * drv_priv,u32 addr,u8 val)718 static __inline u32 _os_write8_pcie(void *drv_priv, u32 addr, u8 val)
719 {
720 	PlatformEFIOWrite1Byte(drv_priv, addr, val);
721 	return 0;
722 }
_os_write16_pcie(void * drv_priv,u32 addr,u16 val)723 static __inline u32 _os_write16_pcie(void *drv_priv, u32 addr, u16 val)
724 {
725 	PlatformEFIOWrite2Byte(drv_priv, addr, val);
726 	return 0;
727 }
_os_write32_pcie(void * drv_priv,u32 addr,u32 val)728 static __inline u32 _os_write32_pcie(void *drv_priv, u32 addr, u32 val)
729 {
730 	PlatformEFIOWrite4Byte(drv_priv, addr, val);
731 	return 0;
732 }
733 #endif/*#ifdef CONFIG_PCI_HCI*/
734 
735 #ifdef CONFIG_USB_HCI
736 
_os_usbctrl_vendorreq(void * drv_priv,u8 request,u16 value,u16 index,void * pdata,u16 len,u8 requesttype)737 static __inline u32 _os_usbctrl_vendorreq(void *drv_priv, u8 request, u16 value,
738 			u16 index, void *pdata, u16 len, u8 requesttype)
739 {
740 	// return value ?? RTW_PHL_STATUS or boolean??
741 	return pltfm_usb_ctrl_vendor_request(
742 			drv_priv,
743 			request,
744 			value,
745 			index,
746 			pdata,
747 			len,
748 			requesttype);
749 
750 }
751 
os_usb_tx(void * h,u8 * tx_buf_ptr,u8 bulk_id,u32 len,u8 * pkt_data_buf)752 static inline int os_usb_tx(void *h, u8 *tx_buf_ptr,
753 			u8 bulk_id, u32 len, u8 *pkt_data_buf)
754 {
755 	if(pltfm_usb_out_token_send(h, tx_buf_ptr, pkt_data_buf, len, bulk_id) == TRUE)
756 		return 0; // RTW_PHL_STATUS_SUCCESS
757 	else
758 		return 1;
759 }
760 
os_enable_usb_out_pipes(void * drv_priv)761 static __inline void os_enable_usb_out_pipes(void *drv_priv)
762 {
763 	pltfm_usb_out_pipes_start(drv_priv);
764 }
765 
os_disable_usb_out_pipes(void * drv_priv)766 static __inline void os_disable_usb_out_pipes(void *drv_priv)
767 {
768 	pltfm_usb_out_pipes_stop(drv_priv);
769 }
770 
os_out_token_alloc(void * drv_priv)771 static __inline u8 os_out_token_alloc(void *drv_priv)
772 {
773 	if(core_usb_out_token_init(drv_priv)== TRUE)
774 		return 0; // RTW_PHL_STATUS_SUCCESS
775 	else
776 		return 1;
777 }
778 
os_out_token_free(void * drv_priv)779 static __inline void os_out_token_free(void *drv_priv)
780 {
781 	core_usb_out_token_deinit(drv_priv);
782 }
783 
os_in_token_alloc(void * drv_priv)784 static __inline u8 os_in_token_alloc(void *drv_priv)
785 {
786 	if(core_usb_in_token_init(drv_priv)== TRUE)
787 		return 0; // RTW_PHL_STATUS_SUCCESS
788 	else
789 		return 1;
790 }
791 
os_in_token_free(void * drv_priv)792 static __inline void os_in_token_free(void *drv_priv)
793 {
794 	core_usb_in_token_deinit(drv_priv);
795 }
796 
os_send_usb_in_token(void * drv_priv,void * rxobj,u8 * inbuf,u32 inbuf_len,u8 pipe_idx,u8 minLen)797 static __inline u8 os_send_usb_in_token(void *drv_priv, void *rxobj, u8 *inbuf, u32 inbuf_len, u8 pipe_idx, u8 minLen)
798 {
799 	if(pltfm_usb_in_token_send(drv_priv, rxobj, inbuf, inbuf_len, pipe_idx, minLen) == TRUE)
800 		return 0;// RTW_PHL_STATUS_SUCCESS
801 	else
802 		return 1;
803 }
804 
os_enable_usb_in_pipes(void * drv_priv)805 static __inline void os_enable_usb_in_pipes(void *drv_priv)
806 {
807 	pltfm_usb_in_pipes_start(drv_priv);
808 }
809 
os_disable_usb_in_pipes(void * drv_priv)810 static __inline void os_disable_usb_in_pipes(void *drv_priv)
811 {
812 	pltfm_usb_in_pipes_stop(drv_priv);
813 }
814 
815 #endif /*CONFIG_USB_HCI*/
816 
817 #ifdef CONFIG_SDIO_HCI
_os_sdio_cmd52_r8(void * d,u32 offset)818 static __inline u8 _os_sdio_cmd52_r8(void *d, u32 offset)
819 {
820 	return PlatformEFSdioLocalCmd52Read1Byte(d, offset);
821 }
822 
_os_sdio_cmd53_r8(void * d,u32 offset)823 static __inline u8 _os_sdio_cmd53_r8(void *d, u32 offset)
824 {
825 	return PlatformEFSdioLocalCmd53Read1Byte(d, offset);
826 }
827 
_os_sdio_cmd53_r16(void * d,u32 offset)828 static __inline u16 _os_sdio_cmd53_r16(void *d, u32 offset)
829 {
830 	return PlatformEFSdioLocalCmd53Read2Byte(d, offset);
831 }
832 
_os_sdio_cmd53_r32(void * d,u32 offset)833 static __inline u32 _os_sdio_cmd53_r32(void *d, u32 offset)
834 {
835 	return PlatformEFSdioLocalCmd53Read4Byte(d, offset);
836 }
837 
_os_sdio_cmd53_rn(void * d,u32 offset,u32 size,u8 * data)838 static __inline u8 _os_sdio_cmd53_rn(void *d, u32 offset, u32 size, u8 *data)
839 {
840 	if (!data){
841 		return _FAIL;
842 	}
843 
844 	PlatformEFSdioLocalCmd53ReadNByte(d, offset, size, (pu1Byte)data);
845 
846 	return _SUCCESS;
847 }
848 
_os_sdio_cmd53_r(void * d,u32 offset,u32 size,u8 * data)849 static __inline u8 _os_sdio_cmd53_r(void *d, u32 offset, u32 size, u8 *data)
850 {
851 
852 	PlatformEFSdioLocalCmd53ReadNByte(d, offset, size, data);
853 
854 	return _SUCCESS;
855 }
856 
_os_sdio_cmd52_w8(void * d,u32 offset,u8 val)857 static __inline void _os_sdio_cmd52_w8(void *d, u32 offset, u8 val)
858 {
859 	PlatformEFSdioLocalCmd52Write1Byte(d, offset, val);
860 }
861 
_os_sdio_cmd53_w8(void * d,u32 offset,u8 val)862 static __inline void _os_sdio_cmd53_w8(void *d, u32 offset, u8 val)
863 {
864 	PlatformEFSdioLocalCmd53Write1Byte(d, offset, val);
865 }
866 
_os_sdio_cmd53_w16(void * d,u32 offset,u16 val)867 static __inline void _os_sdio_cmd53_w16(void *d, u32 offset, u16 val)
868 {
869 	PlatformEFSdioLocalCmd53Write2Byte(d, offset, val);
870 }
871 
_os_sdio_cmd53_w32(void * d,u32 offset,u32 val)872 static __inline void _os_sdio_cmd53_w32(void *d, u32 offset, u32 val)
873 {
874 	PlatformEFSdioLocalCmd53Write4Byte(d, offset, val);
875 }
876 
_os_sdio_cmd53_wn(void * d,u32 offset,u32 size,u8 * data)877 static __inline void _os_sdio_cmd53_wn(void *d, u32 offset, u32 size, u8 *data)
878 {
879 	PlatformEFSdioLocalCmd53WriteNByte(d, offset, size, (pu1Byte)data);
880 }
881 
_os_sdio_cmd53_w(void * d,u32 offset,u32 size,u8 * data)882 static __inline void _os_sdio_cmd53_w(void *d, u32 offset, u32 size, u8 *data)
883 {
884 	PlatformEFSdioLocalCmd53WriteNByte(d, offset, size, (pu1Byte)data);
885 }
886 
_os_sdio_f0_read(void * d,u32 addr,void * buf,size_t len)887 static __inline u8 _os_sdio_f0_read(void *d, u32 addr, void *buf, size_t len)
888 {
889 	return 0;
890 }
891 
_os_sdio_read_cia_r8(void * d,u32 addr)892 static __inline u8 _os_sdio_read_cia_r8(void *d, u32 addr)
893 {
894 	return 0;
895 }
896 
897 #endif /*CONFIG_SDIO_HCI*/
898 
899 
900 #endif /*_HAL_PLTFM_WINDOWS_H_*/
901