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
84  m_power.powerOnCore(info->coreId);
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 }
SunxiCpuConfig::IOBase
static const Address IOBase
Physical base memory address of CPU Configuration Module.
Definition: SunxiCpuConfig.h:47
CoreManager::m_cores
List< uint > m_cores
List of core ids found.
Definition: CoreManager.h:91
SunxiPowerManagement::Success
@ Success
Definition: SunxiPowerManagement.h:66
Memory::Writable
@ Writable
Definition: Memory.h:42
CoreManager::InvalidArgument
@ InvalidArgument
Definition: CoreManager.h:50
IO::map
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
Memory::User
@ User
Definition: Memory.h:44
ARMIO::write
void write(u32 reg, u32 data)
write to memory mapped I/O register
Definition: ARMIO.h:46
PAGESIZE
#define PAGESIZE
ARM uses 4K pages.
Definition: ARMConstant.h:97
SunxiPowerManagement::Result
Result
Result codes.
Definition: SunxiPowerManagement.h:64
SunxiCpuConfig::EntryAddr
@ EntryAddr
Reset Entry Address.
Definition: SunxiCpuConfig.h:75
Memory::Device
@ Device
Definition: Memory.h:48
SunxiCpuConfig::initialize
virtual Result initialize()
Perform initialization.
Definition: SunxiCpuConfig.cpp:21
SunxiCpuConfig::boot
virtual Result boot(CoreInfo *info)
Boot a processor.
Definition: SunxiCpuConfig.cpp:52
SunxiCpuConfig::m_io
Arch::IO m_io
Memory I/O object.
Definition: SunxiCpuConfig.h:118
ARMIO::unset
void unset(Address addr, u32 data)
Unset bits in memory mapped register.
Definition: ARMIO.h:122
Memory::Readable
@ Readable
Definition: Memory.h:41
Log.h
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
CoreInfo::coreId
uint coreId
Core identifier.
Definition: CoreInfo.h:66
SunxiCpuConfig::DbgExtern
@ DbgExtern
Debug External.
Definition: SunxiCpuConfig.h:76
IO::setBase
void setBase(const Address base)
Set memory I/O base offset.
Definition: IO.cpp:33
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
SunxiCpuConfig::NumberOfCores
static const Size NumberOfCores
Number of CPU processor cores is fixed.
Definition: SunxiCpuConfig.h:44
CoreInfo::kernelEntry
Address kernelEntry
Kernel entry point.
Definition: CoreInfo.h:72
List::append
void append(T t)
Insert an item at the end of the list.
Definition: List.h:139
SunxiCpuConfig.h
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
SunxiCpuConfig::Cpu3RstCtrl
@ Cpu3RstCtrl
CPU#3 Reset Control.
Definition: SunxiCpuConfig.h:64
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
SunxiCpuConfig::GenCtrl
@ GenCtrl
General Control.
Definition: SunxiCpuConfig.h:73
SunxiCpuConfig::Cpu2RstCtrl
@ Cpu2RstCtrl
CPU#2 Reset Control.
Definition: SunxiCpuConfig.h:61
CoreInfo
Per-Core information structure.
Definition: CoreInfo.h:60
IO::Success
@ Success
Definition: IO.h:44
CoreManager::IOError
@ IOError
Definition: CoreManager.h:48
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
CoreManager::Success
@ Success
Definition: CoreManager.h:47
SunxiCpuConfig::Cpu1RstCtrl
@ Cpu1RstCtrl
CPU#1 Reset Control.
Definition: SunxiCpuConfig.h:58
SunxiCpuConfig::Cpu0RstCtrl
@ Cpu0RstCtrl
CPU#0 Reset Control.
Definition: SunxiCpuConfig.h:55
ARMIO::set
void set(Address addr, u32 data)
Set bits in memory mapped register.
Definition: ARMIO.h:109
SunxiPowerManagement::powerOnCore
Result powerOnCore(const Size coreId)
Power on a processor.
Definition: SunxiPowerManagement.cpp:34
IO::getBase
Address getBase() const
Get memory I/O base offset.
Definition: IO.cpp:28
SunxiPowerManagement::initialize
Result initialize()
Perform initialization.
Definition: SunxiPowerManagement.cpp:20
SunxiCpuConfig::discover
virtual Result discover()
Discover processors.
Definition: SunxiCpuConfig.cpp:44
CoreManager::Result
Result
Result codes.
Definition: CoreManager.h:45
SunxiCpuConfig::m_power
SunxiPowerManagement m_power
Power Management module.
Definition: SunxiCpuConfig.h:121