diff --git a/drivers/platform/tegra/Makefile b/drivers/platform/tegra/Makefile index 1b9d7952..4b2ca553 100644 --- a/drivers/platform/tegra/Makefile +++ b/drivers/platform/tegra/Makefile @@ -17,6 +17,7 @@ tegra-cactmon-objs += actmon_common.o obj-m += tegra-cactmon.o obj-m += tegra-fsicom.o +tegra-camera-rtcpu-objs := tegra-camera-rtcpu-base.o rtcpu/tegra-rtcpu-trace.o rtcpu/rtcpu-monitor.o obj-m += tegra-camera-rtcpu.o obj-m += cvnas/ diff --git a/drivers/platform/tegra/rtcpu/Makefile b/drivers/platform/tegra/rtcpu/Makefile index 43c1943d..f7364070 100644 --- a/drivers/platform/tegra/rtcpu/Makefile +++ b/drivers/platform/tegra/rtcpu/Makefile @@ -1,6 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +LINUXINCLUDE += -I$(srctree.nvidia)/drivers/gpu/host1x/hw/ +LINUXINCLUDE += -I$(srctree.nvidia)/drivers/gpu/host1x/include +LINUXINCLUDE += -I$(srctree.nvidia)/include LINUXINCLUDE += -I$(srctree.nvidia-oot)/include LINUXINCLUDE += -I$(srctree)/include LINUXINCLUDE += -I$(srctree.nvidia-oot)/drivers/platform/tegra/rtcpu @@ -13,7 +16,5 @@ obj-m += camera-diagnostics.o obj-m += debug.o obj-m += clk-group.o obj-m += hsp-mailbox-client.o -obj-m += tegra-rtcpu-trace.o -obj-m += rtcpu-monitor.o obj-m += reset-group.o obj-m += device-group.o diff --git a/drivers/platform/tegra/rtcpu/camchar.c b/drivers/platform/tegra/rtcpu/camchar.c index eb689501..00491207 100644 --- a/drivers/platform/tegra/rtcpu/camchar.c +++ b/drivers/platform/tegra/rtcpu/camchar.c @@ -16,9 +16,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include @@ -113,7 +113,7 @@ static ssize_t tegra_camchar_read(struct file *fp, char __user *buffer, size_t l break; prepare_to_wait(&dev_data->waitq, &wait, TASK_INTERRUPTIBLE); - ret = tegra_ivc_read_user(&ch->ivc, buffer, len); + ret = tegra_ivc_read(&ch->ivc, buffer, NULL, len); mutex_unlock(&dev_data->io_lock); if (ret != -ENOMEM) @@ -153,7 +153,7 @@ static ssize_t tegra_camchar_write(struct file *fp, const char __user *buffer, break; prepare_to_wait(&dev_data->waitq, &wait, TASK_INTERRUPTIBLE); - ret = tegra_ivc_write_user(&ch->ivc, buffer, len); + ret = tegra_ivc_write(&ch->ivc, buffer, NULL, len); mutex_unlock(&dev_data->io_lock); if (ret > 0) @@ -200,7 +200,7 @@ static long tegra_camchar_ioctl(struct file *fp, unsigned int cmd, break; /* ioctls specific to this device */ case CCIOGNFRAMES: - val = ch->ivc.nframes; + val = ch->ivc.num_frames; ret = put_user(val, (int __user *)arg); break; case CCIOGNBYTES: @@ -385,6 +385,7 @@ static const struct of_device_id camchar_of_match[] = { .data = (void *)"camchar-dbg", }, { }, }; +MODULE_DEVICE_TABLE(of, camchar_of_match); static struct tegra_ivc_driver camchar_driver = { .driver = { diff --git a/drivers/platform/tegra/rtcpu/camera-diagnostics.c b/drivers/platform/tegra/rtcpu/camera-diagnostics.c index 8b6dd7d9..e831457b 100644 --- a/drivers/platform/tegra/rtcpu/camera-diagnostics.c +++ b/drivers/platform/tegra/rtcpu/camera-diagnostics.c @@ -7,9 +7,9 @@ #include #include #include -#include +#include #include -#include +#include static int tegra_camera_diagnostics_probe(struct tegra_ivc_channel *ch) { @@ -33,6 +33,8 @@ static const struct of_device_id camera_diagnostics_of_match[] = { { }, }; +MODULE_DEVICE_TABLE(of, camera_diagnostics_of_match); + static struct tegra_ivc_driver camera_diagnostics_driver = { .driver = { .owner = THIS_MODULE, diff --git a/drivers/platform/tegra/rtcpu/capture-ivc.c b/drivers/platform/tegra/rtcpu/capture-ivc.c index 8914400b..893411b2 100644 --- a/drivers/platform/tegra/rtcpu/capture-ivc.c +++ b/drivers/platform/tegra/rtcpu/capture-ivc.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -41,7 +41,7 @@ static int tegra_capture_ivc_tx_(struct tegra_capture_ivc *civc, ret = wait_event_interruptible(civc->write_q, tegra_ivc_can_write(&chan->ivc)); if (likely(ret == 0)) - ret = tegra_ivc_write(&chan->ivc, req, len); + ret = tegra_ivc_write(&chan->ivc, NULL, req, len); mutex_unlock(&civc->ivc_wr_lock); @@ -352,7 +352,7 @@ static inline void tegra_capture_ivc_recv_msg( static inline void tegra_capture_ivc_recv(struct tegra_capture_ivc *civc) { - struct ivc *ivc = &civc->chan->ivc; + struct tegra_ivc *ivc = &civc->chan->ivc; struct device *dev = &civc->chan->dev; while (tegra_ivc_can_read(ivc)) { @@ -486,6 +486,7 @@ static struct of_device_id tegra_capture_ivc_channel_of_match[] = { { .compatible = "nvidia,tegra186-camera-ivc-protocol-capture" }, { }, }; +MODULE_DEVICE_TABLE(of, tegra_capture_ivc_channel_of_match); static const struct tegra_ivc_channel_ops tegra_capture_ivc_ops = { .probe = tegra_capture_ivc_probe, diff --git a/drivers/platform/tegra/rtcpu/debug.c b/drivers/platform/tegra/rtcpu/debug.c index a2614635..9604dd06 100644 --- a/drivers/platform/tegra/rtcpu/debug.c +++ b/drivers/platform/tegra/rtcpu/debug.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #if IS_ENABLED(CONFIG_TEGRA_BWMGR) @@ -32,8 +32,6 @@ #endif #include -#include - #define CAMRTC_TEST_CAM_DEVICES 4 struct camrtc_test_device { @@ -287,7 +285,7 @@ static int camrtc_ivc_dbg_full_frame_xact( goto out; } - ret = tegra_ivc_write(&ch->ivc, req, req_size); + ret = tegra_ivc_write(&ch->ivc, NULL, req, req_size); if (ret < 0) { dev_err(&ch->dev, "IVC write error: %d\n", ret); goto out; @@ -309,7 +307,7 @@ static int camrtc_ivc_dbg_full_frame_xact( dev_dbg(&ch->dev, "rx msg\n"); - ret = tegra_ivc_read_peek(&ch->ivc, resp, 0, resp_size); + ret = tegra_ivc_read_peek(&ch->ivc, NULL, resp, 0, resp_size); if (ret < 0) { dev_err(&ch->dev, "IVC read error: %d\n", ret); break; @@ -919,7 +917,7 @@ static void camrtc_membw_set(struct camrtc_run_membw *membw, u32 bw) if (bw == 0) { ; - } else if (tegra_get_chip_id() == TEGRA234) { + } else { #if IS_ENABLED(CONFIG_INTERCONNECT) struct icc_path *icc_path; int ret; @@ -936,31 +934,6 @@ static void camrtc_membw_set(struct camrtc_run_membw *membw, u32 bw) membw->icc_path = icc_path; } -#endif - } else { -#if IS_ENABLED(CONFIG_TEGRA_BWMGR) - struct tegra_bwmgr_client *bwmgr; - unsigned long emc_rate; - int ret; - - bwmgr = tegra_bwmgr_register(TEGRA_BWMGR_CLIENT_CAMERA_NON_ISO); - - if (!IS_ERR_OR_NULL(bwmgr)) { - if (bw == 0xFFFFFFFFU) - emc_rate = tegra_bwmgr_get_max_emc_rate(); - else - emc_rate = tegra_bwmgr_round_rate(bw); - - ret = tegra_bwmgr_set_emc(bwmgr, - emc_rate, TEGRA_BWMGR_SET_EMC_SHARED_BW); - - if (ret < 0) - dev_info(dev, "emc request rate %lu failed, %d\n", emc_rate, ret); - else - dev_dbg(dev, "requested emc rate %lu\n", emc_rate); - - membw->bwmgr = bwmgr; - } #endif } } @@ -1979,6 +1952,7 @@ static const struct of_device_id camrtc_debug_of_match[] = { { .compatible = "nvidia,tegra186-camera-ivc-protocol-debug" }, { }, }; +MODULE_DEVICE_TABLE(of, camrtc_debug_of_match); static struct tegra_ivc_driver camrtc_debug_driver = { .driver = { diff --git a/drivers/platform/tegra/rtcpu/device-group.c b/drivers/platform/tegra/rtcpu/device-group.c index fa684523..540a47eb 100644 --- a/drivers/platform/tegra/rtcpu/device-group.c +++ b/drivers/platform/tegra/rtcpu/device-group.c @@ -9,7 +9,6 @@ #include #include #include -#include "drivers/video/tegra/host/nvhost_acm.h" struct camrtc_device_group { struct device *dev; diff --git a/drivers/platform/tegra/rtcpu/hsp-mailbox-client.c b/drivers/platform/tegra/rtcpu/hsp-mailbox-client.c index 22bc90c7..36d97a07 100644 --- a/drivers/platform/tegra/rtcpu/hsp-mailbox-client.c +++ b/drivers/platform/tegra/rtcpu/hsp-mailbox-client.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -#include "hsp-combo.h" +#include "linux/tegra-hsp-combo.h" #include @@ -326,15 +326,27 @@ static int camrtc_hsp_vm_get_fw_hash(struct camrtc_hsp *camhsp, u32 index, return camrtc_hsp_vm_sendrecv(camhsp, request, timeout); } +static struct device_node *hsp_vm_get_available(const struct device_node *parent) +{ + const char *compatible = "nvidia,tegra-camrtc-hsp-vm"; + struct device_node *child; + + for_each_child_of_node(parent, child) { + if (of_device_is_compatible(child, compatible) && + of_device_is_available(child)) + break; + } + return child; +} + static int camrtc_hsp_vm_probe(struct camrtc_hsp *camhsp) { struct device_node *np = camhsp->dev.parent->of_node; int err = -ENOTSUPP; const char *obtain = ""; - np = of_get_compatible_child(np, "nvidia,tegra-camrtc-hsp-vm"); - if (!of_device_is_available(np)) { - of_node_put(np); + np = hsp_vm_get_available(np); + if (np == NULL) { dev_err(&camhsp->dev, "no hsp protocol \"%s\"\n", "nvidia,tegra-camrtc-hsp-vm"); return -ENOTSUPP; diff --git a/drivers/platform/tegra/rtcpu/ivc-bus.c b/drivers/platform/tegra/rtcpu/ivc-bus.c index 594075ad..8fc530e3 100644 --- a/drivers/platform/tegra/rtcpu/ivc-bus.c +++ b/drivers/platform/tegra/rtcpu/ivc-bus.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -33,14 +33,13 @@ struct tegra_ivc_bus { struct tegra_ivc_region regions[]; }; -static void tegra_ivc_channel_ring(struct ivc *ivc) +static void tegra_ivc_channel_ring(struct tegra_ivc *ivc, void *data) { struct tegra_ivc_channel *chan = container_of(ivc, struct tegra_ivc_channel, ivc); - struct tegra_ivc_bus *bus = - container_of(chan->dev.parent, struct tegra_ivc_bus, dev); + struct camrtc_hsp *camhsp = (struct camrtc_hsp *) data; - tegra_camrtc_ivc_ring(bus->dev.parent, chan->group); + camrtc_hsp_group_ring(camhsp, chan->group); } struct device_type tegra_ivc_channel_type = { @@ -75,7 +74,8 @@ static void tegra_ivc_channel_release(struct device *dev) static struct tegra_ivc_channel *tegra_ivc_channel_create( struct tegra_ivc_bus *bus, struct device_node *ch_node, - struct tegra_ivc_region *region) + struct tegra_ivc_region *region, + struct camrtc_hsp *camhsp) { struct device *peer_device = bus->dev.parent; struct camrtc_tlv_ivc_setup *tlv; @@ -162,13 +162,15 @@ static struct tegra_ivc_channel *tegra_ivc_channel_create( end.tx = region->ivc_size; /* Init IVC */ - ret = tegra_ivc_init_with_dma_handle(&chan->ivc, - region->base + start.rx, region->iova + start.rx, - region->base + start.tx, region->iova + start.tx, + ret = tegra_ivc_init(&chan->ivc, + NULL, + (void *)(region->base + start.rx), + region->iova + start.rx, + (void *)(region->base + start.tx), + region->iova + start.tx, nframes, frame_size, - /* Device used to allocate the shared memory for IVC */ - peer_device, - tegra_ivc_channel_ring); + tegra_ivc_channel_ring, + (void *)camhsp); if (ret) { dev_err(&chan->dev, "IVC initialization error: %d\n", ret); goto error; @@ -290,7 +292,8 @@ static void tegra_ivc_bus_stop(struct tegra_ivc_bus *bus) } } -static int tegra_ivc_bus_start(struct tegra_ivc_bus *bus) +static int tegra_ivc_bus_start(struct tegra_ivc_bus *bus, + struct camrtc_hsp *camhsp) { struct device_node *dn = bus->dev.parent->of_node; struct of_phandle_args reg_spec; @@ -317,7 +320,8 @@ static int tegra_ivc_bus_start(struct tegra_ivc_bus *bus) } chan = tegra_ivc_channel_create(bus, ch_node, - &bus->regions[i]); + &bus->regions[i], + camhsp); if (IS_ERR(chan)) { ret = PTR_ERR(chan); of_node_put(ch_node); @@ -339,7 +343,8 @@ error: * This is called during RTCPU boot to synchronize * (or re-synchronize in the case of PM resume). */ -int tegra_ivc_bus_boot_sync(struct tegra_ivc_bus *bus) +int tegra_ivc_bus_boot_sync(struct tegra_ivc_bus *bus, + int (*iovm_setup)(struct device*, dma_addr_t)) { int i; @@ -347,7 +352,7 @@ int tegra_ivc_bus_boot_sync(struct tegra_ivc_bus *bus) return 0; for (i = 0; i < bus->num_regions; i++) { - int ret = tegra_camrtc_iovm_setup(bus->dev.parent, + int ret = (*iovm_setup)(bus->dev.parent, bus->regions[i].iova); if (ret != 0) { dev_info(&bus->dev, "IOVM setup error: %d\n", ret); @@ -531,7 +536,8 @@ static unsigned tegra_ivc_bus_count_regions(const struct device_node *dev_node) return i; } -struct tegra_ivc_bus *tegra_ivc_bus_create(struct device *dev) +struct tegra_ivc_bus *tegra_ivc_bus_create(struct device *dev, + struct camrtc_hsp *camhsp) { struct tegra_ivc_bus *bus; unsigned num; @@ -566,7 +572,7 @@ struct tegra_ivc_bus *tegra_ivc_bus_create(struct device *dev) goto error; } - ret = tegra_ivc_bus_start(bus); + ret = tegra_ivc_bus_start(bus, camhsp); if (ret) { dev_err(&bus->dev, "bus start failed: %d\n", ret); goto error; diff --git a/drivers/platform/tegra/rtcpu/rtcpu-monitor.c b/drivers/platform/tegra/rtcpu/rtcpu-monitor.c index 66667a77..151e0b97 100644 --- a/drivers/platform/tegra/rtcpu/rtcpu-monitor.c +++ b/drivers/platform/tegra/rtcpu/rtcpu-monitor.c @@ -11,9 +11,6 @@ #include #include -#include "drivers/video/tegra/host/vi/vi_notify.h" -#include "vi-notify.h" - struct tegra_camrtc_mon { struct device *rce_dev; int wdt_irq; diff --git a/drivers/platform/tegra/tegra-camera-rtcpu.c b/drivers/platform/tegra/tegra-camera-rtcpu-base.c similarity index 95% rename from drivers/platform/tegra/tegra-camera-rtcpu.c rename to drivers/platform/tegra/tegra-camera-rtcpu-base.c index bef36b48..2b1d9c33 100644 --- a/drivers/platform/tegra/tegra-camera-rtcpu.c +++ b/drivers/platform/tegra/tegra-camera-rtcpu-base.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -37,15 +36,12 @@ #include #include -#include - #include "rtcpu/clk-group.h" #include "rtcpu/device-group.h" #include "rtcpu/reset-group.h" -#include "rtcpu/hsp-combo.h" +#include "linux/tegra-hsp-combo.h" #include "soc/tegra/camrtc-commands.h" -#include #define CAMRTC_NUM_REGS 2 #define CAMRTC_NUM_RESETS 2 @@ -131,7 +127,6 @@ struct tegra_cam_rtcpu { struct device_dma_parameters dma_parms; struct camrtc_hsp *hsp; struct tegra_rtcpu_trace *tracer; - struct tegra_rtcpu_coverage *coverage; u32 cmd_timeout; u32 fw_version; u8 fw_hash[RTCPU_FW_HASH_SIZE]; @@ -351,13 +346,9 @@ static void tegra_camrtc_init_membw(struct device *dev) if (of_property_read_u32(dev->of_node, "nvidia,memory-bw", &bw) != 0) { ; - } else if (tegra_get_chip_id() == TEGRA234) { + } else { #if IS_ENABLED(CONFIG_INTERCONNECT) tegra_camrtc_init_icc(dev, bw); -#endif - } else { -#if IS_ENABLED(CONFIG_TEGRA_BWMGR) - tegra_camrtc_init_bwmgr(dev, bw); #endif } } @@ -577,24 +568,10 @@ static int tegra_camrtc_setup_shared_memory(struct device *dev) if (ret < 0) dev_err(dev, "trace boot sync failed: %d\n", ret); - /* - * Set-up coverage buffer - */ - ret = tegra_rtcpu_coverage_boot_sync(rtcpu->coverage); - if (ret < 0) { - /* - * Not a fatal error, don't stop the sync. - * But go ahead and remove the coverage debug FS - * entries and release the memory. - */ - tegra_rtcpu_coverage_destroy(rtcpu->coverage); - rtcpu->coverage = NULL; - } - /* * Set-up and activate the IVC services in firmware */ - ret = tegra_ivc_bus_boot_sync(rtcpu->ivc); + ret = tegra_ivc_bus_boot_sync(rtcpu->ivc, &tegra_camrtc_iovm_setup); if (ret < 0) dev_err(dev, "ivc-bus boot sync failed: %d\n", ret); @@ -636,14 +613,6 @@ static void tegra_camrtc_ivc_notify(struct device *dev, u16 group) tegra_ivc_bus_notify(rtcpu->ivc, group); } -void tegra_camrtc_ivc_ring(struct device *dev, u16 group) -{ - struct tegra_cam_rtcpu *rtcpu = dev_get_drvdata(dev); - - camrtc_hsp_group_ring(rtcpu->hsp, group); -} -EXPORT_SYMBOL(tegra_camrtc_ivc_ring); - static int tegra_camrtc_poweron(struct device *dev, bool full_speed) { struct tegra_cam_rtcpu *rtcpu = dev_get_drvdata(dev); @@ -862,8 +831,6 @@ static int tegra_cam_rtcpu_remove(struct platform_device *pdev) tegra_rtcpu_trace_destroy(rtcpu->tracer); rtcpu->tracer = NULL; - tegra_rtcpu_coverage_destroy(rtcpu->coverage); - rtcpu->coverage = NULL; tegra_camrtc_poweroff(&pdev->dev); #if IS_ENABLED(CONFIG_TEGRA_BWMGR) @@ -927,10 +894,6 @@ static int tegra_cam_rtcpu_probe(struct platform_device *pdev) (void)of_property_read_u32(dev->of_node, NV(max-reboot), &rtcpu->max_reboot_retry); timeout = 2000; -#if 0 /* disabled for OOT kernel */ - if (tegra_platform_is_vdk()) - timeout = 5000; -#endif (void)of_property_read_u32(dev->of_node, "nvidia,cmd-timeout", &timeout); @@ -950,8 +913,6 @@ static int tegra_cam_rtcpu_probe(struct platform_device *pdev) rtcpu->tracer = tegra_rtcpu_trace_create(dev, rtcpu->camera_devices); - rtcpu->coverage = tegra_rtcpu_coverage_create(dev); - ret = tegra_camrtc_hsp_init(dev); if (ret) goto fail; @@ -961,7 +922,7 @@ static int tegra_cam_rtcpu_probe(struct platform_device *pdev) if (ret < 0) goto fail; - rtcpu->ivc = tegra_ivc_bus_create(dev); + rtcpu->ivc = tegra_ivc_bus_create(dev, rtcpu->hsp); if (IS_ERR(rtcpu->ivc)) { ret = PTR_ERR(rtcpu->ivc); rtcpu->ivc = NULL; diff --git a/drivers/platform/tegra/rtcpu/hsp-combo.h b/include/linux/tegra-hsp-combo.h similarity index 100% rename from drivers/platform/tegra/rtcpu/hsp-combo.h rename to include/linux/tegra-hsp-combo.h diff --git a/include/linux/tegra-ivc-bus.h b/include/linux/tegra-ivc-bus.h index d0332566..5bf43f06 100644 --- a/include/linux/tegra-ivc-bus.h +++ b/include/linux/tegra-ivc-bus.h @@ -6,19 +6,22 @@ #ifndef _LINUX_TEGRA_IVC_BUS_H #define _LINUX_TEGRA_IVC_BUS_H -#include +#include #include +#include extern struct bus_type tegra_ivc_bus_type; extern struct device_type tegra_ivc_bus_dev_type; struct tegra_ivc_bus; struct tegra_ivc_rpc_data; -struct tegra_ivc_bus *tegra_ivc_bus_create(struct device *); +struct tegra_ivc_bus *tegra_ivc_bus_create(struct device *dev, + struct camrtc_hsp *camhsp); void tegra_ivc_bus_ready(struct tegra_ivc_bus *bus, bool online); void tegra_ivc_bus_destroy(struct tegra_ivc_bus *bus); -int tegra_ivc_bus_boot_sync(struct tegra_ivc_bus *bus); +int tegra_ivc_bus_boot_sync(struct tegra_ivc_bus *bus, + int (*iovm_setup)(struct device*, dma_addr_t)); void tegra_ivc_bus_notify(struct tegra_ivc_bus *bus, u16 group); struct tegra_ivc_driver { @@ -59,7 +62,7 @@ tegra_ivc_subsys_driver(__driver, \ extern struct device_type tegra_ivc_channel_type; struct tegra_ivc_channel { - struct ivc ivc; + struct tegra_ivc ivc; struct device dev; const struct tegra_ivc_channel_ops __rcu *ops; struct tegra_ivc_channel *next;