1 //==========================================================================
5 // HAL implementation miscellaneous functions
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2002 Gary Thomas
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //==========================================================================
42 //#####DESCRIPTIONBEGIN####
45 // Contributors: jskov
47 // Purpose: HAL miscellaneous functions
48 // Description: This file contains miscellaneous functions provided by the
51 //####DESCRIPTIONEND####
53 //==========================================================================
55 #include <pkgconf/hal.h>
57 #define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
58 #include <cyg/hal/ppc_regs.h>
59 #include <cyg/infra/cyg_type.h>
61 #include <cyg/hal/hal_mem.h>
63 //--------------------------------------------------------------------------
64 void hal_variant_init(void)
69 //--------------------------------------------------------------------------
70 // Variant specific idle thread action.
72 hal_variant_idle_thread_action( cyg_uint32 count )
74 // Let architecture idle thread action run
78 //---------------------------------------------------------------------------
79 // Use MMU resources to map memory regions.
80 // Takes and returns an int used to ID the MMU resource to use. This ID
81 // is increased as resources are used and should be used for subsequent
84 cyg_hal_map_memory (int id,CYG_ADDRESS virt, CYG_ADDRESS phys,
85 cyg_int32 size, cyg_uint8 flags)
87 // Use BATs to map the memory.
88 cyg_uint32 ubat, lbat;
90 ubat = (virt & UBAT_BEPIMASK) | UBAT_VS | UBAT_VP;
91 lbat = (phys & LBAT_BRPNMASK);
92 if (flags & CYGARC_MEMDESC_CI)
94 if (flags & CYGARC_MEMDESC_GUARDED)
98 lbat |= LBAT_PP_RW; // Always enable for Read-Write
100 if (flags & CYGARC_MEMDESC_RO) // Memory is Read Only
102 if (flags & CYGARC_MEMDESC_RW) // Memory is RW
105 // There are 4 BATs, size is programmable.
106 while (id < 4 && size > 0) {
107 cyg_uint32 blk_size = 128*1024;
109 while (blk_size < 256*1024*1024 && blk_size < size) {
113 ubat = (ubat & ~UBAT_BLMASK) | (bl << 2);
117 CYGARC_MTSPR (IBAT0U, ubat);
118 CYGARC_MTSPR (IBAT0L, lbat);
119 CYGARC_MTSPR (DBAT0U, ubat);
120 CYGARC_MTSPR (DBAT0L, lbat);
123 CYGARC_MTSPR (IBAT1U, ubat);
124 CYGARC_MTSPR (IBAT1L, lbat);
125 CYGARC_MTSPR (DBAT1U, ubat);
126 CYGARC_MTSPR (DBAT1L, lbat);
129 CYGARC_MTSPR (IBAT2U, ubat);
130 CYGARC_MTSPR (IBAT2L, lbat);
131 CYGARC_MTSPR (DBAT2U, ubat);
132 CYGARC_MTSPR (DBAT2L, lbat);
135 CYGARC_MTSPR (IBAT3U, ubat);
136 CYGARC_MTSPR (IBAT3L, lbat);
137 CYGARC_MTSPR (DBAT3U, ubat);
138 CYGARC_MTSPR (DBAT3L, lbat);
150 // Initialize MMU to a sane (NOP) state.
152 cyg_hal_clear_MMU (void)
154 cyg_uint32 ubat, lbat;
156 // Initialize BATs with 0 -- VS&VP are unset, making all matches fail
160 CYGARC_MTSPR (IBAT0U, ubat);
161 CYGARC_MTSPR (IBAT0L, lbat);
162 CYGARC_MTSPR (DBAT0U, ubat);
163 CYGARC_MTSPR (DBAT0L, lbat);
164 CYGARC_MTSPR (IBAT1U, ubat);
165 CYGARC_MTSPR (IBAT1L, lbat);
166 CYGARC_MTSPR (DBAT1U, ubat);
167 CYGARC_MTSPR (DBAT1L, lbat);
168 CYGARC_MTSPR (IBAT2U, ubat);
169 CYGARC_MTSPR (IBAT2L, lbat);
170 CYGARC_MTSPR (DBAT2U, ubat);
171 CYGARC_MTSPR (DBAT2L, lbat);
172 CYGARC_MTSPR (IBAT3U, ubat);
173 CYGARC_MTSPR (IBAT3L, lbat);
174 CYGARC_MTSPR (DBAT3U, ubat);
175 CYGARC_MTSPR (DBAT3L, lbat);
178 //--------------------------------------------------------------------------