blob: 2662e916b96af86892ec71315cc660702ba852a3 [file] [log] [blame]
Martyn Welcha17a75e2009-07-31 09:28:17 +01001#ifndef _VME_BRIDGE_H_
2#define _VME_BRIDGE_H_
3
Dmitry Kalinkinad1bfe42015-10-11 01:00:58 +03004#include <linux/vme.h>
5
Martyn Welcha17a75e2009-07-31 09:28:17 +01006#define VME_CRCSR_BUF_SIZE (508*1024)
Martyn Welcha17a75e2009-07-31 09:28:17 +01007/*
8 * Resource structures
9 */
10struct vme_master_resource {
11 struct list_head list;
12 struct vme_bridge *parent;
13 /*
14 * We are likely to need to access the VME bus in interrupt context, so
Martyn Welch400822f2009-08-11 16:20:22 +010015 * protect master routines with a spinlock rather than a mutex.
Martyn Welcha17a75e2009-07-31 09:28:17 +010016 */
17 spinlock_t lock;
18 int locked;
19 int number;
Martyn Welch6af04b02011-12-01 17:06:29 +000020 u32 address_attr;
21 u32 cycle_attr;
22 u32 width_attr;
Martyn Welch8fafb472010-02-18 15:13:12 +000023 struct resource bus_resource;
Emilio G. Cota05997262010-11-12 11:15:40 +000024 void __iomem *kern_base;
Martyn Welcha17a75e2009-07-31 09:28:17 +010025};
26
27struct vme_slave_resource {
28 struct list_head list;
29 struct vme_bridge *parent;
Martyn Welch400822f2009-08-11 16:20:22 +010030 struct mutex mtx;
Martyn Welcha17a75e2009-07-31 09:28:17 +010031 int locked;
32 int number;
Martyn Welch6af04b02011-12-01 17:06:29 +000033 u32 address_attr;
34 u32 cycle_attr;
Martyn Welcha17a75e2009-07-31 09:28:17 +010035};
36
37struct vme_dma_pattern {
38 u32 pattern;
Martyn Welch6af04b02011-12-01 17:06:29 +000039 u32 type;
Martyn Welcha17a75e2009-07-31 09:28:17 +010040};
41
42struct vme_dma_pci {
43 dma_addr_t address;
44};
45
46struct vme_dma_vme {
47 unsigned long long address;
Martyn Welch6af04b02011-12-01 17:06:29 +000048 u32 aspace;
49 u32 cycle;
50 u32 dwidth;
Martyn Welcha17a75e2009-07-31 09:28:17 +010051};
52
53struct vme_dma_list {
54 struct list_head list;
55 struct vme_dma_resource *parent;
56 struct list_head entries;
Martyn Welch400822f2009-08-11 16:20:22 +010057 struct mutex mtx;
Martyn Welcha17a75e2009-07-31 09:28:17 +010058};
59
60struct vme_dma_resource {
61 struct list_head list;
62 struct vme_bridge *parent;
Martyn Welch400822f2009-08-11 16:20:22 +010063 struct mutex mtx;
Martyn Welcha17a75e2009-07-31 09:28:17 +010064 int locked;
65 int number;
66 struct list_head pending;
67 struct list_head running;
Martyn Welch6af04b02011-12-01 17:06:29 +000068 u32 route_attr;
Martyn Welcha17a75e2009-07-31 09:28:17 +010069};
70
Martyn Welch42fb5032009-08-11 17:44:56 +010071struct vme_lm_resource {
72 struct list_head list;
73 struct vme_bridge *parent;
74 struct mutex mtx;
75 int locked;
76 int number;
77 int monitors;
78};
79
Dmitry Kalinkin0b049662015-09-18 02:01:44 +030080struct vme_error_handler {
Martyn Welcha17a75e2009-07-31 09:28:17 +010081 struct list_head list;
Dmitry Kalinkin0b049662015-09-18 02:01:44 +030082 unsigned long long start; /* Beginning of error window */
83 unsigned long long end; /* End of error window */
84 unsigned long long first_error; /* Address of the first error */
85 u32 aspace; /* Address space of error window*/
86 unsigned num_errors; /* Number of errors */
Martyn Welcha17a75e2009-07-31 09:28:17 +010087};
88
89struct vme_callback {
90 void (*func)(int, int, void*);
91 void *priv_data;
92};
93
94struct vme_irq {
95 int count;
Dmitry Kalinkinad1bfe42015-10-11 01:00:58 +030096 struct vme_callback callback[VME_NUM_STATUSID];
Martyn Welcha17a75e2009-07-31 09:28:17 +010097};
98
99/* Allow 16 characters for name (including null character) */
100#define VMENAMSIZ 16
101
102/* This structure stores all the information about one bridge
103 * The structure should be dynamically allocated by the driver and one instance
104 * of the structure should be present for each VME chip present in the system.
Martyn Welcha17a75e2009-07-31 09:28:17 +0100105 */
106struct vme_bridge {
Martyn Welchead1f3e2009-12-15 08:43:02 +0000107 char name[VMENAMSIZ];
Martyn Welcha17a75e2009-07-31 09:28:17 +0100108 int num;
109 struct list_head master_resources;
110 struct list_head slave_resources;
111 struct list_head dma_resources;
Martyn Welch42fb5032009-08-11 17:44:56 +0100112 struct list_head lm_resources;
Martyn Welcha17a75e2009-07-31 09:28:17 +0100113
Dmitry Kalinkin0b049662015-09-18 02:01:44 +0300114 /* List for registered errors handlers */
115 struct list_head vme_error_handlers;
116 /* List of devices on this bridge */
117 struct list_head devices;
Martyn Welcha17a75e2009-07-31 09:28:17 +0100118
119 /* Bridge Info - XXX Move to private structure? */
Manohar Vanga7f58f022011-08-10 11:33:46 +0200120 struct device *parent; /* Parent device (eg. pdev->dev for PCI) */
Martyn Welch29848ac2010-02-18 15:13:05 +0000121 void *driver_priv; /* Private pointer for the bridge driver */
Manohar Vanga733e3ef2011-08-12 12:30:48 +0200122 struct list_head bus_list; /* list of VME buses */
Martyn Welcha17a75e2009-07-31 09:28:17 +0100123
Martyn Welcha17a75e2009-07-31 09:28:17 +0100124 /* Interrupt callbacks */
125 struct vme_irq irq[7];
Martyn Welchc813f592009-10-29 16:34:54 +0000126 /* Locking for VME irq callback configuration */
127 struct mutex irq_mtx;
Martyn Welcha17a75e2009-07-31 09:28:17 +0100128
129 /* Slave Functions */
130 int (*slave_get) (struct vme_slave_resource *, int *,
131 unsigned long long *, unsigned long long *, dma_addr_t *,
Martyn Welch6af04b02011-12-01 17:06:29 +0000132 u32 *, u32 *);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100133 int (*slave_set) (struct vme_slave_resource *, int, unsigned long long,
Martyn Welch6af04b02011-12-01 17:06:29 +0000134 unsigned long long, dma_addr_t, u32, u32);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100135
136 /* Master Functions */
137 int (*master_get) (struct vme_master_resource *, int *,
Martyn Welch6af04b02011-12-01 17:06:29 +0000138 unsigned long long *, unsigned long long *, u32 *, u32 *,
139 u32 *);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100140 int (*master_set) (struct vme_master_resource *, int,
Martyn Welch6af04b02011-12-01 17:06:29 +0000141 unsigned long long, unsigned long long, u32, u32, u32);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100142 ssize_t (*master_read) (struct vme_master_resource *, void *, size_t,
143 loff_t);
144 ssize_t (*master_write) (struct vme_master_resource *, void *, size_t,
145 loff_t);
146 unsigned int (*master_rmw) (struct vme_master_resource *, unsigned int,
147 unsigned int, unsigned int, loff_t);
148
149 /* DMA Functions */
150 int (*dma_list_add) (struct vme_dma_list *, struct vme_dma_attr *,
151 struct vme_dma_attr *, size_t);
152 int (*dma_list_exec) (struct vme_dma_list *);
153 int (*dma_list_empty) (struct vme_dma_list *);
154
155 /* Interrupt Functions */
Martyn Welch29848ac2010-02-18 15:13:05 +0000156 void (*irq_set) (struct vme_bridge *, int, int, int);
157 int (*irq_generate) (struct vme_bridge *, int, int);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100158
159 /* Location monitor functions */
Martyn Welch6af04b02011-12-01 17:06:29 +0000160 int (*lm_set) (struct vme_lm_resource *, unsigned long long, u32, u32);
161 int (*lm_get) (struct vme_lm_resource *, unsigned long long *, u32 *,
162 u32 *);
Aaron Sierrafa54b322016-04-29 16:41:02 -0500163 int (*lm_attach)(struct vme_lm_resource *, int,
164 void (*callback)(void *), void *);
Martyn Welch42fb5032009-08-11 17:44:56 +0100165 int (*lm_detach) (struct vme_lm_resource *, int);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100166
167 /* CR/CSR space functions */
Martyn Welch29848ac2010-02-18 15:13:05 +0000168 int (*slot_get) (struct vme_bridge *);
Manohar Vanga7f58f022011-08-10 11:33:46 +0200169
170 /* Bridge parent interface */
171 void *(*alloc_consistent)(struct device *dev, size_t size,
172 dma_addr_t *dma);
173 void (*free_consistent)(struct device *dev, size_t size,
174 void *vaddr, dma_addr_t dma);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100175};
176
Dmitry Kalinkine2c63932015-09-18 02:01:42 +0300177void vme_bus_error_handler(struct vme_bridge *bridge,
Dmitry Kalinkin472f16f2015-09-18 02:01:43 +0300178 unsigned long long address, int am);
Martyn Welchc813f592009-10-29 16:34:54 +0000179void vme_irq_handler(struct vme_bridge *, int, int);
180
Aaron Sierra326071b2016-04-24 15:11:38 -0500181struct vme_bridge *vme_init_bridge(struct vme_bridge *);
Martyn Welchead1f3e2009-12-15 08:43:02 +0000182int vme_register_bridge(struct vme_bridge *);
183void vme_unregister_bridge(struct vme_bridge *);
Dmitry Kalinkin0b049662015-09-18 02:01:44 +0300184struct vme_error_handler *vme_register_error_handler(
185 struct vme_bridge *bridge, u32 aspace,
186 unsigned long long address, size_t len);
187void vme_unregister_error_handler(struct vme_error_handler *handler);
Martyn Welcha17a75e2009-07-31 09:28:17 +0100188
189#endif /* _VME_BRIDGE_H_ */