1 #ifndef __CMNOS_API_H__
2 #define __CMNOS_API_H__
5 * This file contains wrappers to OS operating system functions
6 * that are available in all versions of the operating system.
8 * Target software must always use these wrappers to access OS
9 * services -- it may not access any OS services directly.
12 #include "xtensa/config/core.h"
13 #include "xtensa/hal.h"
14 #include "xtensa/xtruntime.h"
18 #include "printf_api.h"
23 #include "string_api.h"
24 #include "timer_api.h"
26 #include "allocram_api.h"
27 #include "tasklet_api.h"
28 #include "clock_api.h"
31 #include "eeprom_api.h"
34 #if defined(PROJECT_K2)
35 #if SYSTEM_MODULE_SFLASH
36 #include "sflash_api.h"
40 #define AR6K_ROM_START 0x004e0000
41 #define AR6K_ROM_ADDR(byte_offset) (AR6K_ROM_START+(byte_offset))
42 #define TARG_ROM_ADDRS(byte_offset) AR6K_ROM_ADDR(byte_offset)
44 #define IML_SIGNAL_UNUSED0_ADDR TARG_ROM_ADDRS(0) /* Cannot be used -- aligned */
45 #define IML_SIGNAL_ASSERT_ADDR TARG_ROM_ADDRS(1) /* Signal an assertion failure */
46 #define IML_SIGNAL_PRINTF_ADDR TARG_ROM_ADDRS(2) /* Signal a printf request */
47 #define IML_SIGNAL_UNUSED4_ADDR TARG_ROM_ADDRS(4) /* Cannot be used -- aligned */
48 #define IML_SIGNAL_UNUSED8_ADDR TARG_ROM_ADDRS(8) /* Cannot be used -- aligned */
49 #define IML_SIGNAL_UNUSEDC_ADDR TARG_ROM_ADDRS(0xc) /* Cannot be used -- aligned */
50 #define IML_SIGNAL_MASK 0xfffe000f
51 #define IML_LINENUM_SHIFT 4
53 #define NOW() xthal_get_ccount()
55 #if defined(__XTENSA__)
56 #define _A_BARRIER asm volatile("memw")
61 #define A_ASSERT( __bool ) \
63 if (0 == (__bool)) { \
64 (void)*((volatile int *)(IML_SIGNAL_ASSERT_ADDR+(__LINE__<<4)));\
70 #define A_IML_IS_ASSERT(vaddr) \
71 (((vaddr) & IML_SIGNAL_MASK) == (IML_SIGNAL_ASSERT_ADDR & IML_SIGNAL_MASK))
74 #define PRINT_FAILURE_STATE() \
76 uint32_t epc1, epc2, epc3, epc4; \
78 asm volatile("rsr %0,%1" : "=r" (epc1) : "n" (EPC_1)); \
79 asm volatile("rsr %0,%1" : "=r" (epc2) : "n" (EPC_2)); \
80 asm volatile("rsr %0,%1" : "=r" (epc3) : "n" (EPC_3)); \
81 asm volatile("rsr %0,%1" : "=r" (epc4) : "n" (EPC_4)); \
83 A_PRINTF("\tepc1=0x%x, epc2=0x%x, epc3=0x%x, epc4=0x%x\n", \
84 epc1, epc2, epc3, epc4); \
85 A_PRINTF("0x%08x, 0x%08x, 0x%08x, \n\r", \
86 DEBUG_SYSTEM_STATE, WATCH_DOG_RESET_COUNTER, \
87 WATCH_DOG_MAGIC_PATTERN); \
89 ////////////////////////////////////////////////////////////////////////////////////
92 //#define A_CMN(sym) _A_OS_INDIRECTION_TABLE->cmnos.sym
93 #define A_CMN(sym) _A_MAGPIE_INDIRECTION_TABLE->cmnos.sym
97 #define A_MEMSET(addr, value, size) \
98 A_CMN(mem._memset((char *)(addr), (int)(value), (int)(size)))
100 #define A_MEMZERO(addr, size) \
101 A_CMN(mem._memset((char *)(addr), (int)0, (int)(size)))
103 #define A_MEMCPY(dst, src, size) \
104 A_CMN(mem._memcpy((char *)(dst), (char *)(src), (int)(size)))
106 #define A_MEMMOVE(dst, src, size) \
107 A_CMN(mem._memmove((char *)(dst), (char *)(src), (int)(size)))
109 #define A_MEMCMP(p1, p2, nbytes) \
110 A_CMN(mem._memcmp)((void *)(p1), (void *)(p2), (int)(nbytes))
113 #define A_MEMSET(addr, value, size)
115 #define A_MEMZERO(addr, size)
117 #define A_MEMCPY(dst, src, size)
119 #define A_MEMMOVE(dst, src, size)
121 #define A_MEMCMP(p1, p2, nbytes)
126 /* String interfaces */
127 #define A_STRCPY(dst, src) A_CMN(string._strcpy((dst), (src)))
128 #define A_STRNCPY(dst, src, n) A_CMN(string._strncpy((dst), (src), (n)))
129 #define A_STRLEN(str) A_CMN(string._strlen(str))
130 #define A_STRCMP(str1, str2) A_CMN(string._strcmp((str1), (str2)))
131 #define A_STRNCMP(str1, str2, n) A_CMN(string._strncmp((str1), (str2), (n)))
134 #if SYSTEM_MODULE_PRINT
136 #define A_PRINTF_INIT() A_CMN(printf._printf_init())
137 #define A_PRINTF A_CMN(printf._printf)
139 #define A_PRINTF_INIT()
141 #endif /* SYSTEM_MODULE_PRINT */
143 #if SYSTEM_MODULE_UART
144 /* Serial port support */
145 #define A_UART_INIT() A_CMN(uart._uart_init())
147 #define A_UART_HWINIT(freq, baud) \
148 A_CMN(uart._uart_hwinit((freq), (baud)))
150 #define A_UART_ENABLED() (HOST_INTEREST->hi_uart_enable)
152 #define A_PUTS(str) A_CMN(uart._uart_str_out(str))
154 #define A_PUTC(ch) A_CMN(uart._uart_char_put(ch))
155 #define A_GETC(pCh) A_CMN(uart._uart_char_get(pCh))
157 #define A_UART_TASK() A_CMN(uart._uart_task())
158 #define A_UART_CONFIG(x) A_CMN(uart._uart_config(x))
162 #define A_UART_INIT()
164 #define A_UART_HWINIT(freq, baud)
166 #define A_UART_ENABLED()
173 #define A_UART_TASK()
174 #define A_UART_CONFIG(x)
178 #if SYSTEM_MODULE_MISC
180 #define A_RESET() A_CMN(misc._system_reset())
181 #define A_RESET_MAC() A_CMN(misc._mac_reset())
183 /* Assertion failure */
184 #define A_ASSFAIL(regdump) A_CMN(misc._assfail((regdump)))
186 /* Report a failure to the Host */
187 #define A_REPORT_FAILURE(data, len) \
188 A_CMN(misc._report_failure_to_host((data), (len)))
190 /* UNALIGNED references are used for ASSERTs */
191 #define A_MISALIGNED_LOAD_HANDLER(dump) A_CMN(misc._misaligned_load_handler(dump))
193 /* reture the host interface type */
194 #define A_IS_HOST_PRESENT() A_CMN(misc._is_host_present())
195 #define A_KBHIT(delay) A_CMN(misc._kbhit(delay))
196 #define A_GET_ROM_VER() A_CMN(misc._rom_version_get())
200 #define A_RESET_MAC()
202 /* Assertion failure */
203 #define A_ASSFAIL(regdump)
205 #define A_MISALIGNED_LOAD_HANDLER(dump)
207 /* Report a failure to the Host */
208 #define A_REPORT_FAILURE(data, len)
210 #define A_IS_HOST_PRESENT()
211 #define A_KBHIT(delay)
212 #define A_GET_ROM_VER()
215 #if SYSTEM_MODULE_USB
217 #define A_USB_INIT() A_CMN(usb._usb_init())
218 #define A_USB_ROM_TASK() A_CMN(usb._usb_rom_task())
219 #define A_USB_FW_TASK() A_CMN(usb._usb_fw_task())
220 #define A_USB_INIT_PHY() A_CMN(usb._usb_init_phy())
222 #define A_USB_EP0_SETUP() A_CMN(usb._usb_ep0_setup())
223 #define A_USB_EP0_TX_DATA() A_CMN(usb._usb_ep0_tx_data())
224 #define A_USB_EP0_RX_DATA() A_CMN(usb._usb_ep0_rx_data())
226 #define A_USB_GET_CONFIG() A_CMN(usb._usb_get_configuration())
227 #define A_USB_SET_CONFIG() A_CMN(usb._usb_set_configuration())
229 #define A_USB_GET_INTERFACE() A_CMN(usb._usb_get_interface())
230 #define A_USB_SET_INTERFACE() A_CMN(usb._usb_set_interface())
232 #define A_USB_STANDARD_CMD() A_CMN(usb._usb_standard_cmd())
233 #define A_USB_VENDOR_CMD() A_CMN(usb._usb_vendor_cmd())
235 #define A_USB_POWER_OFF() A_CMN(usb._usb_power_off())
236 #define A_USB_RESET_FIFO() A_CMN(usb._usb_reset_fifo())
237 #define A_USB_GEN_WDT() A_CMN(usb._usb_gen_wdt())
238 #define A_USB_JUMP_BOOT() A_CMN(usb._usb_jump_boot())
240 #define A_USB_GET_DESCRIPTOR() A_CMN(usb._usb_get_descriptor())
241 #define A_USB_SET_ADDRESS() A_CMN(usb._usb_set_address())
242 #define A_USB_SET_FEATURE() A_CMN(usb._usb_set_feature())
243 #define A_USB_CLEAR_FEATURE() A_CMN(usb._usb_clr_feature())
245 #define A_USB_GET_STATUS() A_CMN(usb._usb_get_status())
246 #define A_USB_SETUP_DESC() A_CMN(usb._usb_setup_desc())
247 #define A_USB_STATUS_IN() A_CMN(usb._usb_status_in())
248 #define A_USB_REG_OUT() A_CMN(usb._usb_reg_out())
250 #define A_USB_EP0_TX() A_CMN(usb._usb_ep0_tx())
251 #define A_USB_EP0_RX() A_CMN(usb._usb_ep0_rx())
252 #define A_USB_CLK_INIT() A_CMN(usb._usb_clk_init())
257 #define A_USB_INIT_PHY()
259 #define A_USB_EP0_SETUP()
260 #define A_USB_EP0_TX()
261 #define A_USB_EP0_RX()
263 #define A_USB_GET_CONFIG()
264 #define A_USB_SET_CONFIG()
266 #define A_USB_GET_INTERFACE()
267 #define A_USB_SET_INTERFACE()
269 #define A_USB_STANDARD_CMD()
270 #define A_USB_VENDOR_CMD()
272 #define A_USB_POWER_OFF()
273 #define A_USB_RESET_FIFO()
274 #define A_USB_GEN_WDT()
275 #define A_USB_JUMP_BOOT()
277 #define A_USB_GET_DESCRIPTOR()
278 #define A_USB_SET_ADDRESS()
279 #define A_USB_SET_FEATURE()
280 #define A_USB_CLEAR_FEATURE()
282 #define A_USB_GET_STATUS()
283 #define A_USB_SETUP_DESC()
286 #define A_USB_STATUS_IN()
287 #define A_USB_REG_OUT()
289 #define A_USB_EP0_TX()
290 #define A_USB_EP0_RX()
292 #define A_USB_CLK_INIT()
295 #if SYSTEM_MODULE_INTR
296 /* Low-level interrupt support intended for use by OS modules */
297 #define A_INTR_GET_INTRENABLE() A_CMN(intr._get_intrenable())
298 #define A_INTR_SET_INTRENABLE(val) A_CMN(intr._set_intrenable(val))
299 #define A_INTR_GET_INTRPENDING() A_CMN(intr._get_intrpending())
300 #define A_INTR_UNBLOCK_ALL_INTRLVL() A_CMN(intr._unblock_all_intrlvl())
302 /* Interrupt support */
303 #define A_INTR_INIT() A_CMN(intr._intr_init())
305 #define A_INTR_DISABLE(pOld) \
307 *(pOld) = A_CMN(intr._intr_disable()); \
310 #define A_INTR_RESTORE(old) A_CMN(intr._intr_restore((old)))
312 #define A_INVOKE_ISR(inum) A_CMN(intr._intr_invoke_isr(inum))
314 #define A_INTR_MASK(inum) A_CMN(intr._intr_mask_inum(inum))
315 #define A_INTR_UNMASK(inum) A_CMN(intr._intr_unmask_inum(inum))
317 #define A_ATTACH_ISR(inum, isr, arg) A_CMN(intr._intr_attach_isr(inum, isr, arg))
319 #define A_INTR_INIT()
320 #define A_INTR_DISABLE(pOld)
321 #define A_INTR_RESTORE(old)
323 #define A_INTR_GET_INTRENABLE()
324 #define A_INTR_SET_INTRENABLE(val)
325 #define A_INTR_GET_INTRPENDING()
326 #define A_INTR_UNBLOCK_ALL_INTRLVL()
327 #define A_INVOKE_ISR(inum)
328 #define A_INTR_MASK(inum)
329 #define A_INTR_UNMASK(inum)
330 #define A_ATTACH_ISR(inum, isr, arg)
334 /* Tasklet Support */
335 #define A_TASKLET_INIT() A_CMN(tasklet._tasklet_init())
336 #define A_TASKLET_INIT_TASK(f, arg, t) A_CMN(tasklet._tasklet_init_task(f, arg, t))
337 #define A_TASKLET_DISABLE(t) A_CMN(tasklet._tasklet_disable(t))
338 #define A_TASKLET_SCHEDULE(t) A_CMN(tasklet._tasklet_schedule(t))
339 #define A_TASKLET_RUN() A_CMN(tasklet._tasklet_run())
342 /* RAM Allocation Support */
343 #if defined(__mips__)
344 #define alloc_arena_start _end
346 #if defined(__XTENSA__)
347 #define alloc_arena_start _end
350 #if SYSTEM_MODULE_CLOCK
352 #define A_CLOCK_INIT(refclk_guess) A_CMN(clock._clock_init(refclk_guess))
353 #define A_CLOCK_TICK() A_CMN(clock._clock_tick())
354 #define A_CLOCK_GET_TICK() A_CMN(clock._clock_get_tick())
357 * Get the number of millisecond ticks since the system was started.
358 * Note that this only approximates 1Ms. It's actually 32 ticks of
361 * Returns a A_UINT32 value.
363 #define A_MILLISECONDS() A_CMN(clock._milliseconds())
366 * Get the frequency of the reference clock, expressed as
367 * an A_refclk_speed_t.
369 #define A_REFCLK_SPEED_GET() A_CMN(clock._refclk_speed_get())
372 #define A_DELAY_USECS(us) A_CMN(clock._delay_us(us))
374 #define A_UART_FREQUENCY() A_CMN(clock._uart_frequency())
376 #define A_CLOCKREGS_INIT() A_CMN(clock._clockregs_init())
378 /* which_band is either A_BAND_24GHZ or A_BAND_5GHZ */
379 #define A_WLAN_BAND_SET(which_band) \
380 A_CMN(clock._wlan_band_set(which_band))
382 /* Called whenever the system clock changes speed */
383 #define A_SYSCLK_CHANGE(mhz) A_CMN(clock._sysclk_change(mhz))
385 #define A_SYSCLK_GET() A_CMN(clock._sysclk_get())
389 #define A_CLOCK_INIT(refclk_guess)
390 #define A_CLOCK_TICK()
391 #define A_CLOCK_GET_TICK()
392 #define A_MILLISECONDS()
393 #define A_REFCLK_SPEED_GET()
394 #define A_DELAY_USECS(us)
395 #define A_UART_FREQUENCY()
396 #define A_CLOCKREGS_INIT()
397 #define A_WLAN_BAND_SET(which_band)
398 #define A_SYSCLK_CHANGE(mhz)
399 #define A_SYSCLK_GET()
404 #define A_INIT_TIMER(pTimer, pFunction, pArg) \
405 A_CMN(timer._timer_setfn((pTimer), (pFunction), (pArg)))
407 /* Set a (possibly periodic) timer for "period" Milliseconds. */
408 #define A_TIMEOUT_MS(pTimer, period) \
409 A_CMN(timer._timer_arm((pTimer), (period)))
411 #define A_UNTIMEOUT(pTimer) \
412 A_CMN(timer._timer_disarm(pTimer))
414 #define A_TIMER_RUN() \
415 A_CMN(timer._timer_run())
417 #define A_PCI_BOOT_INIT() \
418 A_CMN(pci.pci_boot_init())
420 #define A_GMAC_BOOT_INIT() \
421 A_CMN(gmac.gmac_boot_init())
423 #if SYSTEM_MODULE_ALLOCRAM
424 /* Default size of ALLOCRAM area */
425 #define ARENA_SZ_DEFAULT 12000
427 #define A_ALLOCRAM_INIT(arena_start, arena_size) \
429 extern unsigned int alloc_arena_start; \
432 astart = (arena_start) ? (void *)(arena_start) : &alloc_arena_start; \
433 asize = (arena_size) ? (arena_size) : (ARENA_SZ_DEFAULT); \
434 A_CMN(allocram.cmnos_allocram_init((astart), (asize))); \
437 #define A_ALLOCRAM(nbytes) A_CMN(allocram.cmnos_allocram(0, (nbytes)))
439 #define A_ALLOCRAM_DEBUG() A_CMN(allocram.cmnos_allocram_debug())
442 #define A_ALLOCRAM_INIT(arena_start, arena_size)
443 #define A_ALLOCRAM(nbytes)
444 #define A_ALLOCRAM_DEBUG()
447 #if SYSTEM_MODULE_ROM_PATCH
449 #define A_ROMP_INIT() A_CMN(romp._romp_init())
450 #define A_ROMP_DOWNLOAD(x) A_CMN(romp._romp_download(x))
451 #define A_ROMP_DECODE(addr) A_CMN(romp._romp_decode(addr))
452 #define A_ROMP_INSTALL() A_CMN(romp._romp_install())
454 #define A_ROMP_INIT()
455 #define A_ROMP_DOWNLOAD(x)
456 #define A_ROMP_DECODE(addr)
457 #define A_ROMP_INSTALL()
460 #if SYSTEM_MODULE_WDT
462 #define A_WDT_INIT() A_CMN(wdt_timer._wdt_init())
463 #define A_WDT_ENABLE() A_CMN(wdt_timer._wdt_enable())
464 #define A_WDT_DISABLE() A_CMN(wdt_timer._wdt_disable())
465 #define A_WDT_SET(t) A_CMN(wdt_timer._wdt_set(t))
466 #define A_WDT_TASK() A_CMN(wdt_timer._wdt_task())
467 #define A_WDT_LASTBOOT() A_CMN(wdt_timer._wdt_last_boot())
468 #define A_WDT_RESET() A_CMN(wdt_timer._wdt_reset())
472 #define A_WDT_ENABLE()
473 #define A_WDT_DISABLE()
476 #define A_WDT_LASTBOOT()
477 #define A_WDT_RESET()
481 #if SYSTEM_MODULE_EEPROM
482 #define A_EEP_INIT() A_CMN(eep._eep_init())
483 #define A_EEP_READ(off, len, buf) A_CMN(eep._eep_read(off, len, buf))
484 #define A_EEP_WRITE(off, len, buf) A_CMN(eep._eep_write(off, len, buf))
485 #define A_EEP_IS_EXIST() A_CMN(eep._eep_is_exist())
488 #define A_EEP_READ(off, len, buf)
489 #define A_EEP_WRITE(off, len, buf)
490 #define A_EEP_IS_EXIST()
495 struct _A_os_linkage_check; /* OS-dependent */
497 typedef struct _A_cmnos_indirection_table {
498 int (* hal_linkage_check)(int sz, struct _A_os_linkage_check *);
499 unsigned int *start_bss;
500 void (* app_start)(void);
502 #if SYSTEM_MODULE_MEM
506 #if SYSTEM_MODULE_MISC
507 struct misc_api misc;
510 #if SYSTEM_MODULE_PRINT
511 struct printf_api printf;
514 #if SYSTEM_MODULE_UART
515 struct uart_api uart;
518 #if SYSTEM_MODULE_DBG
519 #if !MOVE_DBG_TO_RAM // move to firmware not in cmnos
523 #if SYSTEM_MODULE_PCI
527 #if SYSTEM_MODULE_GMAC
528 struct gmac_api gmac;
531 #if SYSTEM_MODULE_USB
535 #if SYSTEM_MODULE_CLOCK
536 struct clock_api clock;
539 #if SYSTEM_MODULE_TIMER
540 struct timer_api timer;
543 #if SYSTEM_MODULE_INTR
544 struct intr_api intr;
547 #if SYSTEM_MODULE_ALLOCRAM
548 struct allocram_api allocram;
551 #if SYSTEM_MODULE_ROM_PATCH
552 struct romp_api romp;
555 #if SYSTEM_MODULE_WDT
556 struct wdt_api wdt_timer;
559 #if SYSTEM_MODULE_EEPROM
563 struct string_api string;
564 struct tasklet_api tasklet;
566 } _A_cmnos_indirection_table_t;
568 /* Module installation for cmnos modules */
570 #if SYSTEM_MODULE_MEM
571 extern void cmnos_mem_module_install(struct mem_api *);
574 #if SYSTEM_MODULE_MISC
575 extern void cmnos_misc_module_install(struct misc_api *);
578 #if SYSTEM_MODULE_PRINT
579 extern void cmnos_printf_module_install(struct printf_api *);
582 #if SYSTEM_MODULE_UART
583 extern void cmnos_uart_module_install(struct uart_api *);
586 #if SYSTEM_MODULE_DBG
587 extern void cmnos_dbg_module_install(struct dbg_api *);
590 #if SYSTEM_MODULE_USB
591 extern void cmnos_usb_module_install(struct usb_api *);
594 #if SYSTEM_MODULE_INTR
595 extern void cmnos_intr_module_install(struct intr_api *);
598 #if SYSTEM_MODULE_CLOCK
599 extern void cmnos_clock_module_install(struct clock_api *);
602 #if SYSTEM_MODULE_TIMER
603 extern void cmnos_timer_module_install(struct timer_api *);
606 #if SYSTEM_MODULE_ALLOCRAM
607 extern void cmnos_allocram_module_install(struct allocram_api *);
610 #if SYSTEM_MODULE_ROM_PATCH
611 extern void cmnos_romp_module_install(struct romp_api *);
614 #if SYSTEM_MODULE_WDT
615 extern void cmnos_wdt_module_install(struct wdt_api *);
618 #if SYSTEM_MODULE_EEPROM
619 extern void cmnos_eep_module_install(struct eep_api *);
622 #if SYSTEM_MODULE_PCI
623 extern void cmnos_pci_module_install(struct pci_api *);
626 extern void cmnos_tasklet_module_install(struct tasklet_api *);
628 extern void cmnos_string_module_install(struct string_api *tbl);
630 #endif /* __CMNOS_API_H__ */