xref: /openbmc/linux/arch/powerpc/include/asm/vio.h (revision cb52d8970eee65bf2c47d9a91bd4f58b17f595f4)
1b8b572e1SStephen Rothwell /*
2b8b572e1SStephen Rothwell  * IBM PowerPC Virtual I/O Infrastructure Support.
3b8b572e1SStephen Rothwell  *
4b8b572e1SStephen Rothwell  * Copyright (c) 2003 IBM Corp.
5b8b572e1SStephen Rothwell  *  Dave Engebretsen engebret@us.ibm.com
6b8b572e1SStephen Rothwell  *  Santiago Leon santil@us.ibm.com
7b8b572e1SStephen Rothwell  *
8b8b572e1SStephen Rothwell  * This program is free software; you can redistribute it and/or
9b8b572e1SStephen Rothwell  * modify it under the terms of the GNU General Public License
10b8b572e1SStephen Rothwell  * as published by the Free Software Foundation; either version
11b8b572e1SStephen Rothwell  * 2 of the License, or (at your option) any later version.
12b8b572e1SStephen Rothwell  */
13b8b572e1SStephen Rothwell 
14b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_VIO_H
15b8b572e1SStephen Rothwell #define _ASM_POWERPC_VIO_H
16b8b572e1SStephen Rothwell #ifdef __KERNEL__
17b8b572e1SStephen Rothwell 
18b8b572e1SStephen Rothwell #include <linux/init.h>
19b8b572e1SStephen Rothwell #include <linux/errno.h>
20b8b572e1SStephen Rothwell #include <linux/device.h>
21b8b572e1SStephen Rothwell #include <linux/dma-mapping.h>
22b8b572e1SStephen Rothwell #include <linux/mod_devicetable.h>
23b8b572e1SStephen Rothwell 
24b8b572e1SStephen Rothwell #include <asm/hvcall.h>
25b8b572e1SStephen Rothwell #include <asm/scatterlist.h>
26b8b572e1SStephen Rothwell 
27b8b572e1SStephen Rothwell /*
28b8b572e1SStephen Rothwell  * Architecture-specific constants for drivers to
29b8b572e1SStephen Rothwell  * extract attributes of the device using vio_get_attribute()
30b8b572e1SStephen Rothwell  */
31b8b572e1SStephen Rothwell #define VETH_MAC_ADDR "local-mac-address"
32b8b572e1SStephen Rothwell #define VETH_MCAST_FILTER_SIZE "ibm,mac-address-filters"
33b8b572e1SStephen Rothwell 
34b8b572e1SStephen Rothwell /* End architecture-specific constants */
35b8b572e1SStephen Rothwell 
36b8b572e1SStephen Rothwell #define h_vio_signal(ua, mode) \
37b8b572e1SStephen Rothwell   plpar_hcall_norets(H_VIO_SIGNAL, ua, mode)
38b8b572e1SStephen Rothwell 
39b8b572e1SStephen Rothwell #define VIO_IRQ_DISABLE		0UL
40b8b572e1SStephen Rothwell #define VIO_IRQ_ENABLE		1UL
41b8b572e1SStephen Rothwell 
42b8b572e1SStephen Rothwell /*
43b8b572e1SStephen Rothwell  * VIO CMO minimum entitlement for all devices and spare entitlement
44b8b572e1SStephen Rothwell  */
45b8b572e1SStephen Rothwell #define VIO_CMO_MIN_ENT 1562624
46b8b572e1SStephen Rothwell 
47b8b572e1SStephen Rothwell struct iommu_table;
48b8b572e1SStephen Rothwell 
49b8b572e1SStephen Rothwell /**
50b8b572e1SStephen Rothwell  * vio_dev - This structure is used to describe virtual I/O devices.
51b8b572e1SStephen Rothwell  *
52b8b572e1SStephen Rothwell  * @desired: set from return of driver's get_desired_dma() function
53b8b572e1SStephen Rothwell  * @entitled: bytes of IO data that has been reserved for this device.
54b8b572e1SStephen Rothwell  * @allocated: bytes of IO data currently in use by the device.
55b8b572e1SStephen Rothwell  * @allocs_failed: number of DMA failures due to insufficient entitlement.
56b8b572e1SStephen Rothwell  */
57b8b572e1SStephen Rothwell struct vio_dev {
58b8b572e1SStephen Rothwell 	const char *name;
59b8b572e1SStephen Rothwell 	const char *type;
60b8b572e1SStephen Rothwell 	uint32_t unit_address;
61b8b572e1SStephen Rothwell 	unsigned int irq;
62b8b572e1SStephen Rothwell 	struct {
63b8b572e1SStephen Rothwell 		size_t desired;
64b8b572e1SStephen Rothwell 		size_t entitled;
65b8b572e1SStephen Rothwell 		size_t allocated;
66b8b572e1SStephen Rothwell 		atomic_t allocs_failed;
67b8b572e1SStephen Rothwell 	} cmo;
68b8b572e1SStephen Rothwell 	struct device dev;
69b8b572e1SStephen Rothwell };
70b8b572e1SStephen Rothwell 
71b8b572e1SStephen Rothwell struct vio_driver {
72*cb52d897SBenjamin Herrenschmidt 	const char *name;
73b8b572e1SStephen Rothwell 	const struct vio_device_id *id_table;
74b8b572e1SStephen Rothwell 	int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
75b8b572e1SStephen Rothwell 	int (*remove)(struct vio_dev *dev);
76b8b572e1SStephen Rothwell 	/* A driver must have a get_desired_dma() function to
77b8b572e1SStephen Rothwell 	 * be loaded in a CMO environment if it uses DMA.
78b8b572e1SStephen Rothwell 	 */
79b8b572e1SStephen Rothwell 	unsigned long (*get_desired_dma)(struct vio_dev *dev);
80*cb52d897SBenjamin Herrenschmidt 	const struct dev_pm_ops *pm;
81b8b572e1SStephen Rothwell 	struct device_driver driver;
82b8b572e1SStephen Rothwell };
83b8b572e1SStephen Rothwell 
84*cb52d897SBenjamin Herrenschmidt extern int __vio_register_driver(struct vio_driver *drv, struct module *owner,
85*cb52d897SBenjamin Herrenschmidt 				 const char *mod_name);
86*cb52d897SBenjamin Herrenschmidt /*
87*cb52d897SBenjamin Herrenschmidt  * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
88*cb52d897SBenjamin Herrenschmidt  */
89*cb52d897SBenjamin Herrenschmidt #define vio_register_driver(driver)		\
90*cb52d897SBenjamin Herrenschmidt 	__vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
91b8b572e1SStephen Rothwell extern void vio_unregister_driver(struct vio_driver *drv);
92b8b572e1SStephen Rothwell 
93b8b572e1SStephen Rothwell extern int vio_cmo_entitlement_update(size_t);
94b8b572e1SStephen Rothwell extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired);
95b8b572e1SStephen Rothwell 
96b8b572e1SStephen Rothwell extern void __devinit vio_unregister_device(struct vio_dev *dev);
97b8b572e1SStephen Rothwell 
98b8b572e1SStephen Rothwell struct device_node;
99b8b572e1SStephen Rothwell 
100b8b572e1SStephen Rothwell extern struct vio_dev *vio_register_device_node(
101b8b572e1SStephen Rothwell 		struct device_node *node_vdev);
102b8b572e1SStephen Rothwell extern const void *vio_get_attribute(struct vio_dev *vdev, char *which,
103b8b572e1SStephen Rothwell 		int *length);
104b8b572e1SStephen Rothwell #ifdef CONFIG_PPC_PSERIES
105b8b572e1SStephen Rothwell extern struct vio_dev *vio_find_node(struct device_node *vnode);
106b8b572e1SStephen Rothwell extern int vio_enable_interrupts(struct vio_dev *dev);
107b8b572e1SStephen Rothwell extern int vio_disable_interrupts(struct vio_dev *dev);
108b8b572e1SStephen Rothwell #else
109b8b572e1SStephen Rothwell static inline int vio_enable_interrupts(struct vio_dev *dev)
110b8b572e1SStephen Rothwell {
111b8b572e1SStephen Rothwell 	return 0;
112b8b572e1SStephen Rothwell }
113b8b572e1SStephen Rothwell #endif
114b8b572e1SStephen Rothwell 
115b8b572e1SStephen Rothwell static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
116b8b572e1SStephen Rothwell {
117b8b572e1SStephen Rothwell 	return container_of(drv, struct vio_driver, driver);
118b8b572e1SStephen Rothwell }
119b8b572e1SStephen Rothwell 
120b8b572e1SStephen Rothwell static inline struct vio_dev *to_vio_dev(struct device *dev)
121b8b572e1SStephen Rothwell {
122b8b572e1SStephen Rothwell 	return container_of(dev, struct vio_dev, dev);
123b8b572e1SStephen Rothwell }
124b8b572e1SStephen Rothwell 
125b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
126b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_VIO_H */
127