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