1 /******************************************************
2 * File: netapi_util.h
3 * Purpose: misc utilites
4 **************************************************************
5 * FILE: netapi_util.h
6 *
7 * DESCRIPTION: netapi utility header file for user space transport
8 * library
9 *
10 * REVISION HISTORY: rev 0.0.1
11 *
12 * Copyright (c) Texas Instruments Incorporated 2010-2011
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * Neither the name of Texas Instruments Incorporated nor the names of
27 * its contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *****************************************************/
43 #ifndef __NETAPI_UTIL__H
44 #define __NETAPI_UTIL__H
46 #include <stdint.h>
48 /* virtual address of the [only] memory pool */
49 extern uint8_t *netapi_VM_mem_start;
50 extern uint8_t *netapi_VM_mem_end;
52 /* Physical address of the [only] memory pool */
53 extern uint8_t *netapi_VM_mem_start_phy;
54 extern uint8_t *netapi_VM_mem_end_phy;
56 /* timing */
57 static inline unsigned long netapi_timing_start(void)
58 {
59 volatile int vval;
60 //read clock
61 asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(vval));
62 return vval;
63 }
64 #define netapi_timing_stop netapi_timing_start
66 //netapi kernel module access routines
67 int netapi_utilModInit(void);
68 void netapi_utilModClose(void);
69 unsigned long netapi_utilGetPhysOfBufferArea(void);
70 unsigned long netap_utilGetSizeofBufferArea(void);
71 int netapi_utilCacheWbInv(void *ptr, size_t size);
72 int netapi_utilCacheInv(void *ptr, size_t size);
73 int netapi_utilCacheWb(void *ptr, size_t size);
74 unsigned long netapi_utilGetVaOfBufferArea(unsigned int offset, unsigned int size);
76 //for benchmarking
77 void Osal_cache_op_measure_reset(void);
78 unsigned int Osal_cache_op_measure(int * p_n) ;
80 //utility to convert virt2phy, phy2virt
81 static inline void* _Osal_qmssVirtToPhy (void *ptr)
82 {
83 return (void *)(netapi_VM_mem_start_phy + ((uint8_t*)ptr - netapi_VM_mem_start));
84 }
86 static inline void * _Osal_qmssPhyToVirt (void *ptr)
87 {
88 if (!ptr) return (void *) 0;
89 //todo, see if out of range of mem_start_phy and size!! (like mmu would do)
90 return (void *)(netapi_VM_mem_start + ((uint8_t*)ptr - netapi_VM_mem_start_phy));
91 }
92 #endif