summaryrefslogtreecommitdiff
path: root/user/iotable.c
blob: 91a5016c420058f68bec28c56c1c28a2de612a04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Kernel-based Virtual Machine test driver
 *
 * This test driver provides a simple way of testing kvm, without a full
 * device model.
 *
 * Copyright (C) 2006 Qumranet
 *
 * Authors:
 *
 *  Avi Kivity <avi@qumranet.com>
 *  Yaniv Kamay <yaniv@qumranet.com>
 *
 * This work is licensed under the GNU LGPL license, version 2.
 */

#include <stdlib.h>
#include <stdint.h>
#include <errno.h>

#include "iotable.h"

struct io_table_entry *io_table_lookup(struct io_table *io_table, uint64_t addr)
{
	int i;

	for (i = 0; i < io_table->nr_entries; i++) {
		if (io_table->entries[i].start <= addr &&
		    addr < io_table->entries[i].end)
			return &io_table->entries[i];
	}

	return NULL;
}

int io_table_register(struct io_table *io_table, uint64_t start, uint64_t size,
		      io_table_handler_t *handler, void *opaque)
{
	struct io_table_entry *entry;

	if (io_table->nr_entries == MAX_IO_TABLE)
		return -ENOSPC;

	entry = &io_table->entries[io_table->nr_entries];
	io_table->nr_entries++;

	entry->start = start;
	entry->end = start + size;
	entry->handler = handler;
	entry->opaque = opaque;

	return 0;
}