xref: /linux/arch/powerpc/include/asm/vio.h (revision c4ee0af3fa0dc65f690fc908f02b8355f9576ea0)
1 /*
2  * IBM PowerPC Virtual I/O Infrastructure Support.
3  *
4  * Copyright (c) 2003 IBM Corp.
5  *  Dave Engebretsen engebret@us.ibm.com
6  *  Santiago Leon santil@us.ibm.com
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version
11  * 2 of the License, or (at your option) any later version.
12  */
13 
14 #ifndef _ASM_POWERPC_VIO_H
15 #define _ASM_POWERPC_VIO_H
16 #ifdef __KERNEL__
17 
18 #include <linux/init.h>
19 #include <linux/errno.h>
20 #include <linux/device.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/mod_devicetable.h>
23 
24 #include <asm/hvcall.h>
25 #include <asm/scatterlist.h>
26 
27 /*
28  * Architecture-specific constants for drivers to
29  * extract attributes of the device using vio_get_attribute()
30  */
31 #define VETH_MAC_ADDR "local-mac-address"
32 #define VETH_MCAST_FILTER_SIZE "ibm,mac-address-filters"
33 
34 /* End architecture-specific constants */
35 
36 #define h_vio_signal(ua, mode) \
37   plpar_hcall_norets(H_VIO_SIGNAL, ua, mode)
38 
39 #define VIO_IRQ_DISABLE		0UL
40 #define VIO_IRQ_ENABLE		1UL
41 
42 /*
43  * VIO CMO minimum entitlement for all devices and spare entitlement
44  */
45 #define VIO_CMO_MIN_ENT 1562624
46 
47 extern struct bus_type vio_bus_type;
48 
49 struct iommu_table;
50 
51 /*
52  * Platform Facilities Option (PFO)-specific data
53  */
54 
55 /* Starting unit address for PFO devices on the VIO BUS */
56 #define VIO_BASE_PFO_UA	0x50000000
57 
58 /**
59  * vio_pfo_op - PFO operation parameters
60  *
61  * @flags: h_call subfunctions and modifiers
62  * @in: Input data block logical real address
63  * @inlen: If non-negative, the length of the input data block.  If negative,
64  *	the length of the input data descriptor list in bytes.
65  * @out: Output data block logical real address
66  * @outlen: If non-negative, the length of the input data block.  If negative,
67  *	the length of the input data descriptor list in bytes.
68  * @csbcpb: Logical real address of the 4k naturally-aligned storage block
69  *	containing the CSB & optional FC field specific CPB
70  * @timeout: # of milliseconds to retry h_call, 0 for no timeout.
71  * @hcall_err: pointer to return the h_call return value, else NULL
72  */
73 struct vio_pfo_op {
74 	u64 flags;
75 	s64 in;
76 	s64 inlen;
77 	s64 out;
78 	s64 outlen;
79 	u64 csbcpb;
80 	void *done;
81 	unsigned long handle;
82 	unsigned int timeout;
83 	long hcall_err;
84 };
85 
86 /* End PFO specific data */
87 
88 enum vio_dev_family {
89 	VDEVICE,	/* The OF node is a child of /vdevice */
90 	PFO,		/* The OF node is a child of /ibm,platform-facilities */
91 };
92 
93 /**
94  * vio_dev - This structure is used to describe virtual I/O devices.
95  *
96  * @desired: set from return of driver's get_desired_dma() function
97  * @entitled: bytes of IO data that has been reserved for this device.
98  * @allocated: bytes of IO data currently in use by the device.
99  * @allocs_failed: number of DMA failures due to insufficient entitlement.
100  */
101 struct vio_dev {
102 	const char *name;
103 	const char *type;
104 	uint32_t unit_address;
105 	uint32_t resource_id;
106 	unsigned int irq;
107 	struct {
108 		size_t desired;
109 		size_t entitled;
110 		size_t allocated;
111 		atomic_t allocs_failed;
112 	} cmo;
113 	enum vio_dev_family family;
114 	struct device dev;
115 };
116 
117 struct vio_driver {
118 	const char *name;
119 	const struct vio_device_id *id_table;
120 	int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
121 	int (*remove)(struct vio_dev *dev);
122 	/* A driver must have a get_desired_dma() function to
123 	 * be loaded in a CMO environment if it uses DMA.
124 	 */
125 	unsigned long (*get_desired_dma)(struct vio_dev *dev);
126 	const struct dev_pm_ops *pm;
127 	struct device_driver driver;
128 };
129 
130 extern int __vio_register_driver(struct vio_driver *drv, struct module *owner,
131 				 const char *mod_name);
132 /*
133  * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
134  */
135 #define vio_register_driver(driver)		\
136 	__vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
137 extern void vio_unregister_driver(struct vio_driver *drv);
138 
139 extern int vio_cmo_entitlement_update(size_t);
140 extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired);
141 
142 extern void vio_unregister_device(struct vio_dev *dev);
143 
144 extern int vio_h_cop_sync(struct vio_dev *vdev, struct vio_pfo_op *op);
145 
146 struct device_node;
147 
148 extern struct vio_dev *vio_register_device_node(
149 		struct device_node *node_vdev);
150 extern const void *vio_get_attribute(struct vio_dev *vdev, char *which,
151 		int *length);
152 #ifdef CONFIG_PPC_PSERIES
153 extern struct vio_dev *vio_find_node(struct device_node *vnode);
154 extern int vio_enable_interrupts(struct vio_dev *dev);
155 extern int vio_disable_interrupts(struct vio_dev *dev);
156 #else
157 static inline int vio_enable_interrupts(struct vio_dev *dev)
158 {
159 	return 0;
160 }
161 #endif
162 
163 static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
164 {
165 	return container_of(drv, struct vio_driver, driver);
166 }
167 
168 static inline struct vio_dev *to_vio_dev(struct device *dev)
169 {
170 	return container_of(dev, struct vio_dev, dev);
171 }
172 
173 #endif /* __KERNEL__ */
174 #endif /* _ASM_POWERPC_VIO_H */
175