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