Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * IBM PowerPC Virtual I/O Infrastructure Support.
0004  *
0005  * Copyright (c) 2003 IBM Corp.
0006  *  Dave Engebretsen engebret@us.ibm.com
0007  *  Santiago Leon santil@us.ibm.com
0008  */
0009 
0010 #ifndef _ASM_POWERPC_VIO_H
0011 #define _ASM_POWERPC_VIO_H
0012 #ifdef __KERNEL__
0013 
0014 #include <linux/errno.h>
0015 #include <linux/device.h>
0016 #include <linux/dma-mapping.h>
0017 #include <linux/mod_devicetable.h>
0018 #include <linux/scatterlist.h>
0019 
0020 #include <asm/hvcall.h>
0021 
0022 /*
0023  * Architecture-specific constants for drivers to
0024  * extract attributes of the device using vio_get_attribute()
0025  */
0026 #define VETH_MAC_ADDR "local-mac-address"
0027 #define VETH_MCAST_FILTER_SIZE "ibm,mac-address-filters"
0028 
0029 /* End architecture-specific constants */
0030 
0031 #define h_vio_signal(ua, mode) \
0032   plpar_hcall_norets(H_VIO_SIGNAL, ua, mode)
0033 
0034 #define VIO_IRQ_DISABLE     0UL
0035 #define VIO_IRQ_ENABLE      1UL
0036 
0037 /*
0038  * VIO CMO minimum entitlement for all devices and spare entitlement
0039  */
0040 #define VIO_CMO_MIN_ENT 1562624
0041 
0042 extern struct bus_type vio_bus_type;
0043 
0044 struct iommu_table;
0045 
0046 /*
0047  * Platform Facilities Option (PFO)-specific data
0048  */
0049 
0050 /* Starting unit address for PFO devices on the VIO BUS */
0051 #define VIO_BASE_PFO_UA 0x50000000
0052 
0053 /**
0054  * vio_pfo_op - PFO operation parameters
0055  *
0056  * @flags: h_call subfunctions and modifiers
0057  * @in: Input data block logical real address
0058  * @inlen: If non-negative, the length of the input data block.  If negative,
0059  *  the length of the input data descriptor list in bytes.
0060  * @out: Output data block logical real address
0061  * @outlen: If non-negative, the length of the input data block.  If negative,
0062  *  the length of the input data descriptor list in bytes.
0063  * @csbcpb: Logical real address of the 4k naturally-aligned storage block
0064  *  containing the CSB & optional FC field specific CPB
0065  * @timeout: # of milliseconds to retry h_call, 0 for no timeout.
0066  * @hcall_err: pointer to return the h_call return value, else NULL
0067  */
0068 struct vio_pfo_op {
0069     u64 flags;
0070     s64 in;
0071     s64 inlen;
0072     s64 out;
0073     s64 outlen;
0074     u64 csbcpb;
0075     void *done;
0076     unsigned long handle;
0077     unsigned int timeout;
0078     long hcall_err;
0079 };
0080 
0081 /* End PFO specific data */
0082 
0083 enum vio_dev_family {
0084     VDEVICE,    /* The OF node is a child of /vdevice */
0085     PFO,        /* The OF node is a child of /ibm,platform-facilities */
0086 };
0087 
0088 /**
0089  * vio_dev - This structure is used to describe virtual I/O devices.
0090  *
0091  * @desired: set from return of driver's get_desired_dma() function
0092  * @entitled: bytes of IO data that has been reserved for this device.
0093  * @allocated: bytes of IO data currently in use by the device.
0094  * @allocs_failed: number of DMA failures due to insufficient entitlement.
0095  */
0096 struct vio_dev {
0097     const char *name;
0098     const char *type;
0099     uint32_t unit_address;
0100     uint32_t resource_id;
0101     unsigned int irq;
0102     struct {
0103         size_t desired;
0104         size_t entitled;
0105         size_t allocated;
0106         atomic_t allocs_failed;
0107     } cmo;
0108     enum vio_dev_family family;
0109     struct device dev;
0110 };
0111 
0112 struct vio_driver {
0113     const char *name;
0114     const struct vio_device_id *id_table;
0115     int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
0116     void (*remove)(struct vio_dev *dev);
0117     void (*shutdown)(struct vio_dev *dev);
0118     /* A driver must have a get_desired_dma() function to
0119      * be loaded in a CMO environment if it uses DMA.
0120      */
0121     unsigned long (*get_desired_dma)(struct vio_dev *dev);
0122     const struct dev_pm_ops *pm;
0123     struct device_driver driver;
0124 };
0125 
0126 extern int __vio_register_driver(struct vio_driver *drv, struct module *owner,
0127                  const char *mod_name);
0128 /*
0129  * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
0130  */
0131 #define vio_register_driver(driver)     \
0132     __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
0133 extern void vio_unregister_driver(struct vio_driver *drv);
0134 
0135 extern int vio_cmo_entitlement_update(size_t);
0136 extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired);
0137 
0138 extern void vio_unregister_device(struct vio_dev *dev);
0139 
0140 extern int vio_h_cop_sync(struct vio_dev *vdev, struct vio_pfo_op *op);
0141 
0142 struct device_node;
0143 
0144 extern struct vio_dev *vio_register_device_node(
0145         struct device_node *node_vdev);
0146 extern const void *vio_get_attribute(struct vio_dev *vdev, char *which,
0147         int *length);
0148 #ifdef CONFIG_PPC_PSERIES
0149 extern struct vio_dev *vio_find_node(struct device_node *vnode);
0150 extern int vio_enable_interrupts(struct vio_dev *dev);
0151 extern int vio_disable_interrupts(struct vio_dev *dev);
0152 #else
0153 static inline int vio_enable_interrupts(struct vio_dev *dev)
0154 {
0155     return 0;
0156 }
0157 #endif
0158 
0159 static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
0160 {
0161     return container_of(drv, struct vio_driver, driver);
0162 }
0163 
0164 static inline struct vio_dev *to_vio_dev(struct device *dev)
0165 {
0166     return container_of(dev, struct vio_dev, dev);
0167 }
0168 
0169 #endif /* __KERNEL__ */
0170 #endif /* _ASM_POWERPC_VIO_H */