/* SPDX-License-Identifier: GPL-2.0-only */ /* * Industry-pack bus. * * Copyright (C) 2011-2012 CERN (www.cern.ch) * Author: Samuel Iglesias Gonsalvez <[email protected]> */ #include <linux/mod_devicetable.h> #include <linux/device.h> #include <linux/interrupt.h> #define IPACK_IDPROM_OFFSET_I … #define IPACK_IDPROM_OFFSET_P … #define IPACK_IDPROM_OFFSET_A … #define IPACK_IDPROM_OFFSET_C … #define IPACK_IDPROM_OFFSET_MANUFACTURER_ID … #define IPACK_IDPROM_OFFSET_MODEL … #define IPACK_IDPROM_OFFSET_REVISION … #define IPACK_IDPROM_OFFSET_RESERVED … #define IPACK_IDPROM_OFFSET_DRIVER_ID_L … #define IPACK_IDPROM_OFFSET_DRIVER_ID_H … #define IPACK_IDPROM_OFFSET_NUM_BYTES … #define IPACK_IDPROM_OFFSET_CRC … /* * IndustryPack Fromat, Vendor and Device IDs. */ /* ID section format versions */ #define IPACK_ID_VERSION_INVALID … #define IPACK_ID_VERSION_1 … #define IPACK_ID_VERSION_2 … /* Vendors and devices. Sort key: vendor first, device next. */ #define IPACK1_VENDOR_ID_RESERVED1 … #define IPACK1_VENDOR_ID_RESERVED2 … #define IPACK1_VENDOR_ID_UNREGISTRED01 … #define IPACK1_VENDOR_ID_UNREGISTRED02 … #define IPACK1_VENDOR_ID_UNREGISTRED03 … #define IPACK1_VENDOR_ID_UNREGISTRED04 … #define IPACK1_VENDOR_ID_UNREGISTRED05 … #define IPACK1_VENDOR_ID_UNREGISTRED06 … #define IPACK1_VENDOR_ID_UNREGISTRED07 … #define IPACK1_VENDOR_ID_UNREGISTRED08 … #define IPACK1_VENDOR_ID_UNREGISTRED09 … #define IPACK1_VENDOR_ID_UNREGISTRED10 … #define IPACK1_VENDOR_ID_UNREGISTRED11 … #define IPACK1_VENDOR_ID_UNREGISTRED12 … #define IPACK1_VENDOR_ID_UNREGISTRED13 … #define IPACK1_VENDOR_ID_UNREGISTRED14 … #define IPACK1_VENDOR_ID_UNREGISTRED15 … #define IPACK1_VENDOR_ID_SBS … #define IPACK1_DEVICE_ID_SBS_OCTAL_232 … #define IPACK1_DEVICE_ID_SBS_OCTAL_422 … #define IPACK1_DEVICE_ID_SBS_OCTAL_485 … struct ipack_bus_ops; struct ipack_driver; enum ipack_space { … }; /** */ struct ipack_region { … }; /** * struct ipack_device * * @slot: Slot where the device is plugged in the carrier board * @bus: ipack_bus_device where the device is plugged to. * @id_space: Virtual address to ID space. * @io_space: Virtual address to IO space. * @mem_space: Virtual address to MEM space. * @dev: device in kernel representation. * * Warning: Direct access to mapped memory is possible but the endianness * is not the same with PCI carrier or VME carrier. The endianness is managed * by the carrier board throught bus->ops. */ struct ipack_device { … }; /** * struct ipack_driver_ops -- Callbacks to IPack device driver * * @probe: Probe function * @remove: Prepare imminent removal of the device. Services provided by the * device should be revoked. */ struct ipack_driver_ops { … }; /** * struct ipack_driver -- Specific data to each ipack device driver * * @driver: Device driver kernel representation * @ops: Callbacks provided by the IPack device driver */ struct ipack_driver { … }; /** * struct ipack_bus_ops - available operations on a bridge module * * @map_space: map IP address space * @unmap_space: unmap IP address space * @request_irq: request IRQ * @free_irq: free IRQ * @get_clockrate: Returns the clockrate the carrier is currently * communicating with the device at. * @set_clockrate: Sets the clock-rate for carrier / module communication. * Should return -EINVAL if the requested speed is not supported. * @get_error: Returns the error state for the slot the device is attached * to. * @get_timeout: Returns 1 if the communication with the device has * previously timed out. * @reset_timeout: Resets the state returned by get_timeout. */ struct ipack_bus_ops { … }; /** * struct ipack_bus_device * * @dev: pointer to carrier device * @slots: number of slots available * @bus_nr: ipack bus number * @ops: bus operations for the mezzanine drivers */ struct ipack_bus_device { … }; /** * ipack_bus_register -- register a new ipack bus * * @parent: pointer to the parent device, if any. * @slots: number of slots available in the bus device. * @ops: bus operations for the mezzanine drivers. * * The carrier board device should call this function to register itself as * available bus device in ipack. */ struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots, const struct ipack_bus_ops *ops, struct module *owner); /** * ipack_bus_unregister -- unregister an ipack bus */ int ipack_bus_unregister(struct ipack_bus_device *bus); /** * ipack_driver_register -- Register a new ipack device driver * * Called by a ipack driver to register itself as a driver * that can manage ipack devices. */ int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, const char *name); void ipack_driver_unregister(struct ipack_driver *edrv); /** * ipack_device_init -- initialize an IPack device * @dev: the new device to initialize. * * Initialize a new IPack device ("module" in IndustryPack jargon). The call * is done by the carrier driver. The carrier should populate the fields * bus and slot as well as the region array of @dev prior to calling this * function. The rest of the fields will be allocated and populated * during initalization. * * Return zero on success or error code on failure. * * NOTE: _Never_ directly free @dev after calling this function, even * if it returned an error! Always use ipack_put_device() to give up the * reference initialized in this function instead. */ int ipack_device_init(struct ipack_device *dev); /** * ipack_device_add -- Add an IPack device * @dev: the new device to add. * * Add a new IPack device. The call is done by the carrier driver * after calling ipack_device_init(). * * Return zero on success or error code on failure. * * NOTE: _Never_ directly free @dev after calling this function, even * if it returned an error! Always use ipack_put_device() to give up the * reference initialized in this function instead. */ int ipack_device_add(struct ipack_device *dev); void ipack_device_del(struct ipack_device *dev); void ipack_get_device(struct ipack_device *dev); void ipack_put_device(struct ipack_device *dev); /** * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table * @_table: device table name * * This macro is used to create a struct ipack_device_id array (a device table) * in a generic manner. */ #define DEFINE_IPACK_DEVICE_TABLE(_table) … /** * IPACK_DEVICE - macro used to describe a specific IndustryPack device * @_format: the format version (currently either 1 or 2, 8 bit value) * @vend: the 8 or 24 bit IndustryPack Vendor ID * @dev: the 8 or 16 bit IndustryPack Device ID * * This macro is used to create a struct ipack_device_id that matches a specific * device. */ #define IPACK_DEVICE(_format, vend, dev) … /** * ipack_get_carrier - it increase the carrier ref. counter of * the carrier module * @dev: mezzanine device which wants to get the carrier */ static inline int ipack_get_carrier(struct ipack_device *dev) { … } /** * ipack_get_carrier - it decrease the carrier ref. counter of * the carrier module * @dev: mezzanine device which wants to get the carrier */ static inline void ipack_put_carrier(struct ipack_device *dev) { … }