-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convenience helper for attached ROM dataspaces
In the line of the 'Attached_ram_dataspace' and 'Attached_io_mem_dataspace' classes, this new helper simplifies the access to ROM dataspaces.
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* \brief ROM dataspace utility | ||
* \author Norman Feske | ||
* \date 2012-01-09 | ||
*/ | ||
|
||
/* | ||
* Copyright (C) 2012 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 _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_ | ||
#define _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_ | ||
|
||
#include <rom_session/connection.h> | ||
#include <dataspace/client.h> | ||
#include <base/env.h> | ||
|
||
namespace Genode { | ||
|
||
class Attached_rom_dataspace | ||
{ | ||
private: | ||
|
||
Rom_connection _rom; | ||
Rom_dataspace_capability _ds; | ||
size_t _size; | ||
void *_local_addr; | ||
|
||
public: | ||
|
||
/** | ||
* Constructor | ||
* | ||
* \throw Rom_connection::Rom_session_failed | ||
* \throw Rm_session::Attach_failed | ||
*/ | ||
Attached_rom_dataspace(char const *name) | ||
: | ||
_rom(name), | ||
_ds(_rom.dataspace()), | ||
_size(Dataspace_client(_ds).size()), | ||
_local_addr(env()->rm_session()->attach(_ds)) | ||
{ } | ||
|
||
/** | ||
* Destructor | ||
*/ | ||
~Attached_rom_dataspace() | ||
{ | ||
env()->rm_session()->detach(_local_addr); | ||
} | ||
|
||
/** | ||
* Return capability of the used ROM dataspace | ||
*/ | ||
Rom_dataspace_capability cap() const { return _ds; } | ||
|
||
/** | ||
* Request local address | ||
* | ||
* This is a template to avoid inconvenient casts at | ||
* the caller. A newly allocated ROM dataspace is | ||
* untyped memory anyway. | ||
*/ | ||
template <typename T> | ||
T *local_addr() { return static_cast<T *>(_local_addr); } | ||
|
||
/** | ||
* Return size | ||
*/ | ||
size_t size() const { return _size; } | ||
}; | ||
} | ||
|
||
#endif /* _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_ */ |