FreeNOS
SunxiCpuConfig.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <Log.h>
19#include "SunxiCpuConfig.h"
20
22{
23 // First map our own I/O memory
24 if (m_io.map(IOBase & ~0xfff, PAGESIZE,
27 {
28 ERROR("failed to map I/O memory");
29 return IOError;
30 }
31 m_io.setBase(m_io.getBase() + (IOBase & 0xfff));
32
33 // Also initialize the power management module
36 {
37 ERROR("failed to initialize power management module: " << (uint)r);
38 return IOError;
39 }
40
41 return Success;
42}
43
45{
46 for (Size i = 0; i < NumberOfCores; i++)
47 m_cores.append(i);
48
49 return Success;
50}
51
53{
54 u32 reg = 0;
55
56 DEBUG("resetting core" << info->coreId <<
57 " at " << (void*) info->kernelEntry);
58
59 switch (info->coreId)
60 {
61 case 0: reg = Cpu0RstCtrl; break;
62 case 1: reg = Cpu1RstCtrl; break;
63 case 2: reg = Cpu2RstCtrl; break;
64 case 3: reg = Cpu3RstCtrl; break;
65 default: {
66 ERROR("coreId " << info->coreId << " is invalid");
67 return InvalidArgument;
68 }
69 }
70
71 // Set initial program counter for the core
73
74 // Assert reset
75 m_io.write(reg, 0);
76
77 // Invalidate L1 cache for target core
78 m_io.unset(GenCtrl, 1 << info->coreId);
79
80 // Disable the debug interface
81 m_io.unset(DbgExtern, 1 << info->coreId);
82
83 // Active power for the core
85
86 // De-assert reset
87 m_io.write(reg, (1 << 0) | (1 << 1));
88
89 // Re-enable the debug interface
90 m_io.set(DbgExtern, 1 << info->coreId);
91 return Success;
92}
void set(Address addr, u32 data)
Set bits in memory mapped register.
Definition ARMIO.h:109
void unset(Address addr, u32 data)
Unset bits in memory mapped register.
Definition ARMIO.h:122
void write(u32 reg, u32 data)
write to memory mapped I/O register
Definition ARMIO.h:46
List< uint > m_cores
List of core ids found.
Definition CoreManager.h:91
Result
Result codes.
Definition CoreManager.h:46
void setBase(const Address base)
Set memory I/O base offset.
Definition IO.cpp:33
Result map(Address phys, Size size=4096, Memory::Access access=Memory::Readable|Memory::Writable|Memory::User)
Map I/O address space.
Definition IO.cpp:38
Address getBase() const
Get memory I/O base offset.
Definition IO.cpp:28
@ Success
Definition IO.h:44
void append(T t)
Insert an item at the end of the list.
Definition List.h:139
static const Address IOBase
Physical base memory address of CPU Configuration Module.
virtual Result discover()
Discover processors.
virtual Result initialize()
Perform initialization.
Arch::IO m_io
Memory I/O object.
virtual Result boot(CoreInfo *info)
Boot a processor.
SunxiPowerManagement m_power
Power Management module.
@ Cpu1RstCtrl
CPU#1 Reset Control.
@ Cpu2RstCtrl
CPU#2 Reset Control.
@ GenCtrl
General Control.
@ Cpu0RstCtrl
CPU#0 Reset Control.
@ Cpu3RstCtrl
CPU#3 Reset Control.
@ DbgExtern
Debug External.
@ EntryAddr
Reset Entry Address.
static const Size NumberOfCores
Number of CPU processor cores is fixed.
Result powerOnCore(const Size coreId)
Power on a processor.
Result initialize()
Perform initialization.
#define PAGESIZE
ARM uses 4K pages.
Definition ARMConstant.h:97
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
#define ERROR(msg)
Output an error message.
Definition Log.h:61
unsigned int uint
Unsigned integer number.
Definition Types.h:44
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89
@ User
Definition Memory.h:44
@ Readable
Definition Memory.h:41
@ Device
Definition Memory.h:48
@ Writable
Definition Memory.h:42
Per-Core information structure.
Definition CoreInfo.h:61
uint coreId
Core identifier.
Definition CoreInfo.h:66
Address kernelEntry
Kernel entry point.
Definition CoreInfo.h:72