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