OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [i386/] [arch/] [v2_0/] [include/] [hal_smp.h] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#ifndef CYGONCE_HAL_SMP_H
2
#define CYGONCE_HAL_SMP_H
3
 
4
//=============================================================================
5
//
6
//      hal_smp.h
7
//
8
//      SMP support
9
//
10
//=============================================================================
11
//####ECOSGPLCOPYRIGHTBEGIN####
12
// -------------------------------------------
13
// This file is part of eCos, the Embedded Configurable Operating System.
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23
// for more details.
24
//
25
// You should have received a copy of the GNU General Public License along
26
// with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28
//
29
// As a special exception, if other files instantiate templates or use macros
30
// or inline functions from this file, or you compile this file and link it
31
// with other works to produce a work based on this file, this file does not
32
// by itself cause the resulting work to be covered by the GNU General Public
33
// License. However the source code for this file must still be made available
34
// in accordance with section (3) of the GNU General Public License.
35
//
36
// This exception does not invalidate any other reasons why a work based on
37
// this file might be covered by the GNU General Public License.
38
//
39
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40
// at http://sources.redhat.com/ecos/ecos-license/
41
// -------------------------------------------
42
//####ECOSGPLCOPYRIGHTEND####
43
//=============================================================================
44
//#####DESCRIPTIONBEGIN####
45
//
46
// Author(s):   nickg
47
// Contributors:  nickg
48
// Date:        2001-08-03
49
// Purpose:     Define SMP support abstractions
50
// Usage:       #include <cyg/hal/hal_smp.h>
51
 
52
//              
53
//####DESCRIPTIONEND####
54
//
55
//=============================================================================
56
 
57
#include <pkgconf/hal.h>
58
 
59
#ifdef CYGPKG_HAL_SMP_SUPPORT
60
 
61
#include <cyg/infra/cyg_type.h>
62
 
63
#include <cyg/hal/hal_arch.h>
64
 
65
//=============================================================================
66
 
67
/*------------------------------------------------------------------------*/
68
// APIC definitions
69
 
70
#define HAL_APIC_ID         0x0020
71
#define HAL_APIC_VER        0x0030
72
#define HAL_APIC_TPR        0x0080
73
#define HAL_APIC_EOI        0x00b0
74
#define HAL_APIC_LDR        0x00d0
75
#define HAL_APIC_DFR        0x00e0
76
#define HAL_APIC_SPIV       0x00f0
77
 
78
#define HAL_APIC_ISR        0x0100
79
#define HAL_APIC_TMR        0x0180
80
#define HAL_APIC_IRR        0x0200
81
 
82
#define HAL_APIC_ICR_LO     0x0300
83
#define HAL_APIC_ICR_HI     0x0310
84
 
85
#define HAL_APIC_LVT_TIMER  0x0320
86
#define HAL_APIC_LVT_PC     0x0340
87
#define HAL_APIC_LVT_INT0   0x0350
88
#define HAL_APIC_LVT_INT1   0x0360
89
#define HAL_APIC_LVT_ERROR  0x0370
90
#define      HAL_APIC_LVT_MASK      0x00010000
91
 
92
/*------------------------------------------------------------------------*/
93
// APIC access macros
94
 
95
#define HAL_APIC_READ( __addr, __val )                                  \
96
{                                                                       \
97
    HAL_READMEM_UINT32(cyg_hal_smp_local_apic+(__addr), __val );        \
98
}
99
 
100
#define HAL_APIC_WRITE( __addr, __val )                                 \
101
{                                                                       \
102
    HAL_WRITEMEM_UINT32(cyg_hal_smp_local_apic+(__addr), __val );       \
103
}
104
 
105
/*------------------------------------------------------------------------*/
106
// I/O APIC definitions
107
 
108
#define HAL_IOAPIC_REGSEL           0x0000
109
#define HAL_IOAPIC_REGWIN           0x0010
110
 
111
#define HAL_IOAPIC_REG_APICID       0x0000
112
#define HAL_IOAPIC_REG_APICVER      0x0001
113
#define HAL_IOAPIC_REG_APICARB      0x0002
114
#define HAL_IOAPIC_REG_REDTBL       0x0010
115
#define HAL_IOAPIC_REG_REDIR_LO(n)  (HAL_IOAPIC_REG_REDTBL+((n)*2))
116
#define HAL_IOAPIC_REG_REDIR_HI(n)  (HAL_IOAPIC_REG_REDTBL+((n)*2)+1)
117
 
118
/*------------------------------------------------------------------------*/
119
// I/O APIC access macros
120
 
121
#define HAL_IOAPIC_READ( __reg, __val )                                 \
122
{                                                                       \
123
    HAL_WRITEMEM_UINT32( cyg_hal_smp_io_apic+HAL_IOAPIC_REGSEL, __reg );    \
124
    HAL_READMEM_UINT32( cyg_hal_smp_io_apic+HAL_IOAPIC_REGWIN, __val );     \
125
}
126
 
127
#define HAL_IOAPIC_WRITE( __reg, __val )                                \
128
{                                                                       \
129
    HAL_WRITEMEM_UINT32( cyg_hal_smp_io_apic+HAL_IOAPIC_REGSEL, __reg );    \
130
    HAL_WRITEMEM_UINT32( cyg_hal_smp_io_apic+HAL_IOAPIC_REGWIN, __val );    \
131
}
132
 
133
//-----------------------------------------------------------------------------
134
// SMP configuration determined from platform during initialization
135
 
136
__externC CYG_ADDRESS cyg_hal_smp_local_apic;
137
 
138
__externC CYG_ADDRESS cyg_hal_smp_io_apic;
139
 
140
__externC CYG_WORD32 cyg_hal_smp_cpu_count;
141
 
142
__externC CYG_BYTE cyg_hal_smp_cpu_flags[CYGPKG_HAL_SMP_CPU_MAX];
143
 
144
__externC CYG_BYTE cyg_hal_isa_bus_id;
145
__externC CYG_BYTE cyg_hal_isa_bus_irq[16];
146
 
147
__externC CYG_BYTE cyg_hal_pci_bus_id;
148
__externC CYG_BYTE cyg_hal_pci_bus_irq[4];
149
 
150
//-----------------------------------------------------------------------------
151
// CPU numbering macros
152
 
153
#define HAL_SMP_CPU_TYPE        cyg_uint32
154
 
155
#define HAL_SMP_CPU_MAX         CYGPKG_HAL_SMP_CPU_MAX
156
 
157
#define HAL_SMP_CPU_COUNT()     cyg_hal_smp_cpu_count
158
 
159
#define HAL_SMP_CPU_THIS()                      \
160
({                                              \
161
    HAL_SMP_CPU_TYPE __id;                      \
162
    HAL_APIC_READ( HAL_APIC_ID, __id );         \
163
    (__id>>24)&0xF;                             \
164
})
165
 
166
#define HAL_SMP_CPU_NONE        (CYGPKG_HAL_SMP_CPU_MAX+1)
167
 
168
//-----------------------------------------------------------------------------
169
// CPU startup
170
 
171
__externC void cyg_hal_cpu_release(HAL_SMP_CPU_TYPE cpu);
172
 
173
#define HAL_SMP_CPU_START( __cpu ) cyg_hal_cpu_release( __cpu );
174
 
175
#define HAL_SMP_CPU_RESCHEDULE_INTERRUPT( __cpu, __wait ) \
176
        cyg_hal_cpu_message( __cpu, HAL_SMP_MESSAGE_RESCHEDULE, 0, __wait);
177
 
178
#define HAL_SMP_CPU_TIMESLICE_INTERRUPT( __cpu, __wait ) \
179
        cyg_hal_cpu_message( __cpu, HAL_SMP_MESSAGE_TIMESLICE, 0, __wait);
180
 
181
//-----------------------------------------------------------------------------
182
// CPU message exchange
183
 
184
__externC void cyg_hal_cpu_message( HAL_SMP_CPU_TYPE cpu,
185
                                    CYG_WORD32 msg,
186
                                    CYG_WORD32 arg,
187
                                    CYG_WORD32 wait);
188
 
189
#define HAL_SMP_MESSAGE_TYPE            0xF0000000
190
#define HAL_SMP_MESSAGE_ARG             (~HAL_SMP_MESSAGE_TYPE)
191
 
192
#define HAL_SMP_MESSAGE_RESCHEDULE      0x10000000
193
#define HAL_SMP_MESSAGE_MASK            0x20000000
194
#define HAL_SMP_MESSAGE_UNMASK          0x30000000
195
#define HAL_SMP_MESSAGE_REVECTOR        0x40000000
196
#define HAL_SMP_MESSAGE_TIMESLICE       0x50000000
197
 
198
//-----------------------------------------------------------------------------
199
// Test-and-set support
200
// These macros provide test-and-set support for the least significant bit
201
// in a word. 
202
 
203
#define HAL_TAS_TYPE    volatile CYG_WORD32
204
 
205
#define HAL_TAS_SET( _tas_, _oldb_ )                    \
206
CYG_MACRO_START                                         \
207
{                                                       \
208
    register CYG_WORD32 __old;                          \
209
    __asm__ volatile (                                  \
210
                       "lock btsl   $0,%1\n"            \
211
                       "sbbl   %0,%0\n"                 \
212
                       : "=r" (__old), "=m" (_tas_)     \
213
                       :                                \
214
                       : "memory"                       \
215
                     );                                 \
216
    _oldb_ = ( __old & 1 ) != 0;                        \
217
}                                                       \
218
CYG_MACRO_END
219
 
220
#define HAL_TAS_CLEAR( _tas_, _oldb_ )                  \
221
CYG_MACRO_START                                         \
222
{                                                       \
223
    register CYG_WORD32 __old;                          \
224
    __asm__ volatile (                                  \
225
                       "lock btrl   $0,%1\n"            \
226
                       "sbbl   %0,%0\n"                 \
227
                       : "=r" (__old), "=m" (_tas_)     \
228
                       :                                \
229
                       : "memory"                       \
230
                     );                                 \
231
    _oldb_ = ( __old & 1 ) != 0;                        \
232
}                                                       \
233
CYG_MACRO_END
234
 
235
//-----------------------------------------------------------------------------
236
// Spinlock support.
237
// Built on top of test-and-set code.
238
 
239
#define HAL_SPINLOCK_TYPE       volatile CYG_WORD32
240
 
241
#define HAL_SPINLOCK_INIT_CLEAR 0
242
 
243
#define HAL_SPINLOCK_INIT_SET   1
244
 
245
#define HAL_SPINLOCK_SPIN( _lock_ )             \
246
CYG_MACRO_START                                 \
247
{                                               \
248
    cyg_bool _val_;                             \
249
    do                                          \
250
    {                                           \
251
        HAL_TAS_SET( _lock_, _val_ );           \
252
    } while( _val_ );                           \
253
}                                               \
254
CYG_MACRO_END
255
 
256
#define HAL_SPINLOCK_CLEAR( _lock_ )            \
257
CYG_MACRO_START                                 \
258
{                                               \
259
    cyg_bool _val_;                             \
260
    HAL_TAS_CLEAR( _lock_ , _val_ );            \
261
}                                               \
262
CYG_MACRO_END
263
 
264
#define HAL_SPINLOCK_TRY( _lock_, _val_ )       \
265
    HAL_TAS_SET( _lock_, _val_ );               \
266
    (_val_) = (((_val_) & 1) == 0)
267
 
268
#define HAL_SPINLOCK_TEST( _lock_, _val_ )      \
269
    (_val_) = (((_lock_) & 1) != 0)
270
 
271
//-----------------------------------------------------------------------------
272
// Diagnostic output serialization
273
 
274
__externC HAL_SPINLOCK_TYPE cyg_hal_smp_diag_lock;
275
 
276
#define CYG_HAL_DIAG_LOCK_DATA_DEFN \
277
        HAL_SPINLOCK_TYPE cyg_hal_smp_diag_lock = HAL_SPINLOCK_INIT_CLEAR
278
 
279
#define CYG_HAL_DIAG_LOCK() HAL_SPINLOCK_SPIN( cyg_hal_smp_diag_lock )
280
 
281
#define CYG_HAL_DIAG_UNLOCK() HAL_SPINLOCK_CLEAR( cyg_hal_smp_diag_lock )
282
 
283
//-----------------------------------------------------------------------------
284
// Some extra definitions
285
 
286
__externC HAL_SPINLOCK_TYPE cyg_hal_ioapic_lock;
287
 
288
//-----------------------------------------------------------------------------
289
 
290
#endif // CYGPKG_HAL_SMP_SUPPORT
291
 
292
//-----------------------------------------------------------------------------
293
#endif // CYGONCE_HAL_SMP_H
294
// End of hal_smp.h

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.