/* * Copyright (C) 2010 Tobias Klauser * Copyright (C) 2010 chysun2000@gmail.com * * This file is part of nios2sim-ng. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. */ #ifndef _DEVICE_H_ #define _DEVICE_H_ /* IRQs for all used devices shall be allocated here */ #define IRQ_TIMER 1 #define IRQ_UART 2 #define IRQ_JTAG_UART 3 #define IRQ_TO_MASK(irq) (1UL << (irq)) struct device { const char *name; uint32_t base; size_t size; uint32_t irq_mask; int (*init)(struct device *dev); bool (*is_dev_addr)(struct device *dev, uint32_t addr); size_t (*read)(struct device *dev, uint32_t addr, uint8_t *data, size_t count); size_t (*write)(struct device *dev, uint32_t addr, uint8_t *data, size_t count); bool (*has_irq)(struct device *dev); void (*simulate)(struct device *dev); /* Private data */ void *priv; }; extern bool device_generic_is_dev_addr(struct device *dev, uint32_t addr); extern int device_init_all(void); extern struct device *device_get_by_addr(uint32_t addr); extern void device_simulate_all(void); /* * Device registers */ struct io_register { uint32_t addr; uint32_t valid_mask; uint32_t readonly_mask; uint32_t value; }; #define REG_TO_OFF(reg) ((reg) * sizeof(uint32_t)) extern void io_register_init(struct io_register *reg, uint32_t addr, uint32_t valid, uint32_t readonly, uint32_t value); extern uint32_t io_register_read(struct io_register *reg); extern void io_register_write(struct io_register *reg, uint32_t value); #endif /* _DEVICE_H_ */