forked from aquynh/iVM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The current ioport callbacks are not type-safe, in that they accept an "opaque" pointer as an argument whose type must match the argument to the registration function; this is not checked by the compiler. This patch adds an alternative that is type-safe. Instead of an opaque argument, both registation and the callback use a new IOPort type. The callback then uses container_of() to access its main structures. Currently the old and new methods exist side by side; once the old way is gone, we can also save a bunch of memory since the new method requires one pointer per ioport instead of 6. Acked-by: Anthony Liguori <[email protected]> Signed-off-by: Avi Kivity <[email protected]> Signed-off-by: Anthony Liguori <[email protected]>
- Loading branch information
Showing
3 changed files
with
96 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
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
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,30 @@ | ||
#ifndef IORANGE_H | ||
#define IORANGE_H | ||
|
||
#include <stdint.h> | ||
|
||
typedef struct IORange IORange; | ||
typedef struct IORangeOps IORangeOps; | ||
|
||
struct IORangeOps { | ||
void (*read)(IORange *iorange, uint64_t offset, unsigned width, | ||
uint64_t *data); | ||
void (*write)(IORange *iorange, uint64_t offset, unsigned width, | ||
uint64_t data); | ||
}; | ||
|
||
struct IORange { | ||
const IORangeOps *ops; | ||
uint64_t base; | ||
uint64_t len; | ||
}; | ||
|
||
static inline void iorange_init(IORange *iorange, const IORangeOps *ops, | ||
uint64_t base, uint64_t len) | ||
{ | ||
iorange->ops = ops; | ||
iorange->base = base; | ||
iorange->len = len; | ||
} | ||
|
||
#endif |