1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 4 */ 5 6 #ifndef __TEGRA_IVC_H 7 8 #include <linux/device.h> 9 #include <linux/dma-mapping.h> 10 #include <linux/iosys-map.h> 11 #include <linux/types.h> 12 13 struct tegra_ivc_header; 14 15 struct tegra_ivc { 16 struct device *peer; 17 18 struct { 19 struct iosys_map map; 20 unsigned int position; 21 dma_addr_t phys; 22 } rx, tx; 23 24 void (*notify)(struct tegra_ivc *ivc, void *data); 25 void *notify_data; 26 27 unsigned int num_frames; 28 size_t frame_size; 29 }; 30 31 /** 32 * tegra_ivc_read_get_next_frame - Peek at the next frame to receive 33 * @ivc pointer of the IVC channel 34 * 35 * Peek at the next frame to be received, without removing it from 36 * the queue. 37 * 38 * Returns a pointer to the frame, or an error encoded pointer. 39 */ 40 int tegra_ivc_read_get_next_frame(struct tegra_ivc *ivc, struct iosys_map *map); 41 42 /** 43 * tegra_ivc_read_advance - Advance the read queue 44 * @ivc pointer of the IVC channel 45 * 46 * Advance the read queue 47 * 48 * Returns 0, or a negative error value if failed. 49 */ 50 int tegra_ivc_read_advance(struct tegra_ivc *ivc); 51 52 /** 53 * tegra_ivc_write_get_next_frame - Poke at the next frame to transmit 54 * @ivc pointer of the IVC channel 55 * 56 * Get access to the next frame. 57 * 58 * Returns a pointer to the frame, or an error encoded pointer. 59 */ 60 int tegra_ivc_write_get_next_frame(struct tegra_ivc *ivc, struct iosys_map *map); 61 62 /** 63 * tegra_ivc_write_advance - Advance the write queue 64 * @ivc pointer of the IVC channel 65 * 66 * Advance the write queue 67 * 68 * Returns 0, or a negative error value if failed. 69 */ 70 int tegra_ivc_write_advance(struct tegra_ivc *ivc); 71 72 /** 73 * tegra_ivc_notified - handle internal messages 74 * @ivc pointer of the IVC channel 75 * 76 * This function must be called following every notification. 77 * 78 * Returns 0 if the channel is ready for communication, or -EAGAIN if a channel 79 * reset is in progress. 80 */ 81 int tegra_ivc_notified(struct tegra_ivc *ivc); 82 83 /** 84 * tegra_ivc_reset - initiates a reset of the shared memory state 85 * @ivc pointer of the IVC channel 86 * 87 * This function must be called after a channel is reserved before it is used 88 * for communication. The channel will be ready for use when a subsequent call 89 * to notify the remote of the channel reset. 90 */ 91 void tegra_ivc_reset(struct tegra_ivc *ivc); 92 93 size_t tegra_ivc_align(size_t size); 94 unsigned tegra_ivc_total_queue_size(unsigned queue_size); 95 int tegra_ivc_init(struct tegra_ivc *ivc, struct device *peer, const struct iosys_map *rx, 96 dma_addr_t rx_phys, const struct iosys_map *tx, dma_addr_t tx_phys, 97 unsigned int num_frames, size_t frame_size, 98 void (*notify)(struct tegra_ivc *ivc, void *data), 99 void *data); 100 void tegra_ivc_cleanup(struct tegra_ivc *ivc); 101 102 #endif /* __TEGRA_IVC_H */ 103