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