1/* 2 * Intel MIC Platform Software Stack (MPSS) 3 * 4 * Copyright(c) 2016 Intel Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License, version 2, as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * The full GNU General Public License is included in this distribution in 16 * the file called "COPYING". 17 * 18 * Intel Virtio over PCIe Bus driver. 19 */ 20#ifndef _VOP_BUS_H_ 21#define _VOP_BUS_H_ 22/* 23 * Everything a vop driver needs to work with any particular vop 24 * implementation. 25 */ 26#include <linux/dmaengine.h> 27#include <linux/interrupt.h> 28 29#include "../common/mic_dev.h" 30 31struct vop_device_id { 32 u32 device; 33 u32 vendor; 34}; 35 36#define VOP_DEV_TRNSP 1 37#define VOP_DEV_ANY_ID 0xffffffff 38/* 39 * Size of the internal buffer used during DMA's as an intermediate buffer 40 * for copy to/from user. Must be an integral number of pages. 41 */ 42#define VOP_INT_DMA_BUF_SIZE PAGE_ALIGN(64 * 1024ULL) 43 44/** 45 * vop_device - representation of a device using vop 46 * @hw_ops: the hardware ops supported by this device. 47 * @id: the device type identification (used to match it with a driver). 48 * @dev: underlying device. 49 * @dnode - The destination node which this device will communicate with. 50 * @aper: Aperture memory window 51 * @dma_ch - DMA channel 52 * @index: unique position on the vop bus 53 */ 54struct vop_device { 55 struct vop_hw_ops *hw_ops; 56 struct vop_device_id id; 57 struct device dev; 58 u8 dnode; 59 struct mic_mw *aper; 60 struct dma_chan *dma_ch; 61 int index; 62}; 63 64/** 65 * vop_driver - operations for a vop I/O driver 66 * @driver: underlying device driver (populate name and owner). 67 * @id_table: the ids serviced by this driver. 68 * @probe: the function to call when a device is found. Returns 0 or -errno. 69 * @remove: the function to call when a device is removed. 70 */ 71struct vop_driver { 72 struct device_driver driver; 73 const struct vop_device_id *id_table; 74 int (*probe)(struct vop_device *dev); 75 void (*remove)(struct vop_device *dev); 76}; 77 78/** 79 * vop_hw_ops - Hardware operations for accessing a VOP device on the VOP bus. 80 * 81 * @next_db: Obtain the next available doorbell. 82 * @request_irq: Request an interrupt on a particular doorbell. 83 * @free_irq: Free an interrupt requested previously. 84 * @ack_interrupt: acknowledge an interrupt in the ISR. 85 * @get_remote_dp: Get access to the virtio device page used by the remote 86 * node to add/remove/configure virtio devices. 87 * @get_dp: Get access to the virtio device page used by the self 88 * node to add/remove/configure virtio devices. 89 * @send_intr: Send an interrupt to the peer node on a specified doorbell. 90 * @ioremap: Map a buffer with the specified DMA address and length. 91 * @iounmap: Unmap a buffer previously mapped. 92 * @dma_filter: The DMA filter function to use for obtaining access to 93 * a DMA channel on the peer node. 94 */ 95struct vop_hw_ops { 96 int (*next_db)(struct vop_device *vpdev); 97 struct mic_irq *(*request_irq)(struct vop_device *vpdev, 98 irqreturn_t (*func)(int irq, void *data), 99 const char *name, void *data, 100 int intr_src); 101 void (*free_irq)(struct vop_device *vpdev, 102 struct mic_irq *cookie, void *data); 103 void (*ack_interrupt)(struct vop_device *vpdev, int num); 104 void __iomem * (*get_remote_dp)(struct vop_device *vpdev); 105 void * (*get_dp)(struct vop_device *vpdev); 106 void (*send_intr)(struct vop_device *vpdev, int db); 107 void __iomem * (*ioremap)(struct vop_device *vpdev, 108 dma_addr_t pa, size_t len); 109 void (*iounmap)(struct vop_device *vpdev, void __iomem *va); 110}; 111 112struct vop_device * 113vop_register_device(struct device *pdev, int id, 114 const struct dma_map_ops *dma_ops, 115 struct vop_hw_ops *hw_ops, u8 dnode, struct mic_mw *aper, 116 struct dma_chan *chan); 117void vop_unregister_device(struct vop_device *dev); 118int vop_register_driver(struct vop_driver *drv); 119void vop_unregister_driver(struct vop_driver *drv); 120 121/* 122 * module_vop_driver() - Helper macro for drivers that don't do 123 * anything special in module init/exit. This eliminates a lot of 124 * boilerplate. Each module may only use this macro once, and 125 * calling it replaces module_init() and module_exit() 126 */ 127#define module_vop_driver(__vop_driver) \ 128 module_driver(__vop_driver, vop_register_driver, \ 129 vop_unregister_driver) 130 131static inline struct vop_device *dev_to_vop(struct device *dev) 132{ 133 return container_of(dev, struct vop_device, dev); 134} 135 136static inline struct vop_driver *drv_to_vop(struct device_driver *drv) 137{ 138 return container_of(drv, struct vop_driver, driver); 139} 140#endif /* _VOP_BUS_H */ 141