Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 1 | #ifndef _VME_BRIDGE_H_ |
| 2 | #define _VME_BRIDGE_H_ |
| 3 | |
Dmitry Kalinkin | ad1bfe4 | 2015-10-11 01:00:58 +0300 | [diff] [blame] | 4 | #include <linux/vme.h> |
| 5 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 6 | #define VME_CRCSR_BUF_SIZE (508*1024) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 7 | /* |
| 8 | * Resource structures |
| 9 | */ |
| 10 | struct 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 Welch | 400822f | 2009-08-11 16:20:22 +0100 | [diff] [blame] | 15 | * protect master routines with a spinlock rather than a mutex. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 16 | */ |
| 17 | spinlock_t lock; |
| 18 | int locked; |
| 19 | int number; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 20 | u32 address_attr; |
| 21 | u32 cycle_attr; |
| 22 | u32 width_attr; |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 23 | struct resource bus_resource; |
Emilio G. Cota | 0599726 | 2010-11-12 11:15:40 +0000 | [diff] [blame] | 24 | void __iomem *kern_base; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | struct vme_slave_resource { |
| 28 | struct list_head list; |
| 29 | struct vme_bridge *parent; |
Martyn Welch | 400822f | 2009-08-11 16:20:22 +0100 | [diff] [blame] | 30 | struct mutex mtx; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 31 | int locked; |
| 32 | int number; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 33 | u32 address_attr; |
| 34 | u32 cycle_attr; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | struct vme_dma_pattern { |
| 38 | u32 pattern; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 39 | u32 type; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | struct vme_dma_pci { |
| 43 | dma_addr_t address; |
| 44 | }; |
| 45 | |
| 46 | struct vme_dma_vme { |
| 47 | unsigned long long address; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 48 | u32 aspace; |
| 49 | u32 cycle; |
| 50 | u32 dwidth; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct vme_dma_list { |
| 54 | struct list_head list; |
| 55 | struct vme_dma_resource *parent; |
| 56 | struct list_head entries; |
Martyn Welch | 400822f | 2009-08-11 16:20:22 +0100 | [diff] [blame] | 57 | struct mutex mtx; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | struct vme_dma_resource { |
| 61 | struct list_head list; |
| 62 | struct vme_bridge *parent; |
Martyn Welch | 400822f | 2009-08-11 16:20:22 +0100 | [diff] [blame] | 63 | struct mutex mtx; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 64 | int locked; |
| 65 | int number; |
| 66 | struct list_head pending; |
| 67 | struct list_head running; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 68 | u32 route_attr; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 71 | struct 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 Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 80 | struct vme_error_handler { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 81 | struct list_head list; |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 82 | 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 Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | struct vme_callback { |
| 90 | void (*func)(int, int, void*); |
| 91 | void *priv_data; |
| 92 | }; |
| 93 | |
| 94 | struct vme_irq { |
| 95 | int count; |
Dmitry Kalinkin | ad1bfe4 | 2015-10-11 01:00:58 +0300 | [diff] [blame] | 96 | struct vme_callback callback[VME_NUM_STATUSID]; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 97 | }; |
| 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 Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 105 | */ |
| 106 | struct vme_bridge { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 107 | char name[VMENAMSIZ]; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 108 | int num; |
| 109 | struct list_head master_resources; |
| 110 | struct list_head slave_resources; |
| 111 | struct list_head dma_resources; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 112 | struct list_head lm_resources; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 113 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 114 | /* 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 Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 118 | |
| 119 | /* Bridge Info - XXX Move to private structure? */ |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 120 | struct device *parent; /* Parent device (eg. pdev->dev for PCI) */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 121 | void *driver_priv; /* Private pointer for the bridge driver */ |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 122 | struct list_head bus_list; /* list of VME buses */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 123 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 124 | /* Interrupt callbacks */ |
| 125 | struct vme_irq irq[7]; |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 126 | /* Locking for VME irq callback configuration */ |
| 127 | struct mutex irq_mtx; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 128 | |
| 129 | /* Slave Functions */ |
| 130 | int (*slave_get) (struct vme_slave_resource *, int *, |
| 131 | unsigned long long *, unsigned long long *, dma_addr_t *, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 132 | u32 *, u32 *); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 133 | int (*slave_set) (struct vme_slave_resource *, int, unsigned long long, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 134 | unsigned long long, dma_addr_t, u32, u32); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 135 | |
| 136 | /* Master Functions */ |
| 137 | int (*master_get) (struct vme_master_resource *, int *, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 138 | unsigned long long *, unsigned long long *, u32 *, u32 *, |
| 139 | u32 *); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 140 | int (*master_set) (struct vme_master_resource *, int, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 141 | unsigned long long, unsigned long long, u32, u32, u32); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 142 | 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 Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 156 | void (*irq_set) (struct vme_bridge *, int, int, int); |
| 157 | int (*irq_generate) (struct vme_bridge *, int, int); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 158 | |
| 159 | /* Location monitor functions */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 160 | 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 *); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 163 | int (*lm_attach) (struct vme_lm_resource *, int, void (*callback)(int)); |
| 164 | int (*lm_detach) (struct vme_lm_resource *, int); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 165 | |
| 166 | /* CR/CSR space functions */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 167 | int (*slot_get) (struct vme_bridge *); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 168 | |
| 169 | /* Bridge parent interface */ |
| 170 | void *(*alloc_consistent)(struct device *dev, size_t size, |
| 171 | dma_addr_t *dma); |
| 172 | void (*free_consistent)(struct device *dev, size_t size, |
| 173 | void *vaddr, dma_addr_t dma); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 174 | }; |
| 175 | |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 176 | void vme_bus_error_handler(struct vme_bridge *bridge, |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 177 | unsigned long long address, int am); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 178 | void vme_irq_handler(struct vme_bridge *, int, int); |
| 179 | |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 180 | int vme_register_bridge(struct vme_bridge *); |
| 181 | void vme_unregister_bridge(struct vme_bridge *); |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 182 | struct vme_error_handler *vme_register_error_handler( |
| 183 | struct vme_bridge *bridge, u32 aspace, |
| 184 | unsigned long long address, size_t len); |
| 185 | void vme_unregister_error_handler(struct vme_error_handler *handler); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 186 | |
| 187 | #endif /* _VME_BRIDGE_H_ */ |