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