blob: 3aa38c511abe9c8f16ae1684a6f2f0f05ac3bc13 [file] [log] [blame]
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +02001/*
2 * Industry-pack bus.
3 *
4 * (C) 2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
5 * (C) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
Samuel Iglesias Gonsalvez416289b2012-05-11 10:17:13 +02009 * Software Foundation; version 2 of the License.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020010 */
11
12#include <linux/device.h>
13
14#define IPACK_BOARD_NAME_SIZE 16
15#define IPACK_IRQ_NAME_SIZE 50
16#define IPACK_IDPROM_OFFSET_I 0x01
17#define IPACK_IDPROM_OFFSET_P 0x03
18#define IPACK_IDPROM_OFFSET_A 0x05
19#define IPACK_IDPROM_OFFSET_C 0x07
20#define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09
21#define IPACK_IDPROM_OFFSET_MODEL 0x0B
22#define IPACK_IDPROM_OFFSET_REVISION 0x0D
23#define IPACK_IDPROM_OFFSET_RESERVED 0x0F
24#define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11
25#define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13
26#define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15
27#define IPACK_IDPROM_OFFSET_CRC 0x17
28
29struct ipack_bus_ops;
30struct ipack_driver;
31
32enum ipack_space {
33 IPACK_IO_SPACE = 0,
34 IPACK_ID_SPACE = 1,
35 IPACK_MEM_SPACE = 2,
36};
37
38/**
39 * struct ipack_addr_space - Virtual address space mapped for a specified type.
40 *
41 * @address: virtual address
42 * @size: size of the mapped space
43 */
44struct ipack_addr_space {
45 void *address;
46 unsigned int size;
47};
48
49/**
50 * struct ipack_device
51 *
52 * @board_name: IP mezzanine board name
53 * @bus_name: IP carrier board name
54 * @bus_nr: IP bus number where the device is plugged
55 * @slot: Slot where the device is plugged in the carrier board
56 * @irq: IRQ vector
57 * @driver: Pointer to the ipack_driver that manages the device
58 * @ops: Carrier board operations to access the device
59 * @id_space: Virtual address to ID space.
60 * @io_space: Virtual address to IO space.
61 * @mem_space: Virtual address to MEM space.
62 * @dev: device in kernel representation.
63 *
64 * Warning: Direct access to mapped memory is possible but the endianness
65 * is not the same with PCI carrier or VME carrier. The endianness is managed
66 * by the carrier board throught @ops.
67 */
68struct ipack_device {
69 char board_name[IPACK_BOARD_NAME_SIZE];
70 char bus_name[IPACK_BOARD_NAME_SIZE];
71 unsigned int bus_nr;
72 unsigned int slot;
73 unsigned int irq;
74 struct ipack_driver *driver;
75 struct ipack_bus_ops *ops;
76 struct ipack_addr_space id_space;
77 struct ipack_addr_space io_space;
78 struct ipack_addr_space mem_space;
79 struct device dev;
80};
81
82/*
83 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
84 *
85 * @match: Match function
86 * @probe: Probe function
87 * @remove: tell the driver that the carrier board wants to remove one device
88 */
89
90struct ipack_driver_ops {
91 int (*match) (struct ipack_device *dev);
92 int (*probe) (struct ipack_device *dev);
93 void (*remove) (struct ipack_device *dev);
94};
95
96/**
97 * struct ipack_driver -- Specific data to each mezzanine board driver
98 *
99 * @driver: Device driver kernel representation
100 * @ops: Mezzanine driver operations specific for the ipack bus.
101 */
102struct ipack_driver {
103 struct module *owner;
104 struct device_driver driver;
105 struct ipack_driver_ops *ops;
106};
107
108/*
109 * ipack_driver_register -- Register a new mezzanine driver
110 *
111 * Called by the mezzanine driver to register itself as a driver
112 * that can manage ipack devices.
113 */
114
115int ipack_driver_register(struct ipack_driver *edrv);
116void ipack_driver_unregister(struct ipack_driver *edrv);
117
118/*
119 * ipack_device_register -- register a new mezzanine device
120 *
121 * Register a new ipack device (mezzanine device). The call is done by
122 * the carrier device driver.
123 */
124int ipack_device_register(struct ipack_device *dev);
125void ipack_device_unregister(struct ipack_device *dev);
126
127/**
128 * struct ipack_bus_ops - available operations on a bridge module
129 *
130 * @map_space: map IP address space
131 * @unmap_space: unmap IP address space
132 * @request_irq: request IRQ
133 * @free_irq: free IRQ
134 * @read8: read unsigned char
135 * @read16: read unsigned short
136 * @read32: read unsigned int
137 * @write8: read unsigned char
138 * @write16: read unsigned short
139 * @write32: read unsigned int
140 * @remove_device: tell the bridge module that the device has been removed
141 */
142struct ipack_bus_ops {
143 int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space);
144 int (*unmap_space) (struct ipack_device *dev, int space);
145 int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg);
146 int (*free_irq) (struct ipack_device *dev);
147 int (*read8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char *value);
148 int (*read16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short *value);
149 int (*read32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int *value);
150 int (*write8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char value);
151 int (*write16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short value);
152 int (*write32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int value);
153 int (*remove_device) (struct ipack_device *dev);
154};
155
156/**
157 * struct ipack_bus_device
158 *
159 * @dev: pointer to carrier device
160 * @slots: number of slots available
161 * @bus_nr: ipack bus number
162 * @vector: IRQ base vector. IRQ vectors are $vector + $slot_number
163 */
164struct ipack_bus_device {
165 struct device *dev;
166 int slots;
167 int bus_nr;
168 int vector;
169};
170
171/**
172 * ipack_bus_register -- register a new ipack bus
173 *
174 * The carrier board device driver should call this function to register itself
175 * as available bus in ipack.
176 */
177int ipack_bus_register(struct ipack_bus_device *bus);
178
179/**
180 * ipack_bus_unregister -- unregister an ipack bus
181 */
182int ipack_bus_unregister(struct ipack_bus_device *bus);