summaryrefslogtreecommitdiff
path: root/device.h
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2010-11-18 13:55:30 +0100
committerTobias Klauser <tklauser@distanz.ch>2010-11-18 13:55:30 +0100
commit498763e178b5d8f51c17057630779cd48393e6f6 (patch)
tree4937a7e8b76898e150fce43b69ca8bcd9aa05a92 /device.h
parent105d2c8f1436a91867ce352144baae5c390a32e1 (diff)
Generic device handling updates
Diffstat (limited to 'device.h')
-rw-r--r--device.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/device.h b/device.h
index beabe52..cf84e05 100644
--- a/device.h
+++ b/device.h
@@ -12,20 +12,53 @@
#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, uint32_t *data, size_t count);
+ size_t (*write)(struct device *dev, uint32_t addr, uint32_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_ */