1/*
2 * OS Abstraction Layer
3 *
4 * Copyright (C) 2010, Broadcom Corporation. All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * $Id: osl.h,v 13.45.2.2 2010/08/31 00:29:57 Exp $
19 */
20
21#ifndef _osl_h_
22#define _osl_h_
23
24/* osl handle type forward declaration */
25typedef struct osl_info osl_t;
26typedef struct osl_dmainfo osldma_t;
27
28#define OSL_PKTTAG_SZ	32 /* Size of PktTag */
29
30/* Drivers use PKTFREESETCB to register a callback function when a packet is freed by OSL */
31typedef void (*pktfree_cb_fn_t)(void *ctx, void *pkt, unsigned int status);
32
33/* Drivers use REGOPSSET() to register register read/write funcitons */
34typedef unsigned int (*osl_rreg_fn_t)(void *ctx, void *reg, unsigned int size);
35typedef void  (*osl_wreg_fn_t)(void *ctx, void *reg, unsigned int val, unsigned int size);
36
37#ifdef __mips__
38#define PREF_LOAD		0
39#define PREF_STORE		1
40#define PREF_LOAD_STREAMED	4
41#define PREF_STORE_STREAMED	5
42#define PREF_LOAD_RETAINED	6
43#define PREF_STORE_RETAINED	7
44#define PREF_WBACK_INV		25
45#define PREF_PREPARE4STORE	30
46
47#define MAKE_PREFETCH_FN(hint) \
48static inline void prefetch_##hint(const void *addr) \
49{ \
50	__asm__ __volatile__(\
51	"       .set    mips4           \n" \
52	"       pref    %0, (%1)        \n" \
53	"       .set    mips0           \n" \
54	: \
55	: "i" (hint), "r" (addr)); \
56}
57
58#define MAKE_PREFETCH_RANGE_FN(hint) \
59static inline void prefetch_range_##hint(const void *addr, int len) \
60{ \
61	int size = len; \
62	while (size > 0) { \
63		prefetch_##hint(addr); \
64		size -= 32; \
65	} \
66}
67
68MAKE_PREFETCH_FN(PREF_LOAD)
69MAKE_PREFETCH_RANGE_FN(PREF_LOAD)
70MAKE_PREFETCH_FN(PREF_STORE)
71MAKE_PREFETCH_RANGE_FN(PREF_STORE)
72MAKE_PREFETCH_FN(PREF_LOAD_STREAMED)
73MAKE_PREFETCH_RANGE_FN(PREF_LOAD_STREAMED)
74MAKE_PREFETCH_FN(PREF_STORE_STREAMED)
75MAKE_PREFETCH_RANGE_FN(PREF_STORE_STREAMED)
76MAKE_PREFETCH_FN(PREF_LOAD_RETAINED)
77MAKE_PREFETCH_RANGE_FN(PREF_LOAD_RETAINED)
78MAKE_PREFETCH_FN(PREF_STORE_RETAINED)
79MAKE_PREFETCH_RANGE_FN(PREF_STORE_RETAINED)
80#endif /* __mips__ */
81
82#if defined(__ECOS)
83#include <ecos_osl.h>
84#elif  defined(DOS)
85#include <dos_osl.h>
86#elif defined(PCBIOS)
87#include <pcbios_osl.h>
88#elif defined(linux)
89#ifdef USER_MODE
90#include <usermode_osl.h>
91#else
92#include <linux_osl.h>
93#endif
94#elif defined(NDIS)
95#include <ndis_osl.h>
96#elif defined(_CFE_)
97#include <cfe_osl.h>
98#elif defined(_MINOSL_)
99#include <min_osl.h>
100#elif defined(MACOSX)
101#include <macosx_osl.h>
102#elif defined(__NetBSD__)
103#include <bsd_osl.h>
104#elif defined(EFI)
105#include <efi_osl.h>
106#elif defined(TARGETOS_nucleus)
107#include <nucleus_osl.h>
108#else
109#error "Unsupported OSL requested"
110#endif
111
112#ifndef PKTDBG_TRACE
113#define PKTDBG_TRACE(osh, pkt, bit)
114#endif
115
116/* --------------------------------------------------------------------------
117** Register manipulation macros.
118*/
119
120#define	SET_REG(osh, r, mask, val)	W_REG((osh), (r), ((R_REG((osh), r) & ~(mask)) | (val)))
121
122#ifndef AND_REG
123#define AND_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) & (v))
124#endif   /* !AND_REG */
125
126#ifndef OR_REG
127#define OR_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) | (v))
128#endif   /* !OR_REG */
129
130#if !defined(OSL_SYSUPTIME)
131#define OSL_SYSUPTIME() (0)
132#define OSL_SYSUPTIME_SUPPORT FALSE
133#else
134#define OSL_SYSUPTIME_SUPPORT TRUE
135#endif /* OSL_SYSUPTIME */
136
137#endif	/* _osl_h_ */
138