^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2013-2016 Freescale Semiconductor Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/fsl/mc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "fsl-mc-private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct fsl_mc_device *dpmcp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) if (mc_io->dpmcp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) if (dpmcp_dev->mc_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) error = dpmcp_open(mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) dpmcp_dev->obj_desc.id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) &dpmcp_dev->mc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) mc_io->dpmcp_dev = dpmcp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) dpmcp_dev->mc_io = mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static void fsl_mc_io_unset_dpmcp(struct fsl_mc_io *mc_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) error = dpmcp_close(mc_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) dpmcp_dev->mc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) dev_err(&dpmcp_dev->dev, "dpmcp_close() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) mc_io->dpmcp_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) dpmcp_dev->mc_io = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Creates an MC I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @dev: device to be associated with the MC I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @mc_portal_phys_addr: physical address of the MC portal to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @mc_portal_size: size in bytes of the MC portal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @dpmcp-dev: Pointer to the DPMCP object associated with this MC I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * object or NULL if none.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @flags: flags for the new MC I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @new_mc_io: Area to return pointer to newly created MC I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Returns '0' on Success; Error code otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int __must_check fsl_create_mc_io(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) phys_addr_t mc_portal_phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u32 mc_portal_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct fsl_mc_device *dpmcp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u32 flags, struct fsl_mc_io **new_mc_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct fsl_mc_io *mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) void __iomem *mc_portal_virt_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) mc_io = devm_kzalloc(dev, sizeof(*mc_io), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (!mc_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) mc_io->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) mc_io->flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) mc_io->portal_phys_addr = mc_portal_phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) mc_io->portal_size = mc_portal_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) raw_spin_lock_init(&mc_io->spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) mutex_init(&mc_io->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) res = devm_request_mem_region(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) mc_portal_phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) mc_portal_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) "mc_portal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) "devm_request_mem_region failed for MC portal %pa\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) &mc_portal_phys_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) mc_portal_virt_addr = devm_ioremap(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) mc_portal_phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) mc_portal_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (!mc_portal_virt_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) "devm_ioremap failed for MC portal %pa\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) &mc_portal_phys_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) mc_io->portal_virt_addr = mc_portal_virt_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (dpmcp_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) error = fsl_mc_io_set_dpmcp(mc_io, dpmcp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) goto error_destroy_mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *new_mc_io = mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) error_destroy_mc_io:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) fsl_destroy_mc_io(mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return error;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * Destroys an MC I/O object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * @mc_io: MC I/O object to destroy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void fsl_destroy_mc_io(struct fsl_mc_io *mc_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct fsl_mc_device *dpmcp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (!mc_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) dpmcp_dev = mc_io->dpmcp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (dpmcp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) fsl_mc_io_unset_dpmcp(mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) devm_iounmap(mc_io->dev, mc_io->portal_virt_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) devm_release_mem_region(mc_io->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) mc_io->portal_phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) mc_io->portal_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) mc_io->portal_virt_addr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) devm_kfree(mc_io->dev, mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * fsl_mc_portal_allocate - Allocates an MC portal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * @mc_dev: MC device for which the MC portal is to be allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * @mc_io_flags: Flags for the fsl_mc_io object that wraps the allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * MC portal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @new_mc_io: Pointer to area where the pointer to the fsl_mc_io object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * that wraps the allocated MC portal is to be returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * This function allocates an MC portal from the device's parent DPRC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * from the corresponding MC bus' pool of MC portals and wraps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * it in a new fsl_mc_io object. If 'mc_dev' is a DPRC itself, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * portal is allocated from its own MC bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) u16 mc_io_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct fsl_mc_io **new_mc_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct fsl_mc_device *mc_bus_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct fsl_mc_bus *mc_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) phys_addr_t mc_portal_phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) size_t mc_portal_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct fsl_mc_device *dpmcp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct fsl_mc_resource *resource = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct fsl_mc_io *mc_io = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (mc_dev->flags & FSL_MC_IS_DPRC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) mc_bus_dev = mc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (!dev_is_fsl_mc(mc_dev->dev.parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) mc_bus = to_fsl_mc_bus(mc_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) *new_mc_io = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) error = fsl_mc_resource_allocate(mc_bus, FSL_MC_POOL_DPMCP, &resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) dpmcp_dev = resource->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (dpmcp_dev->obj_desc.ver_major < DPMCP_MIN_VER_MAJOR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) (dpmcp_dev->obj_desc.ver_major == DPMCP_MIN_VER_MAJOR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) dpmcp_dev->obj_desc.ver_minor < DPMCP_MIN_VER_MINOR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dev_err(&dpmcp_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) "ERROR: Version %d.%d of DPMCP not supported.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) dpmcp_dev->obj_desc.ver_major,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) dpmcp_dev->obj_desc.ver_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) error = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) goto error_cleanup_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) mc_portal_phys_addr = dpmcp_dev->regions[0].start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) mc_portal_size = resource_size(dpmcp_dev->regions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) error = fsl_create_mc_io(&mc_bus_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) mc_portal_phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) mc_portal_size, dpmcp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) mc_io_flags, &mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) goto error_cleanup_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) dpmcp_dev->consumer_link = device_link_add(&mc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) &dpmcp_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) DL_FLAG_AUTOREMOVE_CONSUMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (!dpmcp_dev->consumer_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) goto error_cleanup_mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) *new_mc_io = mc_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) error_cleanup_mc_io:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) fsl_destroy_mc_io(mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) error_cleanup_resource:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) fsl_mc_resource_free(resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) EXPORT_SYMBOL_GPL(fsl_mc_portal_allocate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * fsl_mc_portal_free - Returns an MC portal to the pool of free MC portals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * of a given MC bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) void fsl_mc_portal_free(struct fsl_mc_io *mc_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct fsl_mc_device *dpmcp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct fsl_mc_resource *resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * Every mc_io obtained by calling fsl_mc_portal_allocate() is supposed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * to have a DPMCP object associated with.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) dpmcp_dev = mc_io->dpmcp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) resource = dpmcp_dev->resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (!resource || resource->type != FSL_MC_POOL_DPMCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (resource->data != dpmcp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) fsl_destroy_mc_io(mc_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) fsl_mc_resource_free(resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) dpmcp_dev->consumer_link = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) EXPORT_SYMBOL_GPL(fsl_mc_portal_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * fsl_mc_portal_reset - Resets the dpmcp object for a given fsl_mc_io object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * @mc_io: Pointer to the fsl_mc_io object that wraps the MC portal to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int fsl_mc_portal_reset(struct fsl_mc_io *mc_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) error = dpmcp_reset(mc_io, 0, dpmcp_dev->mc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) dev_err(&dpmcp_dev->dev, "dpmcp_reset() failed: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) EXPORT_SYMBOL_GPL(fsl_mc_portal_reset);