genode/repos/base-hw/src/core/include/platform.h

151 lines
4.1 KiB
C
Raw Normal View History

/*
* \brief Platform interface
* \author Martin Stein
* \author Stefan Kalkowski
* \date 2011-12-21
*/
/*
2013-01-10 21:44:47 +01:00
* Copyright (C) 2011-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _CORE__INCLUDE__PLATFORM_H_
#define _CORE__INCLUDE__PLATFORM_H_
/* Genode includes */
#include <base/synced_allocator.h>
#include <base/allocator_avl.h>
#include <irq_session/irq_session.h>
/* base-hw includes */
#include <kernel/configuration.h>
#include <kernel/core_interface.h>
/* core includes */
#include <bootinfo.h>
#include <translation_table_allocator_tpl.h>
#include <platform_generic.h>
#include <core_region_map.h>
#include <core_mem_alloc.h>
#include <memory_region.h>
namespace Genode {
/**
* Manages all platform ressources
*/
class Platform : public Platform_generic
{
private:
Core_mem_allocator _core_mem_alloc; /* core-accessible memory */
Phys_allocator _io_mem_alloc; /* MMIO allocator */
Phys_allocator _io_port_alloc; /* I/O port allocator */
Phys_allocator _irq_alloc; /* IRQ allocator */
Rom_fs _rom_fs; /* ROM file system */
static Genode::Bootinfo const & _bootinfo();
static Genode::Memory_region_array const & _core_virt_regions();
/**
* Initialize I/O port allocator
*/
void _init_io_port_alloc();
/**
* Initialize IO memory allocator
*
* Use byte granularity for MMIO regions because on some platforms,
* devices driven by core share a physical page with devices
* driven outside of core. Using byte granularity allows handing
* out the MMIO page to trusted user-level device drivers.
*/
void _init_io_mem_alloc();
/**
* Perform additional platform-specific initialization.
*/
void _init_additional();
public:
Platform();
static addr_t mmio_to_virt(addr_t mmio);
/**
* Return platform IRQ-number for user IRQ-number 'user_irq'
*/
static long irq(long const user_irq);
/**
* Setup mode of an IRQ to specified trigger mode and polarity
*
* \param irq_number ID of targeted interrupt
* \param trigger new interrupt trigger mode
* \param polarity new interrupt polarity setting
*/
static void setup_irq_mode(unsigned irq_number, unsigned trigger,
unsigned polarity);
/**
* Get MSI-related parameters from device PCI config space
*
* \param mmconf PCI config space address of device
* \param address MSI address register value to use
* \param data MSI data register value to use
* \param irq_number IRQ to use
*
* \return true if the device is MSI-capable, false if not
*/
static bool get_msi_params(const addr_t mmconf,
addr_t &address, addr_t &data,
unsigned &irq_number);
static addr_t core_phys_addr(addr_t virt);
static Translation_table * core_translation_table();
static Translation_table_allocator * core_translation_table_allocator();
/********************************
** Platform_generic interface **
********************************/
Range_allocator * core_mem_alloc() {
return &_core_mem_alloc; }
Range_allocator * ram_alloc() {
return _core_mem_alloc.phys_alloc(); }
Range_allocator * region_alloc() {
return _core_mem_alloc.virt_alloc(); }
Range_allocator * io_mem_alloc() { return &_io_mem_alloc; }
Range_allocator * io_port_alloc() { return &_io_port_alloc; }
Range_allocator * irq_alloc() { return &_irq_alloc; }
addr_t vm_start() const { return VIRT_ADDR_SPACE_START; }
size_t vm_size() const { return VIRT_ADDR_SPACE_SIZE; }
Rom_fs *rom_fs() { return &_rom_fs; }
inline void wait_for_exit() {
hw: clean up scheduling-readiness syscalls This cleans up the syscalls that are mainly used to control the scheduling readiness of a thread. The different use cases and requirements were somehow mixed together in the previous interface. The new syscall set is: 1) pause_thread and resume_thread They don't affect the state of the thread (IPC, signalling, etc.) but merely decide wether the thread is allowed for scheduling or not, the so-called pause state. The pause state is orthogonal to the thread state and masks it when it comes to scheduling. In contrast to the stopped state, which is described in "stop_thread and restart_thread", the thread state and the UTCB content of a thread may change while in the paused state. However, the register state of a thread doesn't change while paused. The "pause" and "resume" syscalls are both core-restricted and may target any thread. They are used as back end for the CPU session calls "pause" and "resume". The "pause/resume" feature is made for applications like the GDB monitor that transparently want to stop and continue the execution of a thread no matter what state the thread is in. 2) stop_thread and restart_thread The stop syscall can only be used on a thread in the non-blocking ("active") thread state. The thread then switches to the "stopped" thread state in wich it explicitely waits for a restart. The restart syscall can only be used on a thread in the "stopped" or the "active" thread state. The thread then switches back to the "active" thread state and the syscall returns whether the thread was stopped. Both syscalls are not core-restricted. "Stop" always targets the calling thread while "restart" may target any thread in the same PD as the caller. Thread state and UTCB content of a thread don't change while in the stopped state. The "stop/restart" feature is used when an active thread wants to wait for an event that is not known to the kernel. Actually the syscalls are used when waiting for locks and on thread exit. 3) cancel_thread_blocking Does cleanly cancel a cancelable blocking thread state (IPC, signalling, stopped). The thread whose blocking was cancelled goes back to the "active" thread state. It may receive a syscall return value that reflects the cancellation. This syscall doesn't affect the pause state of the thread which means that it may still not get scheduled. The syscall is core-restricted and may target any thread. 4) yield_thread Does its best that a thread is scheduled as few as possible in the current scheduling super-period without touching the thread or pause state. In the next superperiod, however, the thread is scheduled "normal" again. The syscall is not core-restricted and always targets the caller. Fixes #2104
2016-09-15 17:23:06 +02:00
while (1) { Kernel::stop_thread(); } };
2013-09-18 13:11:27 +02:00
bool supports_direct_unmap() const { return 1; }
Affinity::Space affinity_space() const {
return Affinity::Space(NR_OF_CPUS); }
};
}
#endif /* _CORE__INCLUDE__PLATFORM_H_ */