mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-22 00:41:55 +00:00
base: introduce caching attributes (fix #1184)
On ARM it's relevant to not only distinguish between ordinary cached memory and write-combined one, but also having non-cached memory too. To insert the appropriated page table entries e.g.: in the base-hw kernel, we need to preserve the information about the kind of memory from allocation until the pager resolves a page fault. Therefore, this commit introduces a new Cache_attribute type, and replaces the write_combined boolean with the new type where necessary.
This commit is contained in:
committed by
Norman Feske
parent
9580954d81
commit
786fe805da
@ -54,7 +54,7 @@ class Genode::Slab_backend_alloc : public Genode::Allocator,
|
||||
};
|
||||
|
||||
addr_t _base; /* virt. base address */
|
||||
bool _cached; /* non-/cached RAM */
|
||||
Cache_attribute _cached; /* non-/cached RAM */
|
||||
Ram_dataspace_capability _ds_cap[ELEMENTS]; /* dataspaces to put in VM */
|
||||
addr_t _ds_phys[ELEMENTS]; /* physical bases of dataspaces */
|
||||
int _index; /* current index in ds_cap */
|
||||
@ -86,7 +86,7 @@ class Genode::Slab_backend_alloc : public Genode::Allocator,
|
||||
|
||||
public:
|
||||
|
||||
Slab_backend_alloc(bool cached)
|
||||
Slab_backend_alloc(Cache_attribute cached)
|
||||
: Rm_connection(0, VM_SIZE), _cached(cached), _index(0),
|
||||
_range(env()->heap())
|
||||
{
|
||||
@ -220,7 +220,7 @@ class Malloc
|
||||
|
||||
public:
|
||||
|
||||
Malloc(Slab_backend_alloc *alloc, bool cached)
|
||||
Malloc(Slab_backend_alloc *alloc, Genode::Cache_attribute cached)
|
||||
: _back_allocator(alloc), _cached(cached), _start(alloc->start()),
|
||||
_end(alloc->end())
|
||||
{
|
||||
@ -312,8 +312,8 @@ class Malloc
|
||||
*/
|
||||
static Malloc *mem()
|
||||
{
|
||||
static Slab_backend_alloc _b(true);
|
||||
static Malloc _m(&_b, true);
|
||||
static Slab_backend_alloc _b(Genode::CACHED);
|
||||
static Malloc _m(&_b, Genode::CACHED);
|
||||
return &_m;
|
||||
}
|
||||
};
|
||||
|
@ -14,13 +14,17 @@
|
||||
#ifndef _ARM__PLATFORM__LX_MEM_
|
||||
#define _ARM__PLATFORM__LX_MEM_
|
||||
|
||||
#include <base/cache.h>
|
||||
|
||||
class Backend_memory {
|
||||
|
||||
public:
|
||||
|
||||
static Genode::Ram_dataspace_capability alloc(Genode::addr_t size,
|
||||
bool cached) {
|
||||
return Genode::env()->ram_session()->alloc(size, cached); }
|
||||
Genode::Cache_attribute c)
|
||||
{
|
||||
return Genode::env()->ram_session()->alloc(size, c);
|
||||
}
|
||||
|
||||
static void free(Genode::Ram_dataspace_capability cap) {
|
||||
return Genode::env()->ram_session()->free(cap); }
|
||||
|
@ -291,7 +291,7 @@ namespace Nic {
|
||||
/**
|
||||
* Root component, handling new session requests
|
||||
*/
|
||||
class Root : public Packet_root<Root_component, Session_component, true>
|
||||
class Root : public Packet_root<Root_component, Session_component, CACHED>
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -74,7 +74,8 @@ class Packet_session_component : public RPC
|
||||
/**
|
||||
* Root component, handling new session requests
|
||||
*/
|
||||
template <typename ROOT_COMPONENT, typename SESSION_COMPONENT, bool CACHED>
|
||||
template <typename ROOT_COMPONENT, typename SESSION_COMPONENT,
|
||||
Genode::Cache_attribute CACHEABILITY>
|
||||
class Packet_root : public ROOT_COMPONENT
|
||||
{
|
||||
private:
|
||||
@ -116,8 +117,8 @@ class Packet_session_component : public RPC
|
||||
}
|
||||
|
||||
return new (ROOT_COMPONENT::md_alloc())
|
||||
SESSION_COMPONENT(Backend_memory::alloc(tx_buf_size, CACHED),
|
||||
Backend_memory::alloc(rx_buf_size, CACHED),
|
||||
SESSION_COMPONENT(Backend_memory::alloc(tx_buf_size, CACHEABILITY),
|
||||
Backend_memory::alloc(rx_buf_size, CACHEABILITY),
|
||||
_ep, _device);
|
||||
}
|
||||
|
||||
|
@ -14,12 +14,14 @@
|
||||
#ifndef _X86__PLATFORM__LX_MEM_
|
||||
#define _X86__PLATFORM__LX_MEM_
|
||||
|
||||
#include <base/cache.h>
|
||||
|
||||
class Backend_memory {
|
||||
|
||||
public:
|
||||
|
||||
static Genode::Ram_dataspace_capability alloc(Genode::addr_t size,
|
||||
bool cached);
|
||||
Genode::Cache_attribute);
|
||||
|
||||
static void free(Genode::Ram_dataspace_capability cap);
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ class Genode::Slab_backend_alloc : public Genode::Allocator,
|
||||
};
|
||||
|
||||
addr_t _base; /* virt. base address */
|
||||
bool _cached; /* non-/cached RAM */
|
||||
Genode::Cache_attribute _cached; /* non-/cached RAM */
|
||||
Ram_dataspace_capability _ds_cap[ELEMENTS]; /* dataspaces to put in VM */
|
||||
addr_t _ds_phys[ELEMENTS]; /* physical bases of dataspaces */
|
||||
int _index; /* current index in ds_cap */
|
||||
@ -88,7 +88,7 @@ class Genode::Slab_backend_alloc : public Genode::Allocator,
|
||||
|
||||
public:
|
||||
|
||||
Slab_backend_alloc(bool cached)
|
||||
Slab_backend_alloc(Genode::Cache_attribute cached)
|
||||
: Rm_connection(0, VM_SIZE), _cached(cached), _index(0),
|
||||
_range(env()->heap())
|
||||
{
|
||||
@ -206,11 +206,11 @@ class Malloc
|
||||
typedef Genode::Slab_alloc Slab_alloc;
|
||||
typedef Genode::Slab_backend_alloc Slab_backend_alloc;
|
||||
|
||||
Slab_backend_alloc *_back_allocator;
|
||||
Slab_alloc *_allocator[NUM_SLABS];
|
||||
bool _cached; /* cached or un-cached memory */
|
||||
addr_t _start; /* VM region of this allocator */
|
||||
addr_t _end;
|
||||
Slab_backend_alloc *_back_allocator;
|
||||
Slab_alloc *_allocator[NUM_SLABS];
|
||||
Genode::Cache_attribute _cached; /* cached or un-cached memory */
|
||||
addr_t _start; /* VM region of this allocator */
|
||||
addr_t _end;
|
||||
|
||||
/**
|
||||
* Set 'value' at 'addr'
|
||||
@ -240,7 +240,7 @@ class Malloc
|
||||
|
||||
public:
|
||||
|
||||
Malloc(Slab_backend_alloc *alloc, bool cached)
|
||||
Malloc(Slab_backend_alloc *alloc, Genode::Cache_attribute cached)
|
||||
: _back_allocator(alloc), _cached(cached), _start(alloc->start()),
|
||||
_end(alloc->end())
|
||||
{
|
||||
@ -326,8 +326,8 @@ class Malloc
|
||||
*/
|
||||
static Malloc *mem()
|
||||
{
|
||||
static Slab_backend_alloc _b(true);
|
||||
static Malloc _m(&_b, true);
|
||||
static Slab_backend_alloc _b(Genode::CACHED);
|
||||
static Malloc _m(&_b, Genode::CACHED);
|
||||
return &_m;
|
||||
}
|
||||
|
||||
@ -336,8 +336,8 @@ class Malloc
|
||||
*/
|
||||
static Malloc *dma()
|
||||
{
|
||||
static Slab_backend_alloc _b(false);
|
||||
static Malloc _m(&_b, false);
|
||||
static Slab_backend_alloc _b(Genode::UNCACHED);
|
||||
static Malloc _m(&_b, Genode::UNCACHED);
|
||||
return &_m;
|
||||
}
|
||||
};
|
||||
|
@ -367,15 +367,15 @@ void Ram_object::free() { Genode::env()->ram_session()->free(ram_cap()); }
|
||||
void Dma_object::free() { pci.free_dma_buffer(pci_device_cap, ram_cap()); }
|
||||
|
||||
|
||||
Genode::Ram_dataspace_capability Backend_memory::alloc(Genode::addr_t size,
|
||||
bool cached)
|
||||
Genode::Ram_dataspace_capability
|
||||
Backend_memory::alloc(Genode::addr_t size, Genode::Cache_attribute cached)
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Memory_object_base *o;
|
||||
Genode::Ram_dataspace_capability cap;
|
||||
if (cached) {
|
||||
cap = env()->ram_session()->alloc(size, cached);
|
||||
if (cached == CACHED) {
|
||||
cap = env()->ram_session()->alloc(size);
|
||||
o = new (env()->heap()) Ram_object(cap);
|
||||
} else {
|
||||
cap = pci.alloc_dma_buffer(pci_device_cap, size);
|
||||
|
@ -157,7 +157,7 @@ class Storage_device : public Genode::List<Storage_device>::Element,
|
||||
bool dma_enabled() { return true; }
|
||||
|
||||
Genode::Ram_dataspace_capability alloc_dma_buffer(Genode::size_t size) {
|
||||
return Backend_memory::alloc(size, false); }
|
||||
return Backend_memory::alloc(size, Genode::UNCACHED); }
|
||||
|
||||
void free_dma_buffer(Genode::Ram_dataspace_capability cap) {
|
||||
return Backend_memory::free(cap); }
|
||||
|
Reference in New Issue
Block a user