mirror of
https://github.com/LineageOS/android_kernel_fxtec_sm6115.git
synced 2026-08-20 03:21:11 +00:00
version 4.19.325-cip128 * tag 'v4.19.325-cip128' of https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip: CIP: Bump version suffix to -cip128 after merge from cip/linux-4.19.y-st tree Update localversion-st, tree is up-to-date with 5.10.248. NFSv4: ensure the open stateid seqid doesn't go backwards libceph: make calc_target() set t->paused, not just clear it crypto: af_alg - zero initialize memory allocated via sock_kmalloc jbd2: fix the inconsistency between checksum and data in memory for journal sb f2fs: fix to detect recoverable inode during dryrun of find_fsync_dnodes() NFS: add barriers when testing for NFS_FSDATA_BLOCKED NFS: unlink/rmdir shouldn't call d_delete() twice on ENOENT efi/cper: Fix cper_bits_to_str buffer handling and return value iommu/omap: fix device leaks on probe_device() crypto: seqiv - Do not use req->iv after crypto_aead_encrypt f2fs: fix return value of f2fs_recover_fsync_data() ext4: improve integrity checking in __mb_check_buddy by enhancing order-0 validation ext4: remove unused return value of __mb_check_buddy clk: renesas: r9a06g032: Fix memory leak in error path nbd: defer config put in recv_work jbd2: avoid bug_on in jbd2_journal_get_create_access() when file system corrupted scsi: sg: Fix occasional bogus elapsed time that exceeds timeout powercap: fix sscanf() error return value handling powercap: fix race condition in register_control_type() arp: do not assume dev_hard_header() does not change skb->head net: usb: pegasus: fix memory leak in update_eth_regs_async() HID: quirks: work around VID/PID conflict for appledisplay netdev: preserve NETIF_F_ALL_FOR_ALL across TSO updates net: sock: fix hardened usercopy panic in sock_recv_errqueue inet: ping: Fix icmp out counting netfilter: nf_conncount: update last_gc only when GC has been performed ARM: dts: imx6q-ba16: fix RTC interrupt level scsi: ipr: Enable/disable IRQD_NO_BALANCING during reset alpha: don't reference obsolete termio struct for TC* constants ARM: 9461/1: Disable HIGHPTE on PREEMPT_RT kernels ext4: fix out-of-bound read in ext4_xattr_inode_dec_ref_all() ext4: introduce ITAIL helper libceph: make free_choose_arg_map() resilient to partial allocation libceph: replace overzealous BUG_ON in osdmap_apply_incremental() wifi: avoid kernel-infoleak from struct iw_point drm/pl111: Fix error handling in pl111_amba_probe net: 3com: 3c59x: fix possible null dereference in vortex_probe1() atm: Fix dma_free_coherent() size Revert "iommu/amd: Skip enabling command/event buffers for kdump" pwm: stm32: Always program polarity bus: fsl-mc-bus: fix KASAN use-after-free in fsl_mc_bus_remove() scsi: iscsi_tcp: Fix UAF during logout when accessing the shost ipaddress scsi: iscsi: Move pool freeing wifi: mac80211: Discard Beacon frames to non-broadcast address media: samsung: exynos4-is: fix potential ABBA deadlock on init media: vpif_capture: fix section mismatch media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled SUNRPC: svcauth_gss: avoid NULL deref on zero length gss_token in gss_read_proxy_verf NFSD: Clear SECLABEL in the suppattr_exclcreat bitmap usb: ohci-nxp: fix device leak on probe failure usb: ohci-nxp: Use helper function devm_clk_get_enabled() f2fs: fix to avoid updating zero-sized extent in extent cache ext4: fix string copying in parse_apply_sb_mount_options() ALSA: wavefront: Fix integer overflow in sample size validation ALSA: wavefront: Clear substream pointers on close usb: gadget: udc: fix use-after-free in usb_gadget_state_work HID: core: Harden s32ton() against conversion to 0 bits ipv4: Fix uninit-value access in __ip_make_skb() ipv6: Fix potential uninit-value access in __ip6_make_skb() virtio_console: fix order of fields cols and rows drm/nouveau/dispnv50: Don't call drm_atomic_get_crtc_state() in prepare_fb net: nfc: fix deadlock between nfc_unregister_device and rfkill_fop_write net: usb: sr9700: fix incorrect command used to write single register fjes: Add missing iounmap in fjes_hw_init() e1000: fix OOB in e1000_tbi_should_accept() RDMA/core: Check for the presence of LS_NLA_TYPE_DGID correctly media: i2c: adv7842: Remove redundant cancel_delayed_work in probe media: i2c: ADV7604: Remove redundant cancel_delayed_work in probe media: TDA1997x: Remove redundant cancel_delayed_work in probe media: msp3400: Avoid possible out-of-bounds array accesses in msp3400c_thread() media: cec: Fix debugfs leak on bus_register() failure fbdev: tcx.c fix mem_map to correct smem_start offset fbdev: pxafb: Fix multiple clamped values in pxafb_adjust_timing fbdev: gbefb: fix to use physical address instead of dma address media: adv7842: Avoid possible out-of-bounds array accesses in adv7842_cp_log_status() parisc: entry: set W bit for !compat tasks in syscall_restore_rfi() parisc: entry.S: fix space adjustment on interruption for 64-bit userspace media: rc: st_rc: Fix reset control resource leak PCI/PM: Reinstate clearing state_saved in legacy and !PM codepaths iommu/exynos: fix device leak on of_xlate() ASoC: qcom: qdsp6: q6asm-dai: set 10 ms period and buffer alignment. ASoC: qcom: q6adm: the the copp device only during last instance ASoC: qcom: q6asm-dai: perform correct state check before closing selftests/ftrace: traceonoff_triggers: strip off names RDMA/bnxt_re: fix dma_free_coherent() pointer net: rose: fix invalid array index in rose_kill_by_device() ipv4: Fix reference count leak when using error routes with nexthop objects ipv6: BUG() in pskb_expand_head() as part of calipso_skbuff_setattr() net: bridge: Describe @tunnel_hash member in net_bridge_vlan_group struct net: dsa: b53: skip multicast entries for fdb_dump() firewire: nosy: Fix dma_free_coherent() size firewire: nosy: switch from 'pci_' to 'dma_' API genalloc.h: fix htmldocs warning net: usb: rtl8150: fix memory leak on usb_submit_urb() failure team: fix check for port enabled in team_queue_override_port_prio_changed() platform/x86: ibm_rtl: fix EBDA signature search pointer arithmetic platform/x86: msi-laptop: add missing sysfs_remove_group() ip6_gre: make ip6gre_header() robust i40e: fix scheduling in set_rx_mode hwmon: (w83l786ng) Convert macros to functions to avoid TOCTOU hwmon: (w83791d) Convert macros to functions to avoid TOCTOU rpmsg: glink: fix rpmsg device leak amba: tegra-ahb: Fix device leak on SMMU enable nfsd: Mark variable __maybe_unused to avoid W=1 build break PM: runtime: Do not clear needs_force_resume with enabled runtime PM tracing: Do not register unsupported perf events KVM: x86: Fix VM hard lockup after prolonged inactivity with periodic HV timer KVM: x86: Explicitly set new periodic hrtimer expiration in apic_timer_fn() KVM: x86: WARN if hrtimer callback for periodic APIC timer fires with period=0 libceph: make decode_pool() more resilient against corrupted osdmaps parisc: Do not reprogram affinitiy on ASP chip ocfs2: fix kernel BUG in ocfs2_find_victim_chain tools/testing/nvdimm: Use per-DIMM device handle f2fs: invalidate dentry cache on failed whiteout creation scsi: target: Reset t_task_cdb pointer in error case NFSD: use correct reservation type in nfsd4_scsi_fence_client scsi: aic94xx: fix use-after-free in device removal path cpufreq: nforce2: fix reference count leak in nforce2 char: applicom: fix NULL pointer dereference in ac_ioctl usb: renesas_usbhs: Fix a resource leak in usbhs_pipe_malloc() media: pvrusb2: Fix incorrect variable used in trace message media: dvb-usb: dtv5100: fix out-of-bounds in dtv5100_i2c_msg() usb: usb-storage: Maintain minimal modifications to the bcdDevice range. media: v4l2-mem2mem: Fix outdated documentation jbd2: use a weaker annotation in journal handling ext4: fix incorrect group number assertion in mb_check_buddy ext4: xattr: fix null pointer deref in ext4_raw_inode() ktest.pl: Fix uninitialized var in config-bisect.pl floppy: fix for PAGE_SIZE != 4KB usb: usb-storage: No additional quirks need to be added to the EL-R12 optical drive. usb: xhci: limit run_graceperiod for only usb 3.0 devices usb: typec: ucsi: Handle incorrect num_connectors capability via_wdt: fix critical boot hang due to unnamed resource allocation scsi: qla2xxx: Use reinit_completion on mbx_intr_comp powerpc/addnote: Fix overflow on 32-bit builds clk: mvebu: cp110 add CLK_IGNORE_UNUSED to pcie_x10, pcie_x11 & pcie_x4 ipmi: Fix __scan_channels() failing to rescan channels ipmi: Fix the race between __scan_channels() and deliver_response() ALSA: usb-mixer: us16x08: validate meter packet indices ALSA: pcmcia: Fix resource leak in snd_pdacf_probe error path ALSA: vxpocket: Fix resource leak in vxpocket_probe error path spi: fsl-cpm: Check length parity before switching to 16 bit mode Input: ti_am335x_tsc - fix off-by-one error in wire_order validation MIPS: Fix a reference leak bug in ip22_check_gio() hwmon: (ibmpex) fix use-after-free in high/low store net/mlx5: fw_tracer, Handle escaped percent properly net/mlx5: fw_tracer, Validate format string parameters net/mlx5: fw_tracer, Add support for unrecognized string nfc: pn533: Fix error code in pn533_acr122_poweron_rdr() caif: fix integer underflow in cffrml_receive() ipvs: fix ipv4 null-ptr-deref in route error path netfilter: nf_conncount: fix leaked ct in error paths broadcom: b44: prevent uninitialized value usage net: openvswitch: fix middle attribute validation in push_nsh() action mlxsw: spectrum_router: Fix neighbour use-after-free ipvlan: Ignore PACKET_LOOPBACK in handle_mode_l2() netrom: Fix memory leak in nr_sendmsg() btrfs: scrub: always update btrfs_scrub_progress::last_physical hfsplus: fix volume corruption issue for generic/073 hfsplus: Verify inode mode when loading from disk hfsplus: fix missing hfs_bnode_get() in __hfs_bnode_create hfsplus: fix volume corruption issue for generic/070 cpufreq: s5pv210: fix refcount leak ACPI: property: Use ACPI functions in acpi_graph_get_next_endpoint() only ACPICA: Avoid walking the Namespace if start_node is NULL netfilter: nft_connlimit: memleak if nf_ct_netns_get() fails netfilter: nf_conncount: garbage collection is not skipped when jiffies wrap around NFS: Fix missing unlock in nfs_unlink() ALSA: dice: fix buffer overflow in detect_stream_formats() usb: phy: Initialize struct usb_phy list_head ocfs2: fix memory leak in ocfs2_merge_rec_left() efi/cper: Adjust infopfx size to accept an extra space efi/cper: Add a new helper function to print bitmasks dm log-writes: Add missing set_freezable() for freezable kthread dm-raid: fix possible NULL dereference with undefined raid type ARM: 9464/1: fix input-only operand modification in load_unaligned_zeropad() ALSA: uapi: Fix typo in asound.h comment fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8() NFSv4/pNFS: Clear NFS_INO_LAYOUTCOMMIT in pnfs_mark_layout_stateid_invalid fs/nls: Fix utf16 to utf8 conversion NFS: don't unhash dentry during unlink/rename NFS: Label the dentry with a verifier in nfs_rmdir() and nfs_unlink() fbdev: ssd1307fb: fix potential page leak in ssd1307fb_probe() pinctrl: single: Fix incorrect type for error return variable pinctrl: single: Fix PIN_CONFIG_BIAS_DISABLE handling perf tools: Fix split kallsyms DSO counting net/sched: sch_cake: Fix incorrect qlen reduction in cake_drop mtd: lpddr_cmds: fix signed shifts in lpddr_cmds netfilter: nft_connlimit: update the count if add was skipped netfilter: nf_conncount: rework API to use sk_buff directly netfilter: nf_conncount: reduce unnecessary GC netfilter: nft_connlimit: move stateful fields out of expression data regulator: core: Protect regulator_supply_alias_list with regulator_list_mutex virtio: fix virtqueue_set_affinity() docs ACPI: processor_core: fix map_x2apic_id for amd-pstate on am4 backlight: lp855x: Fix lp855x.h kernel-doc warnings staging: fbtft: core: fix potential memory leak in fbtft_probe_common() usb: dwc2: fix hang during shutdown if set as peripheral usb: dwc2: disable platform lowlevel hw resources during shutdown usb: chaoskey: fix locking for O_NONBLOCK wifi: rtl818x: rtl8187: Fix potential buffer underflow in rtl8187_rx_cb() powerpc/64s/ptdump: Fix kernel_hash_pagetable dump for ISA v3.00 HPTE format NFSD/blocklayout: Fix minlength check in proc_layoutget scsi: sim710: Fix resource leak by adding missing ioport_unmap() calls ACPI: property: Fix fwnode refcount leak in acpi_fwnode_graph_parse_endpoint() ocfs2: relax BUG() to ocfs2_error() in __ocfs2_move_extent() nbd: defer config unlock in nbd_genl_connect wifi: cw1200: Fix potential memory leak in cw1200_bh_rx_helper() macintosh/mac_hid: fix race condition in mac_hid_toggle_emumouse scsi: stex: Fix reboot_notifier leak in probe error path perf/x86/intel: Correct large PEBS flag check ext4: correct the checking of quota files before moving extents ext4: minor defrag code improvements mfd: da9055: Fix missing regmap_del_irq_chip() in error path scsi: target: Do not write NUL characters into ASCII configfs output power: supply: apm_power: only unset own apm_get_power_status power: supply: wm831x: Check wm831x_set_bits() return value kmsan: introduce __no_sanitize_memory and __no_kmsan_checks compiler-gcc.h: Define __SANITIZE_ADDRESS__ under hwaddress sanitizer s390/smp: Fix fallback CPU detection crypto: asymmetric_keys - prevent overflow in asymmetric_key_generate_id inet: Avoid ehash lookup race in inet_ehash_insert() rculist: Add hlist_nulls_replace_rcu() and hlist_nulls_replace_init_rcu() irqchip/qcom-irq-combiner: Fix section mismatch USB: Fix descriptor count when handling invalid MBIM extended descriptor drm/vgem-fence: Fix potential deadlock on release smack: fix bug: unprivileged task can create labels staging: rtl8723bs: fix stack buffer overflow in OnAssocReq IE parsing comedi: multiq3: sanitize config options in multiq3_attach() comedi: c6xdigio: Fix invalid PNP driver unregistration platform/x86: acer-wmi: Ignore backlight event bfs: Reconstruct file type when loading from disk spi: imx: keep dma request disabled before dma transfer setup spi: xilinx: increase number of retries before declaring stall USB: serial: kobil_sct: fix TIOCMBIS and TIOCMBIC USB: serial: belkin_sa: fix TIOCMBIS and TIOCMBIC serial: add support of CPCI cards USB: serial: ftdi_sio: match on interface number for jtag USB: serial: option: move Telit 0x10c7 composition in the right place USB: serial: option: add Telit Cinterion FE910C04 new compositions USB: serial: option: add Foxconn T99W760 ext4: add i_data_sem protection in ext4_destroy_inline_data_nolock() locking/spinlock/debug: Fix data-race in do_raw_write_lock ext4: refresh inline data size before write operations xfrm: flush all states in xfrm_state_fini xfrm: also call xfrm_state_delete_tunnel at destroy time for states that were never added Revert "xfrm: destroy xfrm_state synchronously on net exit path" xfrm: delete x->tunnel as we delete x Conflicts: drivers/rpmsg/qcom_glink_native.c drivers/usb/host/xhci-hub.c fs/f2fs/file.c fs/f2fs/super.c Change-Id: I9e00c074af0214588acc89a73fcfc928d1724b7a
528 lines
15 KiB
C
528 lines
15 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_VIRTIO_CONFIG_H
|
|
#define _LINUX_VIRTIO_CONFIG_H
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/bug.h>
|
|
#include <linux/virtio.h>
|
|
#include <linux/virtio_byteorder.h>
|
|
#include <uapi/linux/virtio_config.h>
|
|
|
|
struct irq_affinity;
|
|
|
|
struct virtio_shm_region {
|
|
u64 addr;
|
|
u64 len;
|
|
};
|
|
|
|
/**
|
|
* virtio_config_ops - operations for configuring a virtio device
|
|
* @get: read the value of a configuration field
|
|
* vdev: the virtio_device
|
|
* offset: the offset of the configuration field
|
|
* buf: the buffer to write the field value into.
|
|
* len: the length of the buffer
|
|
* @set: write the value of a configuration field
|
|
* vdev: the virtio_device
|
|
* offset: the offset of the configuration field
|
|
* buf: the buffer to read the field value from.
|
|
* len: the length of the buffer
|
|
* @generation: config generation counter
|
|
* vdev: the virtio_device
|
|
* Returns the config generation counter
|
|
* @get_status: read the status byte
|
|
* vdev: the virtio_device
|
|
* Returns the status byte
|
|
* @set_status: write the status byte
|
|
* vdev: the virtio_device
|
|
* status: the new status byte
|
|
* @reset: reset the device
|
|
* vdev: the virtio device
|
|
* After this, status and feature negotiation must be done again
|
|
* Device must not be reset from its vq/config callbacks, or in
|
|
* parallel with being added/removed.
|
|
* @find_vqs: find virtqueues and instantiate them.
|
|
* vdev: the virtio_device
|
|
* nvqs: the number of virtqueues to find
|
|
* vqs: on success, includes new virtqueues
|
|
* callbacks: array of callbacks, for each virtqueue
|
|
* include a NULL entry for vqs that do not need a callback
|
|
* names: array of virtqueue names (mainly for debugging)
|
|
* include a NULL entry for vqs unused by driver
|
|
* Returns 0 on success or error status
|
|
* @del_vqs: free virtqueues found by find_vqs().
|
|
* @get_features: get the array of feature bits for this device.
|
|
* vdev: the virtio_device
|
|
* Returns the first 32 feature bits (all we currently need).
|
|
* @finalize_features: confirm what device features we'll be using.
|
|
* vdev: the virtio_device
|
|
* This sends the driver feature bits to the device: it can change
|
|
* the dev->feature bits if it wants.
|
|
* Note: despite the name this can be called any number of times.
|
|
* Returns 0 on success or error status
|
|
* @bus_name: return the bus name associated with the device
|
|
* vdev: the virtio_device
|
|
* This returns a pointer to the bus name a la pci_name from which
|
|
* the caller can then copy.
|
|
* @set_vq_affinity: set the affinity for a virtqueue.
|
|
* @get_vq_affinity: get the affinity for a virtqueue (optional).
|
|
* @get_shm_region: get a shared memory region based on the index.
|
|
*/
|
|
typedef void vq_callback_t(struct virtqueue *);
|
|
struct virtio_config_ops {
|
|
void (*get)(struct virtio_device *vdev, unsigned offset,
|
|
void *buf, unsigned len);
|
|
void (*set)(struct virtio_device *vdev, unsigned offset,
|
|
const void *buf, unsigned len);
|
|
u32 (*generation)(struct virtio_device *vdev);
|
|
u8 (*get_status)(struct virtio_device *vdev);
|
|
void (*set_status)(struct virtio_device *vdev, u8 status);
|
|
void (*reset)(struct virtio_device *vdev);
|
|
int (*find_vqs)(struct virtio_device *, unsigned nvqs,
|
|
struct virtqueue *vqs[], vq_callback_t *callbacks[],
|
|
const char * const names[], const bool *ctx,
|
|
struct irq_affinity *desc);
|
|
void (*del_vqs)(struct virtio_device *);
|
|
u64 (*get_features)(struct virtio_device *vdev);
|
|
int (*finalize_features)(struct virtio_device *vdev);
|
|
const char *(*bus_name)(struct virtio_device *vdev);
|
|
int (*set_vq_affinity)(struct virtqueue *vq,
|
|
const struct cpumask *cpu_mask);
|
|
const struct cpumask *(*get_vq_affinity)(struct virtio_device *vdev,
|
|
int index);
|
|
bool (*get_shm_region)(struct virtio_device *vdev,
|
|
struct virtio_shm_region *region, u8 id);
|
|
};
|
|
|
|
/* If driver didn't advertise the feature, it will never appear. */
|
|
void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
|
|
unsigned int fbit);
|
|
|
|
/**
|
|
* __virtio_test_bit - helper to test feature bits. For use by transports.
|
|
* Devices should normally use virtio_has_feature,
|
|
* which includes more checks.
|
|
* @vdev: the device
|
|
* @fbit: the feature bit
|
|
*/
|
|
static inline bool __virtio_test_bit(const struct virtio_device *vdev,
|
|
unsigned int fbit)
|
|
{
|
|
/* Did you forget to fix assumptions on max features? */
|
|
if (__builtin_constant_p(fbit))
|
|
BUILD_BUG_ON(fbit >= 64);
|
|
else
|
|
BUG_ON(fbit >= 64);
|
|
|
|
return vdev->features & BIT_ULL(fbit);
|
|
}
|
|
|
|
/**
|
|
* __virtio_set_bit - helper to set feature bits. For use by transports.
|
|
* @vdev: the device
|
|
* @fbit: the feature bit
|
|
*/
|
|
static inline void __virtio_set_bit(struct virtio_device *vdev,
|
|
unsigned int fbit)
|
|
{
|
|
/* Did you forget to fix assumptions on max features? */
|
|
if (__builtin_constant_p(fbit))
|
|
BUILD_BUG_ON(fbit >= 64);
|
|
else
|
|
BUG_ON(fbit >= 64);
|
|
|
|
vdev->features |= BIT_ULL(fbit);
|
|
}
|
|
|
|
/**
|
|
* __virtio_clear_bit - helper to clear feature bits. For use by transports.
|
|
* @vdev: the device
|
|
* @fbit: the feature bit
|
|
*/
|
|
static inline void __virtio_clear_bit(struct virtio_device *vdev,
|
|
unsigned int fbit)
|
|
{
|
|
/* Did you forget to fix assumptions on max features? */
|
|
if (__builtin_constant_p(fbit))
|
|
BUILD_BUG_ON(fbit >= 64);
|
|
else
|
|
BUG_ON(fbit >= 64);
|
|
|
|
vdev->features &= ~BIT_ULL(fbit);
|
|
}
|
|
|
|
/**
|
|
* virtio_has_feature - helper to determine if this device has this feature.
|
|
* @vdev: the device
|
|
* @fbit: the feature bit
|
|
*/
|
|
static inline bool virtio_has_feature(const struct virtio_device *vdev,
|
|
unsigned int fbit)
|
|
{
|
|
if (fbit < VIRTIO_TRANSPORT_F_START)
|
|
virtio_check_driver_offered_feature(vdev, fbit);
|
|
|
|
return __virtio_test_bit(vdev, fbit);
|
|
}
|
|
|
|
/**
|
|
* virtio_has_iommu_quirk - determine whether this device has the iommu quirk
|
|
* @vdev: the device
|
|
*/
|
|
static inline bool virtio_has_iommu_quirk(const struct virtio_device *vdev)
|
|
{
|
|
/*
|
|
* Note the reverse polarity of the quirk feature (compared to most
|
|
* other features), this is for compatibility with legacy systems.
|
|
*/
|
|
return !virtio_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
|
|
}
|
|
|
|
static inline
|
|
struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,
|
|
vq_callback_t *c, const char *n)
|
|
{
|
|
vq_callback_t *callbacks[] = { c };
|
|
const char *names[] = { n };
|
|
struct virtqueue *vq;
|
|
int err = vdev->config->find_vqs(vdev, 1, &vq, callbacks, names, NULL,
|
|
NULL);
|
|
if (err < 0)
|
|
return ERR_PTR(err);
|
|
return vq;
|
|
}
|
|
|
|
static inline
|
|
int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
|
|
struct virtqueue *vqs[], vq_callback_t *callbacks[],
|
|
const char * const names[],
|
|
struct irq_affinity *desc)
|
|
{
|
|
return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, desc);
|
|
}
|
|
|
|
static inline
|
|
int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs,
|
|
struct virtqueue *vqs[], vq_callback_t *callbacks[],
|
|
const char * const names[], const bool *ctx,
|
|
struct irq_affinity *desc)
|
|
{
|
|
return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, ctx,
|
|
desc);
|
|
}
|
|
|
|
/**
|
|
* virtio_device_ready - enable vq use in probe function
|
|
* @vdev: the device
|
|
*
|
|
* Driver must call this to use vqs in the probe function.
|
|
*
|
|
* Note: vqs are enabled automatically after probe returns.
|
|
*/
|
|
static inline
|
|
void virtio_device_ready(struct virtio_device *dev)
|
|
{
|
|
unsigned status = dev->config->get_status(dev);
|
|
|
|
BUG_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
|
|
dev->config->set_status(dev, status | VIRTIO_CONFIG_S_DRIVER_OK);
|
|
}
|
|
|
|
static inline
|
|
const char *virtio_bus_name(struct virtio_device *vdev)
|
|
{
|
|
if (!vdev->config->bus_name)
|
|
return "virtio";
|
|
return vdev->config->bus_name(vdev);
|
|
}
|
|
|
|
/**
|
|
* virtqueue_set_affinity - setting affinity for a virtqueue
|
|
* @vq: the virtqueue
|
|
* @cpu: the cpu no.
|
|
*
|
|
* Note that this function is best-effort: the affinity hint may not be set
|
|
* due to config support, irq type and sharing.
|
|
*
|
|
*/
|
|
static inline
|
|
int virtqueue_set_affinity(struct virtqueue *vq, const struct cpumask *cpu_mask)
|
|
{
|
|
struct virtio_device *vdev = vq->vdev;
|
|
if (vdev->config->set_vq_affinity)
|
|
return vdev->config->set_vq_affinity(vq, cpu_mask);
|
|
return 0;
|
|
}
|
|
|
|
static inline
|
|
bool virtio_get_shm_region(struct virtio_device *vdev,
|
|
struct virtio_shm_region *region, u8 id)
|
|
{
|
|
if (!vdev->config->get_shm_region)
|
|
return false;
|
|
return vdev->config->get_shm_region(vdev, region, id);
|
|
}
|
|
|
|
static inline bool virtio_is_little_endian(struct virtio_device *vdev)
|
|
{
|
|
return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) ||
|
|
virtio_legacy_is_little_endian();
|
|
}
|
|
|
|
/* Memory accessors */
|
|
static inline u16 virtio16_to_cpu(struct virtio_device *vdev, __virtio16 val)
|
|
{
|
|
return __virtio16_to_cpu(virtio_is_little_endian(vdev), val);
|
|
}
|
|
|
|
static inline __virtio16 cpu_to_virtio16(struct virtio_device *vdev, u16 val)
|
|
{
|
|
return __cpu_to_virtio16(virtio_is_little_endian(vdev), val);
|
|
}
|
|
|
|
static inline u32 virtio32_to_cpu(struct virtio_device *vdev, __virtio32 val)
|
|
{
|
|
return __virtio32_to_cpu(virtio_is_little_endian(vdev), val);
|
|
}
|
|
|
|
static inline __virtio32 cpu_to_virtio32(struct virtio_device *vdev, u32 val)
|
|
{
|
|
return __cpu_to_virtio32(virtio_is_little_endian(vdev), val);
|
|
}
|
|
|
|
static inline u64 virtio64_to_cpu(struct virtio_device *vdev, __virtio64 val)
|
|
{
|
|
return __virtio64_to_cpu(virtio_is_little_endian(vdev), val);
|
|
}
|
|
|
|
static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
|
|
{
|
|
return __cpu_to_virtio64(virtio_is_little_endian(vdev), val);
|
|
}
|
|
|
|
/* Config space accessors. */
|
|
#define virtio_cread(vdev, structname, member, ptr) \
|
|
do { \
|
|
/* Must match the member's type, and be integer */ \
|
|
if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \
|
|
(*ptr) = 1; \
|
|
\
|
|
switch (sizeof(*ptr)) { \
|
|
case 1: \
|
|
*(ptr) = virtio_cread8(vdev, \
|
|
offsetof(structname, member)); \
|
|
break; \
|
|
case 2: \
|
|
*(ptr) = virtio_cread16(vdev, \
|
|
offsetof(structname, member)); \
|
|
break; \
|
|
case 4: \
|
|
*(ptr) = virtio_cread32(vdev, \
|
|
offsetof(structname, member)); \
|
|
break; \
|
|
case 8: \
|
|
*(ptr) = virtio_cread64(vdev, \
|
|
offsetof(structname, member)); \
|
|
break; \
|
|
default: \
|
|
BUG(); \
|
|
} \
|
|
} while(0)
|
|
|
|
/* Config space accessors. */
|
|
#define virtio_cwrite(vdev, structname, member, ptr) \
|
|
do { \
|
|
/* Must match the member's type, and be integer */ \
|
|
if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \
|
|
BUG_ON((*ptr) == 1); \
|
|
\
|
|
switch (sizeof(*ptr)) { \
|
|
case 1: \
|
|
virtio_cwrite8(vdev, \
|
|
offsetof(structname, member), \
|
|
*(ptr)); \
|
|
break; \
|
|
case 2: \
|
|
virtio_cwrite16(vdev, \
|
|
offsetof(structname, member), \
|
|
*(ptr)); \
|
|
break; \
|
|
case 4: \
|
|
virtio_cwrite32(vdev, \
|
|
offsetof(structname, member), \
|
|
*(ptr)); \
|
|
break; \
|
|
case 8: \
|
|
virtio_cwrite64(vdev, \
|
|
offsetof(structname, member), \
|
|
*(ptr)); \
|
|
break; \
|
|
default: \
|
|
BUG(); \
|
|
} \
|
|
} while(0)
|
|
|
|
/*
|
|
* Nothing virtio-specific about these, but let's worry about generalizing
|
|
* these later.
|
|
*/
|
|
#define virtio_le_to_cpu(x) \
|
|
_Generic((x), \
|
|
__u8: (x), \
|
|
__le16: le16_to_cpu(x), \
|
|
__le32: le32_to_cpu(x), \
|
|
__le64: le64_to_cpu(x) \
|
|
)
|
|
|
|
#define virtio_cpu_to_le(x, m) \
|
|
_Generic((m), \
|
|
__u8: (x), \
|
|
__le16: cpu_to_le16(x), \
|
|
__le32: cpu_to_le32(x), \
|
|
__le64: cpu_to_le64(x) \
|
|
)
|
|
|
|
/* LE (e.g. modern) Config space accessors. */
|
|
#define virtio_cread_le(vdev, structname, member, ptr) \
|
|
do { \
|
|
typeof(((structname*)0)->member) virtio_cread_v; \
|
|
\
|
|
might_sleep(); \
|
|
/* Sanity check: must match the member's type */ \
|
|
typecheck(typeof(virtio_le_to_cpu(virtio_cread_v)), *(ptr)); \
|
|
\
|
|
switch (sizeof(virtio_cread_v)) { \
|
|
case 1: \
|
|
case 2: \
|
|
case 4: \
|
|
vdev->config->get((vdev), \
|
|
offsetof(structname, member), \
|
|
&virtio_cread_v, \
|
|
sizeof(virtio_cread_v)); \
|
|
break; \
|
|
default: \
|
|
__virtio_cread_many((vdev), \
|
|
offsetof(structname, member), \
|
|
&virtio_cread_v, \
|
|
1, \
|
|
sizeof(virtio_cread_v)); \
|
|
break; \
|
|
} \
|
|
*(ptr) = virtio_le_to_cpu(virtio_cread_v); \
|
|
} while(0)
|
|
|
|
/* Config space accessors. */
|
|
#define virtio_cwrite_le(vdev, structname, member, ptr) \
|
|
do { \
|
|
typeof(((structname*)0)->member) virtio_cwrite_v = \
|
|
virtio_cpu_to_le(*(ptr), ((structname*)0)->member); \
|
|
\
|
|
might_sleep(); \
|
|
/* Sanity check: must match the member's type */ \
|
|
typecheck(typeof(virtio_le_to_cpu(virtio_cwrite_v)), *(ptr)); \
|
|
\
|
|
vdev->config->set((vdev), offsetof(structname, member), \
|
|
&virtio_cwrite_v, \
|
|
sizeof(virtio_cwrite_v)); \
|
|
} while(0)
|
|
|
|
|
|
/* Read @count fields, @bytes each. */
|
|
static inline void __virtio_cread_many(struct virtio_device *vdev,
|
|
unsigned int offset,
|
|
void *buf, size_t count, size_t bytes)
|
|
{
|
|
u32 old, gen = vdev->config->generation ?
|
|
vdev->config->generation(vdev) : 0;
|
|
int i;
|
|
|
|
do {
|
|
old = gen;
|
|
|
|
for (i = 0; i < count; i++)
|
|
vdev->config->get(vdev, offset + bytes * i,
|
|
buf + i * bytes, bytes);
|
|
|
|
gen = vdev->config->generation ?
|
|
vdev->config->generation(vdev) : 0;
|
|
} while (gen != old);
|
|
}
|
|
|
|
static inline void virtio_cread_bytes(struct virtio_device *vdev,
|
|
unsigned int offset,
|
|
void *buf, size_t len)
|
|
{
|
|
__virtio_cread_many(vdev, offset, buf, len, 1);
|
|
}
|
|
|
|
static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset)
|
|
{
|
|
u8 ret;
|
|
vdev->config->get(vdev, offset, &ret, sizeof(ret));
|
|
return ret;
|
|
}
|
|
|
|
static inline void virtio_cwrite8(struct virtio_device *vdev,
|
|
unsigned int offset, u8 val)
|
|
{
|
|
vdev->config->set(vdev, offset, &val, sizeof(val));
|
|
}
|
|
|
|
static inline u16 virtio_cread16(struct virtio_device *vdev,
|
|
unsigned int offset)
|
|
{
|
|
u16 ret;
|
|
vdev->config->get(vdev, offset, &ret, sizeof(ret));
|
|
return virtio16_to_cpu(vdev, (__force __virtio16)ret);
|
|
}
|
|
|
|
static inline void virtio_cwrite16(struct virtio_device *vdev,
|
|
unsigned int offset, u16 val)
|
|
{
|
|
val = (__force u16)cpu_to_virtio16(vdev, val);
|
|
vdev->config->set(vdev, offset, &val, sizeof(val));
|
|
}
|
|
|
|
static inline u32 virtio_cread32(struct virtio_device *vdev,
|
|
unsigned int offset)
|
|
{
|
|
u32 ret;
|
|
vdev->config->get(vdev, offset, &ret, sizeof(ret));
|
|
return virtio32_to_cpu(vdev, (__force __virtio32)ret);
|
|
}
|
|
|
|
static inline void virtio_cwrite32(struct virtio_device *vdev,
|
|
unsigned int offset, u32 val)
|
|
{
|
|
val = (__force u32)cpu_to_virtio32(vdev, val);
|
|
vdev->config->set(vdev, offset, &val, sizeof(val));
|
|
}
|
|
|
|
static inline u64 virtio_cread64(struct virtio_device *vdev,
|
|
unsigned int offset)
|
|
{
|
|
u64 ret;
|
|
__virtio_cread_many(vdev, offset, &ret, 1, sizeof(ret));
|
|
return virtio64_to_cpu(vdev, (__force __virtio64)ret);
|
|
}
|
|
|
|
static inline void virtio_cwrite64(struct virtio_device *vdev,
|
|
unsigned int offset, u64 val)
|
|
{
|
|
val = (__force u64)cpu_to_virtio64(vdev, val);
|
|
vdev->config->set(vdev, offset, &val, sizeof(val));
|
|
}
|
|
|
|
/* Conditional config space accessors. */
|
|
#define virtio_cread_feature(vdev, fbit, structname, member, ptr) \
|
|
({ \
|
|
int _r = 0; \
|
|
if (!virtio_has_feature(vdev, fbit)) \
|
|
_r = -ENOENT; \
|
|
else \
|
|
virtio_cread((vdev), structname, member, ptr); \
|
|
_r; \
|
|
})
|
|
|
|
#endif /* _LINUX_VIRTIO_CONFIG_H */
|