summaryrefslogtreecommitdiff
path: root/io_device.h
blob: e520ff08e9b9c7c91e571c17120e9f02847e38dc (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
54
55
56
57
58
59
60
61
62
63
64
65
/*
    Nios-sim - one simple NIOSII simulator only for personal interest and fun.
    Copyright (C) 2010  chysun2000@gmail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#ifndef __IO_DEVICE_H__
#define __IO_DEVICE_H__
#include <stdio.h>

#define ADDR_IS_NOT_DEV (0)
#define ADDR_IS_DEV (1)

#define DEV_HAS_IRQ (1)
#define DEV_NO_IRQ  (0)

struct io_device;
struct io_device {
	void * priv_data;
	char * name;
	uint32_t irq_enable_mask;
	void (*init)(struct io_device * self);
	int32_t (*is_belong)(uint32_t address);
	uint32_t (*read_data)(struct io_device * self, uint32_t addr, uint32_t data_len);
	void (*write_data)(struct io_device * self, uint32_t addr, uint32_t data, uint32_t data_len);
	int32_t (*has_irq)(struct io_device * self);
	void (*simulate)(struct io_device * self);
	
};

struct io_reg {
	uint32_t addr;
	uint32_t value;
	uint32_t valid_mask;
	uint32_t only_read_mask;
};

extern void init_devices(void);
extern struct io_device * get_device(uint32_t address);

extern uint32_t io_write_data(uint32_t old_data, uint32_t new_data, uint32_t data_len);
extern uint32_t io_read_data(uint32_t old_data, uint32_t data_len);
extern uint32_t io_write_data_mask(uint32_t old_data, uint32_t new_data, uint32_t data_len, 
										uint32_t valid_mask, uint32_t only_read_mask);
extern void hw_simulating(void);
extern uint32_t get_io_irq_status(void);

extern uint32_t check_reg_bit(uint32_t value, uint32_t mask);
#endif