Commit Graph

16 Commits

Author SHA1 Message Date
Richard Acayan
ba3d9facec fastrpc: add adsp_default_listener interface
The ADSP default listener interface is an interface with which to
register the default listener for FastRPC reverse tunneling. Add the
interface for this so programs can advertise their ability to receive
FastRPC messages.

It was accidentally #include-ed in a previous commit.

Fixes: 2ba7bf1df6 ("fastrpc: rpcd: close remote handle")
2023-01-05 21:17:04 -05:00
Richard Acayan
15e1041d7f fastrpc: change copyright year
None of this was published before January 4, 2023.
2023-01-05 20:58:17 -05:00
Richard Acayan
d31bb95430 fastrpc: only populate the first arguments if needed
If there are no 32-bit integers in the first input or output buffers,
then the argument pointer might be NULL or point out-of-bounds. Only
write to this pointer's target if the buffer was allocated, otherwise
the size of the corresponding first argument has a length of zero and
should be omitted.
2023-01-04 23:05:09 -05:00
Richard Acayan
2ba7bf1df6 fastrpc: rpcd: close remote handle
A request to open a handle should be mirrored with a request to close a
handle. Close the remote handle if it was successfully opened.
2023-01-04 22:50:22 -05:00
Richard Acayan
f7878ae2c3 fastrpc: remotectl: add close definition
A remotectl_open() procedure call should be mirrored with a
remotectl_close() procedure call. Add a definition for this remote
procedure so handles can be closed.
2023-01-04 22:50:22 -05:00
Richard Acayan
a9c79273f8 fastrpc: rpcd: initialize the fastrpc protection domain
This is what happens when I push stuff that isn't quite ready...

FastRPC expects the client to attach to a protection domain and
communicate over a device node. Initialize these things so remote
procedure calls are sent to the remote processor.
2023-01-04 22:50:22 -05:00
Richard Acayan
0b3f26f6ec fastrpc: rpcd: open adsp_default_listener
The adsp_listener is static, with handle 3, and loading it is useless.
Open something more interesting.
2023-01-04 22:50:22 -05:00
Richard Acayan
d1639d0256 fastrpc: rpcd: correct second remotectl_open() output integer
The second 32-bit integer in the first output buffer is not the returned
length of the output buffer. Instead, it is an error code, as defined in
fastrpc.git/inc/AEEStdErr.h. Properly handle the output integer and pass
an appropriate string that represents the error.
2023-01-04 22:50:22 -05:00
Richard Acayan
aaa0e65c2d fastrpc: treat returned length as a normal number (BREAKING CHANGE)
A FastRPC function call does not necessarily return the amount of bytes
written in the output buffer. Implementing a field that makes these
sizes optional would require the function to keep track of the returned
sizes separately from any other output from this function. Since
returned lengths are interleaved and at the last part of the argument
list, it already needs an unnecessary pass to write back the lengths.
Move the returned lengths to the "returned numbers" part of the argument
list and assume that they are counted in the out_nums property of the
function definition.

The (maximum) sizes of the buffers should still be handled separately
because they need to be passed both to the kernel and to the remote
processor. Removing this special handling would just duplicate the size
arguments, while its implementation is more maintainable than the
returned lengths. The kernel API would need to change for this separate
handling to be unnecessary. Therefore, it is useless to introduce any
other breaking change while old code is already broken.
2023-01-04 22:50:21 -05:00
Richard Acayan
6725fc2036 fastrpc: only skip the first output buffer if it exists
The function-level output buffers are passed with the assumption that
a first output buffer needs to be skipped. This is always true, given
that there is always a returned length of each buffer, but it is not
always the case. Calculate the offset instead of hardcoding it so the
first fixed-length output buffer is only skipped if it exists.
2023-01-04 22:49:38 -05:00
Richard Acayan
5527208047 fastrpc: do not manage zero-length buffers
If there are no inputs, or if there are no outputs, one or more of these
buffers may be zero. Do not try to allocate or deallocate buffers that
have a length of zero and cause undefined behavior.

Fixes: 9adc9ea326 ("add fastrpc")
2023-01-04 22:47:50 -05:00
Richard Acayan
37c3d91cb3 fastrpc: write to correct first input buffer index
The first input buffer is skipped when passing the function-level input
buffers, but the first entry communicating the buffer's size is also
skipped. This is incorrect: the sizes for these buffers start at
inbuf[def->in_nums].  Start the iterator at zero and add one to the
argument index to make it clear that the argument buffers index is
offset and the first buffer index is not.

Fixes: 9adc9ea326 ("add fastrpc")
2023-01-04 21:37:44 -05:00
Richard Acayan
4c8717cd71 fastrpc: give fastrpc_invoke_args allocation its own line 2023-01-04 21:37:23 -05:00
Richard Acayan
6787ef3a43 fastrpc: break up argument assignments 2023-01-04 21:36:37 -05:00
Richard Acayan
9adc9ea326 add fastrpc
FastRPC is a communication protocol used to communicate with some remote
processors on Qualcomm SoC's. It might be needed to configure sensors
and to prevent an ADSP crash on the Pixel 3a.

The programs provided by Google and Linaro don't work out of the box to
set up an ADSP listener (even with kernel patches), and is a bit too
unpleasant to read for my tastes. Add a new FastRPC implementation that
will hopefully be more readable for everyone.
2023-01-04 00:38:15 -05:00
Richard Acayan
fd99c4d6d5 initial commit 2023-01-02 18:51:58 -05:00