Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 2 | #ifndef _VME_BRIDGE_H_ |
| 3 | #define _VME_BRIDGE_H_ |
| 4 | |
Dmitry Kalinkin | ad1bfe4 | 2015-10-11 01:00:58 +0300 | [diff] [blame] | 5 | #include <linux/vme.h> |
| 6 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 7 | #define VME_CRCSR_BUF_SIZE (508*1024) |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 8 | /* |
| 9 | * Resource structures |
| 10 | */ |
| 11 | struct vme_master_resource { |
| 12 | struct list_head list; |
| 13 | struct vme_bridge *parent; |
| 14 | /* |
| 15 | * 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] | 16 | * protect master routines with a spinlock rather than a mutex. |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 17 | */ |
| 18 | spinlock_t lock; |
| 19 | int locked; |
| 20 | int number; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 21 | u32 address_attr; |
| 22 | u32 cycle_attr; |
| 23 | u32 width_attr; |
Martyn Welch | 8fafb47 | 2010-02-18 15:13:12 +0000 | [diff] [blame] | 24 | struct resource bus_resource; |
Emilio G. Cota | 0599726 | 2010-11-12 11:15:40 +0000 | [diff] [blame] | 25 | void __iomem *kern_base; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | struct vme_slave_resource { |
| 29 | struct list_head list; |
| 30 | struct vme_bridge *parent; |
Martyn Welch | 400822f | 2009-08-11 16:20:22 +0100 | [diff] [blame] | 31 | struct mutex mtx; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 32 | int locked; |
| 33 | int number; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 34 | u32 address_attr; |
| 35 | u32 cycle_attr; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct vme_dma_pattern { |
| 39 | u32 pattern; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 40 | u32 type; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct vme_dma_pci { |
| 44 | dma_addr_t address; |
| 45 | }; |
| 46 | |
| 47 | struct vme_dma_vme { |
| 48 | unsigned long long address; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 49 | u32 aspace; |
| 50 | u32 cycle; |
| 51 | u32 dwidth; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct vme_dma_list { |
| 55 | struct list_head list; |
| 56 | struct vme_dma_resource *parent; |
| 57 | struct list_head entries; |
Martyn Welch | 400822f | 2009-08-11 16:20:22 +0100 | [diff] [blame] | 58 | struct mutex mtx; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | struct vme_dma_resource { |
| 62 | struct list_head list; |
| 63 | struct vme_bridge *parent; |
Martyn Welch | 400822f | 2009-08-11 16:20:22 +0100 | [diff] [blame] | 64 | struct mutex mtx; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 65 | int locked; |
| 66 | int number; |
| 67 | struct list_head pending; |
| 68 | struct list_head running; |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 69 | u32 route_attr; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 70 | }; |
| 71 | |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 72 | struct vme_lm_resource { |
| 73 | struct list_head list; |
| 74 | struct vme_bridge *parent; |
| 75 | struct mutex mtx; |
| 76 | int locked; |
| 77 | int number; |
| 78 | int monitors; |
| 79 | }; |
| 80 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 81 | struct vme_error_handler { |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 82 | struct list_head list; |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 83 | unsigned long long start; /* Beginning of error window */ |
| 84 | unsigned long long end; /* End of error window */ |
| 85 | unsigned long long first_error; /* Address of the first error */ |
| 86 | u32 aspace; /* Address space of error window*/ |
| 87 | unsigned num_errors; /* Number of errors */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | struct vme_callback { |
| 91 | void (*func)(int, int, void*); |
| 92 | void *priv_data; |
| 93 | }; |
| 94 | |
| 95 | struct vme_irq { |
| 96 | int count; |
Dmitry Kalinkin | ad1bfe4 | 2015-10-11 01:00:58 +0300 | [diff] [blame] | 97 | struct vme_callback callback[VME_NUM_STATUSID]; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /* Allow 16 characters for name (including null character) */ |
| 101 | #define VMENAMSIZ 16 |
| 102 | |
| 103 | /* This structure stores all the information about one bridge |
| 104 | * The structure should be dynamically allocated by the driver and one instance |
| 105 | * 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] | 106 | */ |
| 107 | struct vme_bridge { |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 108 | char name[VMENAMSIZ]; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 109 | int num; |
| 110 | struct list_head master_resources; |
| 111 | struct list_head slave_resources; |
| 112 | struct list_head dma_resources; |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 113 | struct list_head lm_resources; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 114 | |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 115 | /* List for registered errors handlers */ |
| 116 | struct list_head vme_error_handlers; |
| 117 | /* List of devices on this bridge */ |
| 118 | struct list_head devices; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 119 | |
| 120 | /* Bridge Info - XXX Move to private structure? */ |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 121 | struct device *parent; /* Parent device (eg. pdev->dev for PCI) */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 122 | void *driver_priv; /* Private pointer for the bridge driver */ |
Manohar Vanga | 733e3ef | 2011-08-12 12:30:48 +0200 | [diff] [blame] | 123 | struct list_head bus_list; /* list of VME buses */ |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 124 | |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 125 | /* Interrupt callbacks */ |
| 126 | struct vme_irq irq[7]; |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 127 | /* Locking for VME irq callback configuration */ |
| 128 | struct mutex irq_mtx; |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 129 | |
| 130 | /* Slave Functions */ |
| 131 | int (*slave_get) (struct vme_slave_resource *, int *, |
| 132 | unsigned long long *, unsigned long long *, dma_addr_t *, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 133 | u32 *, u32 *); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 134 | int (*slave_set) (struct vme_slave_resource *, int, unsigned long long, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 135 | unsigned long long, dma_addr_t, u32, u32); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 136 | |
| 137 | /* Master Functions */ |
| 138 | int (*master_get) (struct vme_master_resource *, int *, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 139 | unsigned long long *, unsigned long long *, u32 *, u32 *, |
| 140 | u32 *); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 141 | int (*master_set) (struct vme_master_resource *, int, |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 142 | unsigned long long, unsigned long long, u32, u32, u32); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 143 | ssize_t (*master_read) (struct vme_master_resource *, void *, size_t, |
| 144 | loff_t); |
| 145 | ssize_t (*master_write) (struct vme_master_resource *, void *, size_t, |
| 146 | loff_t); |
| 147 | unsigned int (*master_rmw) (struct vme_master_resource *, unsigned int, |
| 148 | unsigned int, unsigned int, loff_t); |
| 149 | |
| 150 | /* DMA Functions */ |
| 151 | int (*dma_list_add) (struct vme_dma_list *, struct vme_dma_attr *, |
| 152 | struct vme_dma_attr *, size_t); |
| 153 | int (*dma_list_exec) (struct vme_dma_list *); |
| 154 | int (*dma_list_empty) (struct vme_dma_list *); |
| 155 | |
| 156 | /* Interrupt Functions */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 157 | void (*irq_set) (struct vme_bridge *, int, int, int); |
| 158 | int (*irq_generate) (struct vme_bridge *, int, int); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 159 | |
| 160 | /* Location monitor functions */ |
Martyn Welch | 6af04b0 | 2011-12-01 17:06:29 +0000 | [diff] [blame] | 161 | int (*lm_set) (struct vme_lm_resource *, unsigned long long, u32, u32); |
| 162 | int (*lm_get) (struct vme_lm_resource *, unsigned long long *, u32 *, |
| 163 | u32 *); |
Aaron Sierra | fa54b32 | 2016-04-29 16:41:02 -0500 | [diff] [blame] | 164 | int (*lm_attach)(struct vme_lm_resource *, int, |
| 165 | void (*callback)(void *), void *); |
Martyn Welch | 42fb503 | 2009-08-11 17:44:56 +0100 | [diff] [blame] | 166 | int (*lm_detach) (struct vme_lm_resource *, int); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 167 | |
| 168 | /* CR/CSR space functions */ |
Martyn Welch | 29848ac | 2010-02-18 15:13:05 +0000 | [diff] [blame] | 169 | int (*slot_get) (struct vme_bridge *); |
Manohar Vanga | 7f58f02 | 2011-08-10 11:33:46 +0200 | [diff] [blame] | 170 | |
| 171 | /* Bridge parent interface */ |
| 172 | void *(*alloc_consistent)(struct device *dev, size_t size, |
| 173 | dma_addr_t *dma); |
| 174 | void (*free_consistent)(struct device *dev, size_t size, |
| 175 | void *vaddr, dma_addr_t dma); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 176 | }; |
| 177 | |
Dmitry Kalinkin | e2c6393 | 2015-09-18 02:01:42 +0300 | [diff] [blame] | 178 | void vme_bus_error_handler(struct vme_bridge *bridge, |
Dmitry Kalinkin | 472f16f | 2015-09-18 02:01:43 +0300 | [diff] [blame] | 179 | unsigned long long address, int am); |
Martyn Welch | c813f59 | 2009-10-29 16:34:54 +0000 | [diff] [blame] | 180 | void vme_irq_handler(struct vme_bridge *, int, int); |
| 181 | |
Aaron Sierra | 326071b | 2016-04-24 15:11:38 -0500 | [diff] [blame] | 182 | struct vme_bridge *vme_init_bridge(struct vme_bridge *); |
Martyn Welch | ead1f3e | 2009-12-15 08:43:02 +0000 | [diff] [blame] | 183 | int vme_register_bridge(struct vme_bridge *); |
| 184 | void vme_unregister_bridge(struct vme_bridge *); |
Dmitry Kalinkin | 0b04966 | 2015-09-18 02:01:44 +0300 | [diff] [blame] | 185 | struct vme_error_handler *vme_register_error_handler( |
| 186 | struct vme_bridge *bridge, u32 aspace, |
| 187 | unsigned long long address, size_t len); |
| 188 | void vme_unregister_error_handler(struct vme_error_handler *handler); |
Martyn Welch | a17a75e | 2009-07-31 09:28:17 +0100 | [diff] [blame] | 189 | |
| 190 | #endif /* _VME_BRIDGE_H_ */ |