2 * HND Run Time Environment for standalone MIPS programs.
4 * Copyright (C) 2010, Broadcom Corporation
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
12 * $Id: hndrte.h,v 13.133.2.1.18.1 2011-02-11 18:38:23 Exp $
24 #if defined(_HNDRTE_SIM_)
25 #include <hndrte_sim.h>
27 #include <hndrte_mips.h>
28 #elif defined(__arm__) || defined(__thumb__) || defined(__thumb2__)
29 #include <hndrte_arm.h>
32 #include <bcmstdlib.h>
33 #include <hndrte_trap.h>
35 #define HNDRTE_DEV_NAME_MAX 16
37 /* RTE IOCTL definitions for generic ether devices */
38 #define RTEGHWADDR 0x8901
39 #define RTESHWADDR 0x8902
40 #define RTEGMTU 0x8903
41 #define RTEGSTATS 0x8904
42 #define RTEGALLMULTI 0x8905
43 #define RTESALLMULTI 0x8906
44 #define RTEGPROMISC 0x8907
45 #define RTESPROMISC 0x8908
46 #define RTESMULTILIST 0x8909
48 #define RTEGPERMADDR 0x890B
50 /* Forward declaration */
54 extern si_t
*hndrte_sih
; /* Chip backplane handle */
55 extern osl_t
*hndrte_osh
; /* Chip backplane osl */
56 extern chipcregs_t
*hndrte_ccr
; /* Chipcommon core regs */
57 extern sbconfig_t
*hndrte_ccsbr
; /* Chipcommon core SB config regs */
58 extern struct pktpool pktpool_shared
;
60 typedef struct hndrte_devfuncs hndrte_devfuncs_t
;
62 /* happens to mirror a section of linux's net_device_stats struct */
64 unsigned long rx_packets
; /* total packets received */
65 unsigned long tx_packets
; /* total packets transmitted */
66 unsigned long rx_bytes
; /* total bytes received */
67 unsigned long tx_bytes
; /* total bytes transmitted */
68 unsigned long rx_errors
; /* bad packets received */
69 unsigned long tx_errors
; /* packet transmit problems */
70 unsigned long rx_dropped
; /* no space in linux buffers */
71 unsigned long tx_dropped
; /* no space available in linux */
72 unsigned long multicast
; /* multicast packets received */
77 uint32 totcpusleep_cycles
;
78 uint32 min_cpusleep_cycles
;
79 uint32 max_cpusleep_cycles
;
85 typedef struct hndrte_dev
{
86 char name
[HNDRTE_DEV_NAME_MAX
];
87 hndrte_devfuncs_t
*funcs
;
89 void *softc
; /* Software context */
90 uint32 flags
; /* RTEDEVFLAG_XXXX */
91 struct hndrte_dev
*next
;
92 struct hndrte_dev
*chained
;
96 #define RTEDEVFLAG_HOSTASLEEP 0x000000001 /* host is asleep */
99 typedef struct _pdev
{
112 /* Device entry points */
113 struct hndrte_devfuncs
{
114 void *(*probe
)(hndrte_dev_t
*dev
, void *regs
, uint bus
,
115 uint16 device
, uint coreid
, uint unit
);
116 int (*open
)(hndrte_dev_t
*dev
);
117 int (*close
)(hndrte_dev_t
*dev
);
118 int (*xmit
)(hndrte_dev_t
*src
, hndrte_dev_t
*dev
, struct lbuf
*lb
);
119 int (*recv
)(hndrte_dev_t
*src
, hndrte_dev_t
*dev
, void *pkt
);
120 int (*ioctl
)(hndrte_dev_t
*dev
, uint32 cmd
, void *buffer
, int len
,
121 int *used
, int *needed
, int set
);
122 void (*txflowcontrol
) (hndrte_dev_t
*dev
, bool state
, int prio
);
123 void (*poll
)(hndrte_dev_t
*dev
);
124 int (*xmit_ctl
)(hndrte_dev_t
*src
, hndrte_dev_t
*dev
, struct lbuf
*lb
);
125 int (*xmit2
)(hndrte_dev_t
*src
, hndrte_dev_t
*dev
, struct lbuf
*lb
, int8 ch
);
128 /* Use standard symbols for Armulator build which does not use the hndrte.lds linker script */
129 #if defined(_HNDRTE_SIM_) || defined(EXT_CBALL)
130 #define text_start _start
131 #define text_end etext
132 #define data_start etext
133 #define data_end edata
134 #define bss_start __bss_start
138 extern char text_start
[], text_end
[];
139 extern char data_start
[], data_end
[];
140 extern char bss_start
[], bss_end
[], _end
[];
143 extern int hndrte_add_device(hndrte_dev_t
*dev
, uint16 coreid
, uint16 device
);
144 extern hndrte_dev_t
*hndrte_get_dev(char *name
);
146 /* ISR registration */
147 typedef void (*isr_fun_t
)(void *cbdata
);
149 extern int hndrte_add_isr(uint irq
, uint coreid
, uint unit
,
150 isr_fun_t isr
, void *cbdata
, uint bus
);
152 /* Basic initialization and background */
153 extern void *hndrte_init(void);
154 extern void hndrte_poll(si_t
*sih
);
155 extern void hndrte_idle(si_t
*sih
);
157 /* Other initialization and background funcs */
158 extern void hndrte_isr(void);
159 extern void hndrte_timer_isr(void);
160 extern void hndrte_cpu_init(si_t
*sih
);
161 extern void hndrte_idle_init(si_t
*sih
);
162 extern void hndrte_arena_init(uintptr base
, uintptr lim
, uintptr stackbottom
);
163 extern void hndrte_cons_init(si_t
*sih
);
164 extern void hndrte_cons_check(void);
165 extern int hndrte_log_init(void);
168 extern void hndrte_update_stats(hndrte_cpu_stats_t
*cpustats
);
171 /* Console command support */
172 typedef void (*cons_fun_t
)(uint32 arg
, uint argc
, char *argv
[]);
174 #ifdef HNDRTE_CONSOLE
175 extern void hndrte_cons_addcmd(char *name
, cons_fun_t fun
, uint32 arg
);
177 #define hndrte_cons_addcmd(name, fun, arg) { (void)(name); (void)(fun); (void)(arg); }
180 /* bcopy, bcmp, and bzero */
181 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
182 #define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
183 #define bzero(b, len) memset((b), '\0', (len))
186 #define TRACE_LOC OSL_UNCACHED(0x18000044) /* flash address reg in chipc */
187 #define HNDRTE_TRACE(val) do {*((uint32 *)TRACE_LOC) = val;} while (0)
188 #define TRACE_LOC2 OSL_UNCACHED(0x180000d0) /* bpaddrlow */
189 #define HNDRTE_TRACE2(val) do {*((uint32 *)TRACE_LOC2) = val;} while (0)
190 #define TRACE_LOC3 OSL_UNCACHED(0x180000d8) /* bpdata */
191 #define HNDRTE_TRACE3(val) do {*((uint32 *)TRACE_LOC3) = val;} while (0)
193 #define HNDRTE_TRACE(val) do {} while (0)
194 #define HNDRTE_TRACE2(val) do {} while (0)
195 #define HNDRTE_TRACE3(val) do {} while (0)
198 /* debugging prints */
200 #define HNDRTE_ERROR(args) do {printf args;} while (0)
201 #else /* BCMDBG_ERR */
202 #define HNDRTE_ERROR(args) do {} while (0)
203 #endif /* BCMDBG_ERR */
206 #if defined(BCMDBG_ASSERT)
207 extern void hndrte_assert(const char *file
, int line
);
209 #define _FILENAME_ "_FILENAME_ is not defined"
211 #define ASSERT(exp) \
212 do { if (!(exp)) hndrte_assert(_FILENAME_, __LINE__); } while (0)
214 #define ASSERT(exp) do {} while (0)
215 #endif /* BCMDBG_ASSERT */
218 typedef void (*to_fun_t
)(void *arg
);
220 typedef struct _ctimeout
{
221 struct _ctimeout
*next
;
228 extern uint32 _memsize
;
230 extern void hndrte_delay(uint32 usec
);
231 extern uint32
hndrte_time(void);
232 extern uint32
hndrte_update_now(void);
233 #ifdef BCMDBG_SD_LATENCY
234 extern uint32
hndrte_time_us(void);
235 extern uint32
hndrte_update_now_us(void);
236 #endif /* BCMDBG_SD_LATENCY */
237 extern void hndrte_wait_irq(si_t
*sih
);
238 extern void hndrte_enable_interrupts(void);
239 extern void hndrte_disable_interrupts(void);
240 extern void hndrte_set_irq_timer(uint ms
);
241 extern void hndrte_ack_irq_timer(void);
242 extern void hndrte_suspend_timer(void);
243 extern void hndrte_resume_timer(void);
244 extern void hndrte_trap_init(void);
245 extern void hndrte_trap_handler(trap_t
*tr
);
247 typedef struct hndrte_timer
249 uint32
*context
; /* first field so address of context is timer struct ptr */
251 void (*mainfn
)(struct hndrte_timer
*);
252 void (*auxfn
)(void *context
);
258 } hndrte_timer_t
, hndrte_task_t
;
260 extern bool hndrte_timeout(ctimeout_t
*t
, uint32 ms
, to_fun_t fun
, void *arg
);
261 extern void hndrte_del_timeout(ctimeout_t
*t
);
262 extern void hndrte_init_timeout(ctimeout_t
*t
);
264 extern hndrte_timer_t
*hndrte_init_timer(void *context
, void *data
,
265 void (*mainfn
)(hndrte_timer_t
*),
266 void (*auxfn
)(void*));
267 extern void hndrte_free_timer(hndrte_timer_t
*t
);
268 extern bool hndrte_add_timer(hndrte_timer_t
*t
, uint ms
, int periodic
);
269 extern bool hndrte_del_timer(hndrte_timer_t
*t
);
271 extern int hndrte_schedule_work(void *context
, void *data
,
272 void (*taskfn
)(hndrte_timer_t
*), int delay
);
275 #if defined(BCMDBG_MEM) || defined(BCMDBG_MEMFAIL)
276 #define hndrte_malloc(_size) hndrte_malloc_align((_size), 0, __FILE__, __LINE__)
277 extern void *hndrte_malloc_align(uint size
, uint alignbits
, const char *file
, int line
);
278 #define hndrte_malloc_pt(_size) hndrte_malloc_ptblk((_size), __FILE__, __LINE__)
279 extern void *hndrte_malloc_ptblk(uint size
, const char *file
, int line
);
281 #define hndrte_malloc(_size) hndrte_malloc_align((_size), 0)
282 extern void *hndrte_malloc_align(uint size
, uint alignbits
);
284 #define hndrte_malloc_pt(_size) hndrte_malloc_ptblk((_size))
285 extern void *hndrte_malloc_ptblk(uint size
);
286 #endif /* BCMDBG_MEM */
287 extern void hndrte_append_ptblk(void);
288 extern void *hndrte_realloc(void *ptr
, uint size
);
289 extern int hndrte_free(void *ptr
);
290 extern int hndrte_free_pt(void *ptr
);
291 extern uint
hndrte_memavail(void);
292 extern uint
hndrte_hwm(void);
293 extern void hndrte_print_memuse(void);
294 extern void hndrte_print_memwaste(uint32 arg
, uint argc
, char *argv
[]);
296 /* Low Memory rescue functions
297 * Implement a list of Low Memory free functions that hndrte can
298 * call on allocation failure. List is populated through calls to
299 * hndrte_pt_lowmem_register() API
301 typedef void (*hndrte_lowmem_free_fn_t
)(void *free_arg
);
302 typedef struct hndrte_lowmem_free hndrte_lowmem_free_t
;
303 struct hndrte_lowmem_free
{
304 hndrte_lowmem_free_t
*next
;
305 hndrte_lowmem_free_fn_t free_fn
;
309 extern void hndrte_pt_lowmem_register(hndrte_lowmem_free_t
*lowmem_free_elt
);
310 extern void hndrte_pt_lowmem_unregister(hndrte_lowmem_free_t
*lowmem_free_elt
);
313 #if defined(BCMDBG_MEM) || defined(BCMDBG_MEMFAIL)
315 extern void hndrte_print_malloc(void);
316 extern int hndrte_memcheck(char *file
, int line
);
318 extern void *hndrte_dma_alloc_consistent(uint size
, uint16 align
, uint
*alloced
,
319 void *pap
, char *file
, int line
);
321 extern void *hndrte_dma_alloc_consistent(uint size
, uint16 align
, uint
*alloced
,
323 #endif /* BCMDBG_MEM */
324 extern void hndrte_dma_free_consistent(void *va
);
327 extern void hndrte_reclaim(void);
329 #define hndrte_reclaim() do {} while (0)
330 #endif /* DONGLEBUILD */
332 extern uint
hndrte_arena_add(uint32 base
, uint size
);
334 #ifndef HNDRTE_STACK_SIZE
335 #define HNDRTE_STACK_SIZE (8192)
338 extern uint __watermark
;
341 extern void hndrte_print_timers(uint32 arg
, uint argc
, char *argv
[]);
343 #if defined(__arm__) || defined(__thumb__) || defined(__thumb2__)
344 #define BCMDBG_TRACE(x) __watermark = (x)
346 #define BCMDBG_TRACE(x)
347 #endif /* !__arm__ && !__thumb__ && !__thumb2__ */
349 #define BCMDBG_TRACE(x)
352 extern uint32 g_assert_type
;
354 #ifdef DONGLEOVERLAYS
355 extern int hndrte_overlay_copy(uint32 overlay_idx
, uint8
*overlay
, int offset
, int len
);
356 extern int hndrte_overlay_invalidate(uint32 overlay_idx
);
357 extern void hndrte_overlay_prep(void);
358 extern uint32
hndrte_overlayerrfn_branch_instr(int32 from
, int32 to
);
359 #endif /* DONGLEOVERLAYS */
361 #endif /* _HNDRTE_H */