FreeNOS
SunxiPowerManagement.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 "SunxiPowerManagement.h"
19 
21 {
22  if (m_io.map(IOBase & ~0xfff, PAGESIZE,
25  {
26  ERROR("failed to map I/O memory");
27  return IOError;
28  }
29 
30  m_io.setBase(m_io.getBase() + (IOBase & 0xfff));
31  return Success;
32 }
33 
35 {
36  if (coreId > NumberOfCores)
37  {
38  ERROR("invalid coreId " << coreId);
39  return InvalidArgument;
40  }
41 
42  // Open up the power clamp for this core
43  for (u32 val = 0x1ff; val != 0; val >>= 1)
44  {
45  m_io.write(CpuPowerClamp + (coreId * sizeof(u32)), val);
46  }
47 
48  // Now enable the power for the core
50  return Success;
51 }
SunxiPowerManagement::Success
@ Success
Definition: SunxiPowerManagement.h:66
Memory::Writable
@ Writable
Definition: Memory.h:42
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
SunxiPowerManagement::NumberOfCores
static const Size NumberOfCores
Total number of cores supported.
Definition: SunxiPowerManagement.h:46
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
Memory::Device
@ Device
Definition: Memory.h:48
SunxiPowerManagement::IOBase
static const Address IOBase
Physical base memory address of the PRCM module.
Definition: SunxiPowerManagement.h:43
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
IO::setBase
void setBase(const Address base)
Set memory I/O base offset.
Definition: IO.cpp:33
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
SunxiPowerManagement::InvalidArgument
@ InvalidArgument
Definition: SunxiPowerManagement.h:68
SunxiPowerManagement::CpuPowerClamp
@ CpuPowerClamp
Definition: SunxiPowerManagement.h:56
IO::Success
@ Success
Definition: IO.h:44
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
SunxiPowerManagement::m_io
Arch::IO m_io
Memory I/O object.
Definition: SunxiPowerManagement.h:90
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
SunxiPowerManagement.h
coreId
u8 coreId
Definition: IntelACPI.h:64
SunxiPowerManagement::CpuPowerOff
@ CpuPowerOff
Definition: SunxiPowerManagement.h:55
SunxiPowerManagement::IOError
@ IOError
Definition: SunxiPowerManagement.h:67