source: svn/trunk/newcon3bcm2_21bu/magnum/basemodules/reg/breg_mem.h @ 55

Last change on this file since 55 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 13.0 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2012, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: breg_mem.h $
11 * $brcm_Revision: Hydra_Software_Devel/15 $
12 * $brcm_Date: 3/9/12 4:48p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/basemodules/reg/breg_mem.h $
19 *
20 * Hydra_Software_Devel/15   3/9/12 4:48p erickson
21 * SW7231-705: add BDBG_OBJECT_ASSERT
22 *
23 * Hydra_Software_Devel/14   8/24/10 8:25a erickson
24 * SW3548-815: allow BREG_Read/Write to be used inside a
25 * BREG_AtomicUpdate32 callback without warning. this avoids the need for
26 * the app to create a second method of accessing registers.
27 *
28 * Hydra_Software_Devel/13   5/3/10 10:41a erickson
29 * SW3548-815: document BREG_AtomicUpdate32 and
30 * BREG_SetAtomicUpdate32Callback more
31 *
32 * Hydra_Software_Devel/12   9/24/08 7:32p vsilyaev
33 * PR 46950: Use unified declaration of BREG handle for debug and release
34 * builds
35 *
36 * Hydra_Software_Devel/11   9/23/08 3:43p erickson
37 * PR46950: added BREG_SetAtomicUpdate32Callback
38 *
39 * Hydra_Software_Devel/10   6/5/08 5:24p vsilyaev
40 * PR43119: PR 43119: Added API for atomic register access
41 *
42 * Hydra_Software_Devel/PR43119/1   5/29/08 12:14p vsilyaev
43 * PR 43119: Added API for atomic register access
44 *
45 * Hydra_Software_Devel/9   7/21/06 11:27a vsilyaev
46 * PR 22695: Changes to make BREG_MEM compatible between debug and release
47 * builds
48 *
49 * Hydra_Software_Devel/8   12/22/04 4:06p marcusk
50 * PR13660: Added _isr flavors for each function.
51 *
52 * Hydra_Software_Devel/7   8/10/04 10:40a vsilyaev
53 * PR 12172: Unified type of the BREG_Handle, it removes space for
54 * different compiler behaviour in debug and release builds
55 *
56 * Hydra_Software_Devel/6   9/15/03 6:08p marcusk
57 * Updated to use void * as register base address.
58 *
59 * Hydra_Software_Devel/5   5/30/03 12:03p marcusk
60 * Changed CreateRegHandle/DestroyRegHandle to Open/Close to be more
61 * consistant.
62 *
63 * Hydra_Software_Devel/4   3/26/03 2:08p marcusk
64 * Added comments.
65 *
66 * Hydra_Software_Devel/3   3/7/03 9:24a marcusk
67 * Minor cleanup.
68 *
69 * Hydra_Software_Devel/2   3/5/03 4:19p marcusk
70 * Fixed minor issues (got it to compile).
71 *
72 * Hydra_Software_Devel/1   3/5/03 3:34p marcusk
73 * Initial version.
74 *
75 ***************************************************************************/
76
77/*= Module Overview ********************************************************
78This module supplies the function required to access memory mapped registers.
79Before any registers can be accessed an appropriate register handle should
80be created (normally done at system init time).  This register handle is
81then given to any modules that require access to the corresponding memory
82mapped registers.
83***************************************************************************/
84
85#ifndef BREG_MEM_H
86#define BREG_MEM_H
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
92/*
93Summary:
94This is an opaque handle that is used for memory mapped register functions.
95*/
96typedef struct BREG_Impl *BREG_Handle;
97
98
99
100
101/*
102Summary:
103This function creates a register handle for memory mapped registers.
104
105Description:
106This function must be called before any memory mapped registers can be
107accessed.  This normally is done by platform specific code during init
108time.  The resulting register handle is then passed to any modules that
109must access the corresponding registers.
110*/
111void BREG_Open(
112                          BREG_Handle *pRegHandle, /* [out] Returns a register handle */
113                          void *Address, /* Base address of the memory mapped register range */
114                          size_t MaxRegOffset /* Maximum offset for this memory mapped register range */
115                          );
116
117/*
118Summary:
119This function destroys a previous created register handle.
120
121Description:
122This function frees any resources associate with a memory mapped register
123handle.  After this function is called the register handle can no longer
124be used for subsequent register accesses.
125*/
126void BREG_Close(
127                           BREG_Handle RegHandle /* Register handle created by BREG_CreateRegHandle() */
128                           );
129
130
131#if BDBG_DEBUG_BUILD != 1
132
133#include "breg_mem_opt.h"   /* Contains optimized versions of these routines */
134
135#else
136
137/*
138Summary:
139This function writes 32 bits to a register.
140
141Description:
142Although this fuction will never return an error it will assert if the
143RegHandle is invalid or during a debug build if the reg offset is larger
144than the MaxRegOffset specified in the BREG_CreateRegHandle function.
145*/
146void BREG_Write32(
147                  BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
148                  uint32_t reg, /* Register offset to write */
149                  uint32_t data /* Data value to write to register */
150                  );
151
152/*
153Summary:
154This function writes 16 bits to a register.
155
156Description:
157Although this fuction will never return an error it will assert if the
158RegHandle is invalid or during a debug build if the reg offset is larger
159than the MaxRegOffset specified in the BREG_CreateRegHandle function.
160*/
161void BREG_Write16(
162                  BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
163                  uint32_t reg, /* Register offset to write */
164                  uint16_t data /* Data value to write to register */
165                  );
166
167/*
168Summary:
169This function writes 8 bits to a register.
170
171Description:
172Although this fuction will never return an error it will assert if the
173RegHandle is invalid or during a debug build if the reg offset is larger
174than the MaxRegOffset specified in the BREG_CreateRegHandle function.
175*/
176void BREG_Write8(
177                  BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
178                  uint32_t reg, /* Register offset to write */
179                 uint8_t data /* Data value to write to register */
180                 );
181
182/*
183Summary:
184This function reads 32 bits from a register.
185
186Description:
187Although this fuction cannot return an error it will assert if the
188RegHandle is invalid or during a debug build if the reg offset is larger
189than the MaxRegOffset specified in the BREG_CreateRegHandle function.
190*/
191uint32_t BREG_Read32(
192                 BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
193                 uint32_t reg /* Register offset to read */
194                 );
195
196/*
197Summary:
198This function reads 16 bits from a register.
199
200Description:
201Although this fuction cannot return an error it will assert if the
202RegHandle is invalid or during a debug build if the reg offset is larger
203than the MaxRegOffset specified in the BREG_CreateRegHandle function.
204*/
205uint16_t BREG_Read16(
206                 BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
207                 uint32_t reg /* Register offset to read */
208                 );
209
210/*
211Summary:
212This function reads 8 bits from a register.
213
214Description:
215Although this fuction cannot return an error it will assert if the
216RegHandle is invalid or during a debug build if the reg offset is larger
217than the MaxRegOffset specified in the BREG_CreateRegHandle function.
218*/
219uint8_t BREG_Read8(
220                 BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
221                 uint32_t reg /* Register offset to read */
222                 );
223
224#endif /* BDBG_DEBUG_BUILD != 1 */
225
226/*
227Summary:
228This function atomically updates a 32 bit register value.
229
230Description:
231This function atomically update 32 bit value stored in the hardware register.
232It's equivalent to the following code:
233
234   BREG_Write32(regHandle, reg, (BREG_Read32(regHandle, reg) & (~mask)) | value);
235
236with the added guarantee that the read/modify/write will be performed atomically across all magnum modules.
237
238See BREG_SetAtomicUpdate32Callback for extending the synchronization domain outside of magnum and into the OS as well.
239*/
240void BREG_AtomicUpdate32(
241                  BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
242                  uint32_t reg, /* Register offset to write */
243                  uint32_t mask,
244                  uint32_t value
245                  );
246
247/*
248Summary:
249This function atomically updates a 32 bit register value. Used for _isr context.
250
251Description:
252See BREG_AtomicUpdate32.
253*/
254void BREG_AtomicUpdate32_isr(
255                  BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
256                  uint32_t reg, /* Register offset to write */
257                  uint32_t mask,
258                  uint32_t value
259                  );
260
261/*
262Summary:
263Callback for BREG_SetAtomicUpdate32Callback
264
265Description:
266Operation should be implemented as:
267
268    uint32_t value;
269    lock();
270    value = *CONVERT_TO_ADDR(reg);
271    value &= ~mask;
272    value |= value;
273    *CONVERT_TO_ADDR(reg) = value;
274    unlock();
275*/
276typedef void (*BREG_AtomicUpdate32Callback)(
277    void *callbackContext, /* callbackContext passed into BREG_SetAtomicUpdate32Callback */
278    uint32_t reg,   /* Register offset to write */
279    uint32_t mask,
280    uint32_t value
281    );
282
283/*
284Summary:
285Set optional atomic update callback
286
287Description:
288On some systems, there are registers which are shared between magnum and the OS.
289In these cases, a platform-specific atomic update must be implemented outside of Magnum by means of this isr callback.
290
291The required implementation varies per OS. For example:
292 - In linux kernel mode, the atomic update callback will acquire a spinlock.
293 - In linux user mode, the atomic update callback will call an ioctl to the user mode driver which will then acquire a spinlock.
294 - In vxworks, the atomic update callback could acquire a mutex shared by the OS.
295
296This callback is not required if there are no registers shared between magnum and the OS.
297Also, if the kernel can call BKNI_EnterCriticalSection for shared registers, this callback is not required.
298*/
299void BREG_SetAtomicUpdate32Callback(
300                  BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
301                  BREG_AtomicUpdate32Callback callback_isr, /* If NULL, default behavior will be restored.
302                                                               This callback is called in isr context. It must be very fast. */
303                  void *callbackContext                     /* User context passed to callback */
304                  );
305
306/*
307Summary:
308This function atomically compares and updates 32 bit register value.
309
310Description:
311This function atomically reads 32 bit value from  the hardware register, compares with value
312given by user, and if match newValue stored in the hardware register. It's equivalent to the following
313code:
314
315    uint32_t val = BREG_Read32(regHandle, reg);
316    if(val==oldValue) BREG_Write32(regHandle, reg, newValue)
317    return val;
318
319with an added guarantee that the read and write are performed atomically.
320*/
321uint32_t BREG_CompareAndSwap32(
322                  BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
323                  uint32_t reg, /* Register offset to write */
324                  uint32_t oldValue, /* value to compare  */
325                  uint32_t newValue /* value to write  */
326                  );
327
328/*
329Summary:
330This function atomically compares and updates 32 bit register value. Used for _isr context.
331*/
332uint32_t BREG_CompareAndSwap32_isr(
333                  BREG_Handle RegHandle, /* Register handle created by BREG_CreateRegHandle() */
334                  uint32_t reg, /* Register offset to write */
335                  uint32_t oldValue, /* value to compare  */
336                  uint32_t newValue /* value to write  */
337                  );
338
339/* ISR() flavors go here so they are picked up for both debug and release builds */
340
341/*
342Summary:
343This function writes 16 bits to a register.  Used for _isr context.
344*/
345#define BREG_Write16_isr BREG_Write16
346
347/*
348Summary:
349This function writes 8 bits to a register.  Used for _isr context.
350*/
351#define BREG_Write8_isr BREG_Write8
352
353/*
354Summary:
355This function writes 32 bits to a register.  Used for _isr context.
356*/
357#define BREG_Write32_isr BREG_Write32
358
359/*
360Summary:
361This function reads 8 bits from a register.  Used for _isr context.
362*/
363#define BREG_Read8_isr BREG_Read8
364
365/*
366Summary:
367This function reads 16 bits from a register.  Used for _isr context.
368*/
369#define BREG_Read16_isr BREG_Read16
370
371/*
372Summary:
373This function reads 32 bits from a register.  Used for _isr context.
374*/
375#define BREG_Read32_isr BREG_Read32
376
377/* Internal representation of the BREG handle */
378BDBG_OBJECT_ID_DECLARE(BREG);
379typedef struct BREG_Impl
380{
381    BDBG_OBJECT(BREG)
382    uint32_t BaseAddr; /* BaseAddr shall be the first member to keep it run-time compatible with the release builds */
383    size_t MaxRegOffset;
384
385    struct {
386        BREG_AtomicUpdate32Callback callback_isr;
387        void *callbackContext;
388    } atomicUpdate32;
389    bool inAtomicUpdateCallback;
390} BREG_Impl;
391
392#ifdef __cplusplus
393}
394#endif
395
396#endif
397/* End of File */
Note: See TracBrowser for help on using the repository browser.