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