Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sbecom_inline_linux.h
Go to the documentation of this file.
1 #ifndef _INC_SBECOM_INLNX_H_
2 #define _INC_SBECOM_INLNX_H_
3 
4 /*-----------------------------------------------------------------------------
5  * sbecom_inline_linux.h - SBE common Linux inlined routines
6  *
7  * Copyright (C) 2007 One Stop Systems, Inc.
8  * Copyright (C) 2005 SBE, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * For further information, contact via email: [email protected]
21  * One Stop Systems, Inc. Escondido, California U.S.A.
22  *-----------------------------------------------------------------------------
23  */
24 
25 
26 #include <linux/types.h>
27 #include <linux/module.h>
28 #include <linux/kernel.h> /* resolves kmalloc references */
29 #include <linux/skbuff.h> /* resolves skb references */
30 #include <linux/netdevice.h> /* resolves dev_kree_skb_any */
31 #include <asm/byteorder.h> /* resolves cpu_to_le32 */
32 
33 /* forward reference */
36 
37 
38 /*
39  * system dependent callbacks
40  */
41 
42 /**********/
43 /* malloc */
44 /**********/
45 
46 static inline void *
47 OS_kmalloc (size_t size)
48 {
49  char *ptr = kmalloc (size, GFP_KERNEL | GFP_DMA);
50 
51  if (ptr)
52  memset (ptr, 0, size);
53  return ptr;
54 }
55 
56 static inline void
57 OS_kfree (void *x)
58 {
59  kfree (x);
60 }
61 
62 
63 /****************/
64 /* memory token */
65 /****************/
66 
67 static inline void *
68 OS_mem_token_alloc (size_t size)
69 {
70  struct sk_buff *skb;
71 
72  skb = dev_alloc_skb (size);
73  if (!skb)
74  {
75  //pr_warning("no mem in OS_mem_token_alloc !\n");
76  return 0;
77  }
78  return skb;
79 }
80 
81 
82 static inline void
83 OS_mem_token_free (void *token)
84 {
85  dev_kfree_skb_any (token);
86 }
87 
88 
89 static inline void
90 OS_mem_token_free_irq (void *token)
91 {
92  dev_kfree_skb_irq (token);
93 }
94 
95 
96 static inline void *
97 OS_mem_token_data (void *token)
98 {
99  return ((struct sk_buff *) token)->data;
100 }
101 
102 
103 static inline void *
104 OS_mem_token_next (void *token)
105 {
106  return 0;
107 }
108 
109 
110 static inline int
111 OS_mem_token_len (void *token)
112 {
113  return ((struct sk_buff *) token)->len;
114 }
115 
116 
117 static inline int
118 OS_mem_token_tlen (void *token)
119 {
120  return ((struct sk_buff *) token)->len;
121 }
122 
123 
124 /***************************************/
125 /* virtual to physical addr conversion */
126 /***************************************/
127 
128 static inline u_long
129 OS_phystov (void *addr)
130 {
131  return (u_long) __va (addr);
132 }
133 
134 
135 static inline u_long
136 OS_vtophys (void *addr)
137 {
138  return __pa (addr);
139 }
140 
141 
142 /**********/
143 /* semops */
144 /**********/
145 
146 void OS_sem_init (void *, int);
147 
148 
149 static inline void
150 OS_sem_free (void *sem)
151 {
152  /*
153  * NOOP - since semaphores structures predeclared w/in structures, no
154  * longer malloc'd
155  */
156 }
157 
158 #define SD_SEM_TAKE(sem,desc) down(sem)
159 #define SD_SEM_GIVE(sem) up(sem)
160 #define SEM_AVAILABLE 1
161 #define SEM_TAKEN 0
162 
163 
164 /**********************/
165 /* watchdog functions */
166 /**********************/
167 
168 struct watchdog
169 {
170  struct timer_list h;
172  void *softc;
173  void (*func) (void *softc);
174  int ticks;
175  int init_tq;
176 };
177 
178 
179 static inline int
180 OS_start_watchdog (struct watchdog * wd)
181 {
182  wd->h.expires = jiffies + wd->ticks;
183  add_timer (&wd->h);
184  return 0;
185 }
186 
187 
188 static inline int
189 OS_stop_watchdog (struct watchdog * wd)
190 {
191  del_timer_sync (&wd->h);
192  return 0;
193 }
194 
195 
196 static inline int
197 OS_free_watchdog (struct watchdog * wd)
198 {
199  OS_stop_watchdog (wd);
200  OS_kfree (wd);
201  return 0;
202 }
203 
204 
205 /* sleep in microseconds */
206 void OS_uwait (int usec, char *description);
207 void OS_uwait_dummy (void);
208 
209 
210 /* watchdog functions */
211 int OS_init_watchdog(struct watchdog *wdp, void (*f) (void *), void *ci, int usec);
212 
213 
214 #endif /*** _INC_SBECOM_INLNX_H_ ***/