source: soft/giet_vm/giet_common/utils.h @ 430

Last change on this file since 430 was 430, checked in by alain, 10 years ago

Introducing fixed format (X_WIDTH / YWIDTH / P_WIDTH) for processor index.

  • Property svn:executable set to *
File size: 17.5 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : utils.h
3// Date     : 18/10/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The utils.c and utils.h files are part of the GIET-VM nano-kernel.
8// They define more or less the GIET-VM Hardware Abstraction Layer,
9// and contains various utility functions, that can be used by both the
10// boot code and the kernel code (but not by the user applications).
11///////////////////////////////////////////////////////////////////////////////////
12
13#ifndef GIET_UTILS_H
14#define GIET_UTILS_H
15
16#include <mapping_info.h>
17#include <giet_config.h>
18
19//////////////////////////////////////////////////////////////////////////////////
20// NULL pointer definition
21//////////////////////////////////////////////////////////////////////////////////
22
23#define NULL (void *)0
24
25///////////////////////////////////////////////////////////////////////////////////
26// This structure is used to have one single lock in a cache line
27///////////////////////////////////////////////////////////////////////////////////
28
29typedef struct giet_lock_s { unsigned int value;
30                             unsigned int padding[15]; } giet_lock_t;
31
32///////////////////////////////////////////////////////////////////////////////////
33// To access the virtual addresses defined in the giet_vsegs.ld file.
34///////////////////////////////////////////////////////////////////////////////////
35
36typedef struct _ld_symbol_s _ld_symbol_t;
37
38extern _ld_symbol_t boot_code_vbase;
39extern _ld_symbol_t boot_data_vbase;
40
41extern _ld_symbol_t kernel_code_vbase;
42extern _ld_symbol_t kernel_data_vbase;
43extern _ld_symbol_t kernel_uncdata_vbase;
44extern _ld_symbol_t kernel_init_vbase;
45
46///////////////////////////////////////////////////////////////////////////////////
47///////////////////////////////////////////////////////////////////////////////////
48//     CP0 registers access functions
49///////////////////////////////////////////////////////////////////////////////////
50///////////////////////////////////////////////////////////////////////////////////
51
52///////////////////////////////////////////////////////////////////////////////////
53// Returns CP0_SCHED register content
54// (virtual base address of the processor scheduler)
55///////////////////////////////////////////////////////////////////////////////////
56extern unsigned int _get_sched(void);
57
58///////////////////////////////////////////////////////////////////////////////////
59// Returns CP0_EPC register content.
60///////////////////////////////////////////////////////////////////////////////////
61extern unsigned int _get_epc(void);
62
63///////////////////////////////////////////////////////////////////////////////////
64// Returns CP0_BVAR register content.
65///////////////////////////////////////////////////////////////////////////////////
66extern unsigned int _get_bvar(void);
67
68///////////////////////////////////////////////////////////////////////////////////
69// Returns CP0_CR register content.
70///////////////////////////////////////////////////////////////////////////////////
71extern unsigned int _get_cr(void);
72
73///////////////////////////////////////////////////////////////////////////////////
74// Returns CP0_SR register content.
75///////////////////////////////////////////////////////////////////////////////////
76extern unsigned int _get_sr(void);
77
78///////////////////////////////////////////////////////////////////////////////////
79// Returns CP0_PROCID register content.
80// Processor identifier (12 bits)
81///////////////////////////////////////////////////////////////////////////////////
82extern unsigned int _get_procid(void);
83
84///////////////////////////////////////////////////////////////////////////////////
85// Returns CP0_TIME register content.
86// Processor local time (32 bits)
87///////////////////////////////////////////////////////////////////////////////////
88extern unsigned int _get_proctime(void);
89
90///////////////////////////////////////////////////////////////////////////////////
91// Save CP0_SR value to variable pointed by save_sr_ptr and disable IRQs.
92///////////////////////////////////////////////////////////////////////////////////
93extern void         _it_disable( unsigned int* save_sr_ptr );
94
95///////////////////////////////////////////////////////////////////////////////////
96// Restore CP0_SR register from variable pointed by save_sr_ptr.
97///////////////////////////////////////////////////////////////////////////////////
98extern void         _it_restore( unsigned int* save_sr_ptr );
99
100///////////////////////////////////////////////////////////////////////////////////
101// Set a new value in CP0_SCHED register.
102// (virtual base address of the processor scheduler)
103///////////////////////////////////////////////////////////////////////////////////
104extern void         _set_sched(unsigned int value);
105
106///////////////////////////////////////////////////////////////////////////////////
107// Set a new value in CP0_SR register.
108///////////////////////////////////////////////////////////////////////////////////
109extern void         _set_sr(unsigned int value);
110
111
112///////////////////////////////////////////////////////////////////////////////////
113///////////////////////////////////////////////////////////////////////////////////
114//     CP2 registers access functions
115///////////////////////////////////////////////////////////////////////////////////
116///////////////////////////////////////////////////////////////////////////////////
117
118///////////////////////////////////////////////////////////////////////////////////
119// Returns CP2_PTPR register value.
120// Page table physical base address for the running context.
121// Contains only the 27 MSB bits, right justified.
122///////////////////////////////////////////////////////////////////////////////////
123extern unsigned int _get_mmu_ptpr(void);
124
125///////////////////////////////////////////////////////////////////////////////////
126// Returns CP2_MODE register value.
127// MMU current mode, defined by 4 bits, right justified: ITLB/DTLB/ICACHE/DCACHE
128///////////////////////////////////////////////////////////////////////////////////
129extern unsigned int _get_mmu_mode(void);
130
131///////////////////////////////////////////////////////////////////////////////////
132// Set a new value in CP2_PTPR register.
133///////////////////////////////////////////////////////////////////////////////////
134extern void         _set_mmu_ptpr(unsigned int value);
135
136///////////////////////////////////////////////////////////////////////////////////
137// Set a new value in CP2_MODE register.
138///////////////////////////////////////////////////////////////////////////////////
139extern void         _set_mmu_mode(unsigned int value);
140
141///////////////////////////////////////////////////////////////////////////////////
142// Set a value in  CP2_DCACHE_INVAL register.
143// It invalidates the data cache line, if the virtual address defined by the
144// value argument hit in DCACHE.
145///////////////////////////////////////////////////////////////////////////////////
146extern void         _set_mmu_dcache_inval(unsigned int value);
147
148
149
150///////////////////////////////////////////////////////////////////////////////////
151///////////////////////////////////////////////////////////////////////////////////
152//     Physical addressing functions
153///////////////////////////////////////////////////////////////////////////////////
154///////////////////////////////////////////////////////////////////////////////////
155
156////////////////////////////////////////////////////////////////////////////
157// This function makes a physical read access to a 32 bits word in memory,
158// after a temporary DTLB de-activation and paddr extension.
159////////////////////////////////////////////////////////////////////////////
160extern unsigned int _physical_read(  unsigned long long paddr );
161
162////////////////////////////////////////////////////////////////////////////
163// This function makes a physical write access to a 32 bits word in memory,
164// after a temporary DTLB de-activation and paddr extension.
165////////////////////////////////////////////////////////////////////////////
166extern void         _physical_write( unsigned long long paddr,
167                                     unsigned int       value );
168
169////////////////////////////////////////////////////////////////////////////
170// This function makes a physical read access to a 64 bits word in memory,
171// after a temporary DTLB de-activation and paddr extension.
172////////////////////////////////////////////////////////////////////////////
173extern unsigned long long _physical_read_ull(  unsigned long long paddr );
174
175////////////////////////////////////////////////////////////////////////////
176// This function makes a physical write access to a 64 bits word in memory,
177// after a temporary DTLB de-activation and paddr extension.
178////////////////////////////////////////////////////////////////////////////
179extern void               _physical_write_ull( unsigned long long paddr,
180                                               unsigned long long value );
181
182///////////////////////////////////////////////////////////////////////////////////
183// This function makes a memcpy from a source buffer to a destination buffer,
184// using physical addresses, after a temporary DTLB de-activation.
185// The source and destination buffers must be word aligned, and size must be
186// multiple of 4 bytes.
187///////////////////////////////////////////////////////////////////////////////////
188extern void         _physical_memcpy( unsigned long long dst_paddr,
189                                      unsigned long long src_paddr,
190                                      unsigned int       size );
191
192///////////////////////////////////////////////////////////////////////////////////
193// This function set a data value in all words of a destination buffer,
194// using physical addresses, after a temporary DTLB de-activation.
195// The destination buffer must be word aligned, and size multiple of 4 bytes.
196///////////////////////////////////////////////////////////////////////////////////
197extern void         _physical_memset( unsigned long long buf_paddr, 
198                                      unsigned int       size, 
199                                      unsigned int       data );
200
201///////////////////////////////////////////////////////////////////////////////////
202// This function is used by several drivers (_xxx_get_register() function).
203// If the MMU is not activated, the virtual address is extended using
204// X_IO and Y_IO to reach the cluster_io.
205///////////////////////////////////////////////////////////////////////////////////
206extern unsigned int _io_extended_read(  unsigned int* vaddr );
207
208///////////////////////////////////////////////////////////////////////////////////
209// This function is used by all drivers (_xxx_set_register() function)
210// If the MMU is not activated, the virtual address is extended using
211// X_IO and Y_IO to reach the cluster_io.
212///////////////////////////////////////////////////////////////////////////////////
213extern void         _io_extended_write( unsigned int* vaddr,
214                                        unsigned int  value );
215
216///////////////////////////////////////////////////////////////////////////////////
217//     Locks access functions
218///////////////////////////////////////////////////////////////////////////////////
219
220
221///////////////////////////////////////////////////////////////////////////////////
222// Takes a lock with a blocking ll/sc atomic access.
223// - When the cache coherence is granted by the hardware,
224//   the first read is a standard (cacheable) lw, as the local copy
225//   can be polled when the lock is already taken by another task, reducing
226//   trafic on the interconnect. When the lock is released by the owner task,
227//   the local copy is updated or invalidated by the coherence protocol.
228// - If there is no hardware cache coherence a random delay is introduced
229//   between two successive retry.
230///////////////////////////////////////////////////////////////////////////////////
231extern void         _get_lock(giet_lock_t* lock);
232
233///////////////////////////////////////////////////////////////////////////////////
234// Release a previouly taken lock.
235///////////////////////////////////////////////////////////////////////////////////
236extern void         _release_lock(giet_lock_t* lock);
237
238
239///////////////////////////////////////////////////////////////////////////////////
240//     TTY0 access functions
241///////////////////////////////////////////////////////////////////////////////////
242
243extern void         _puts( char*        string );
244extern void         _putx( unsigned int val );
245extern void         _putd( unsigned int val ); 
246extern void         _putl( unsigned long long val );
247
248extern void         _printf(char* format, ...); 
249
250extern void         _getc( char*        byte );       
251
252
253///////////////////////////////////////////////////////////////////////////////////
254//     Scheduler and task context access functions
255///////////////////////////////////////////////////////////////////////////////////
256
257
258///////////////////////////////////////////////////////////////////////////////////
259// Returns index of the currently running task from the processor scheduler.
260///////////////////////////////////////////////////////////////////////////////////
261extern unsigned int _get_current_task_id(void);
262
263////////////////////////////////////////////////////////////////////////////////////
264// This function returns the content of a context slot
265// for a task identified by the ltid argument (local task index),
266// and a processor identified by the (x,y,p) arguments.
267////////////////////////////////////////////////////////////////////////////////////
268extern unsigned int _get_task_slot( unsigned int x,
269                                    unsigned int y,
270                                    unsigned int p,
271                                    unsigned int ltid,
272                                    unsigned int slot );
273
274////////////////////////////////////////////////////////////////////////////////////
275// This function updates the content of a context slot
276// for any task identified by the ltid argument (local task index),
277// and a processor identified by the (x,y,p) arguments.
278////////////////////////////////////////////////////////////////////////////////////
279extern void         _set_task_slot( unsigned int x,
280                                    unsigned int y,
281                                    unsigned int p,
282                                    unsigned int ltid,
283                                    unsigned int slot,
284                                    unsigned int value );
285
286////////////////////////////////////////////////////////////////////////////////////
287// This function returns the content of a context slot for the running task.
288////////////////////////////////////////////////////////////////////////////////////
289extern unsigned int _get_context_slot( unsigned int slot );
290
291////////////////////////////////////////////////////////////////////////////////////
292// This function updates the content of a context slot for the running task.
293////////////////////////////////////////////////////////////////////////////////////
294extern void         _set_context_slot( unsigned int slot,
295                                       unsigned int value );
296
297///////////////////////////////////////////////////////////////////////////////////
298//     Mapping access functions
299///////////////////////////////////////////////////////////////////////////////////
300
301extern mapping_cluster_t *  _get_cluster_base(mapping_header_t* header);
302extern mapping_pseg_t *     _get_pseg_base(mapping_header_t* header);
303extern mapping_vspace_t *   _get_vspace_base(mapping_header_t* header);
304extern mapping_vseg_t *     _get_vseg_base(mapping_header_t* header);
305extern mapping_vobj_t *     _get_vobj_base(mapping_header_t* header);
306extern mapping_task_t *     _get_task_base(mapping_header_t* header);
307extern mapping_proc_t *     _get_proc_base(mapping_header_t* header);
308extern mapping_irq_t *      _get_irq_base(mapping_header_t* header);
309extern mapping_coproc_t *   _get_coproc_base(mapping_header_t* header);
310extern mapping_cp_port_t *  _get_cp_port_base(mapping_header_t* header);
311extern mapping_periph_t *   _get_periph_base(mapping_header_t* header);
312
313///////////////////////////////////////////////////////////////////////////////////
314//     Miscelaneous functions
315///////////////////////////////////////////////////////////////////////////////////
316
317extern void         _exit(void);
318
319extern void         _random_wait( unsigned int value );
320
321extern void         _break( char* str);
322
323extern unsigned int _strncmp(const char*  s1, 
324                             const char*  s2, 
325                             unsigned int n);
326
327extern char*        _strcpy( char*        dest,
328                             char*        source );
329
330extern void         _dcache_buf_invalidate( unsigned int buf_vbase, 
331                                            unsigned int buf_size );
332
333extern unsigned int _heap_info( unsigned int* vaddr,
334                                unsigned int* length,
335                                unsigned int  x,
336                                unsigned int  y );
337
338///////////////////////////////////////////////////////////////////////////////////
339//     Required by GCC
340///////////////////////////////////////////////////////////////////////////////////
341
342extern void* memcpy( void* _dst, 
343                     const void* _src, 
344                     unsigned int size );
345
346extern void* memset( void* dst, 
347                     int s, 
348                     unsigned int count );
349
350
351#endif
352
353// Local Variables:
354// tab-width: 4
355// c-basic-offset: 4
356// c-file-offsets:((innamespace . 0)(inline-open . 0))
357// indent-tabs-mode: nil
358// End:
359// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
360
Note: See TracBrowser for help on using the repository browser.