Skip to content

Commit 6a1caeb

Browse files
committed
staging: vchiq_arm: Add the requested explanations
Replace the TODO items with explanations largely derived by reading the code. Signed-off-by: Phil Elwell <[email protected]>
1 parent 814a390 commit 6a1caeb

File tree

3 files changed

+102
-17
lines changed

3 files changed

+102
-17
lines changed

drivers/staging/vc04_services/Documentation/vchiq-cdev

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,82 @@ Description:
66
The ioctl interface for the VCHIQ character device.
77
Following actions are supported:
88

9-
/* TODO: Please explain each IOCTL in short */
10-
119
* VCHIQ_IOC_CONNECT:
10+
Establish/confirm the link to the VPU peer.
1211

1312
* VCHIQ_IOC_SHUTDOWN:
13+
Close the link to the VPU peer, removing all services.
1414

1515
* VCHIQ_IOC_CREATE_SERVICE:
16+
Create a VCHIQ service with the given FOURCC, registering a
17+
callback. If is_open is true, attempt to connect to the same
18+
FOURCC on the peer. If successful, populates the handle field
19+
in the parameter structure, otherwise returns an error.
1620

1721
* VCHIQ_IOC_REMOVE_SERVICE:
22+
Close and remove the service indicated by the provided
23+
handle.
1824

1925
* VCHIQ_IOC_QUEUE_MESSAGE:
26+
Adds the given in-band message for the indicated server to
27+
the queue.
2028

2129
* VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
30+
Adds the given out-of-band bulk message for the indicated
31+
service to the bulk queue.
2232

2333
* VCHIQ_IOC_QUEUE_BULK_RECEIVE:
34+
Adds the given out-of-band bulk buffer for data from the
35+
indicated service to the bulk queue.
2436

2537
* VCHIQ_IOC_AWAIT_COMPLETION:
38+
The in-kernel API allows direct callbacks to client code.
39+
Userspace clients rely on the equivalent of an RPC, with the
40+
parameters for each callback marshalled into structures
41+
called completions. This method blocks waiting for
42+
completions to process.
2643

2744
* VCHIQ_IOC_DEQUEUE_MESSAGE:
45+
Copy the next message for the indicated service, releasing
46+
the space that was occupied. Optionally blocks if no message
47+
is waiting.
2848

2949
* VCHIQ_IOC_GET_CLIENT_ID:
50+
Retrieve an identifier for the client. This is intended to
51+
allow instances of multiple services to be grouped. For
52+
services provided by Linux the client ID is the pid. VPU
53+
services have a client ID of 1.
3054

3155
* VCHIQ_IOC_GET_CONFIG:
56+
Returns various properties of the VCHIQ configuration, such
57+
as the maximum message size and version numbers.
3258

3359
* VCHIQ_IOC_CLOSE_SERVICE:
60+
Cause a service to disconnect from the peer, returning it to
61+
the closed/listening state, i.e. REMOVE_SERVICE but without
62+
destroying the service.
3463

3564
* VCHIQ_IOC_USE_SERVICE:
36-
3765
* VCHIQ_IOC_RELEASE_SERVICE:
66+
Use to mark the start and end of activity on a service. An
67+
active service is intended to prevent the system from
68+
suspending. N.B. Raspberry Pi devices that run VCHIQ do not
69+
implement suspend/resume.
3870

3971
* VCHIQ_IOC_SET_SERVICE_OPTION:
72+
Sets a number of per-service options: AUTOCLOSE, SLOT_QUOTA,
73+
MESSAGE_QUOTA, SYNCHRONOUS mode and TRACE.
4074

4175
* VCHIQ_IOC_DUMP_PHYS_MEM:
76+
No longer implemented.
4277

4378
* VCHIQ_IOC_LIB_VERSION:
79+
Notify the kernel of the version of the userspace VCHIQ
80+
library being used. Currently used to determine if the
81+
CLOSE_DELIVERED ioctl is used, and therefore whether to
82+
wait for the extra handshake on a close.
4483

4584
* VCHIQ_IOC_CLOSE_DELIVERED:
85+
Signal that the userspace code has finished processing the
86+
close. This additional handshake avoids a race on service
87+
closure.

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ static const struct vchiq_platform_info bcm2711_info = {
8282
};
8383

8484
struct vchiq_arm_state {
85-
/* Keepalive-related data */
86-
/* TODO: Please elaborate the purpose of this thread
87-
* What needs to be kept alive?
85+
/*
86+
* Keepalive-related data
87+
*
88+
* The keepalive mechanism was retro-fitted to VCHIQ to allow active
89+
* services to prevent the system from suspending. This feature is not used
90+
* on Raspberry Pi devices.
8891
*/
8992
struct task_struct *ka_thread;
9093
struct completion ka_evt;

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,21 @@ struct vchiq_slot_info {
174174
short release_count;
175175
};
176176

177-
/* TODO: Please explain the meaning of "service" in the context of VCHIQ */
177+
/*
178+
* VCHIQ is a reliable connection-oriented datagram protocol.
179+
*
180+
* A VCHIQ service is equivalent to a TCP connection, except:
181+
* + FOURCCs are used for the rendezvous, and port numbers are assigned at the
182+
* time the connection is established.
183+
* + There is less of a distinction between server and client sockets, the only
184+
* difference being which end makes the first move.
185+
* + For a multi-client server, the server creates new "listening" services as
186+
* the existing one becomes connected - there is no need to specify the
187+
* maximum number of clients up front.
188+
* + Data transfer is reliable but packetised (messages have defined ends).
189+
* + Messages can be either short (capable of fitting in a slot) and in-band,
190+
* or copied between external buffers (bulk transfers).
191+
*/
178192
struct vchiq_service {
179193
struct vchiq_service_base base;
180194
unsigned int handle;
@@ -291,8 +305,21 @@ struct vchiq_shared_state {
291305
};
292306

293307
/*
294-
* TODO: Mark all structs which are shared with the VideoCore and must not
295-
* be modified (ABI)
308+
* vchiq_slot_zero describes the memory shared between the ARM host and the
309+
* VideoCore VPU. The "master" and "slave" states are owned by the respective
310+
* sides but visible to the other; the slots are shared, and the remaining
311+
* fields are read-only.
312+
*
313+
* In the configuration used by this implementation, the memory is allocated
314+
* by the host, the VPU is the master (the side which controls the DMA for bulk
315+
* transfers), and the host is the slave.
316+
*
317+
* The owmership of slots changes with use:
318+
* + When empty they are owned by the sender.
319+
* + When partially filled they are shared with the receiver.
320+
* + When completely full they are owned by the receiver.
321+
* + When the receiver has finished processing the contents, they are recycled
322+
* back to the sender.
296323
*/
297324
struct vchiq_slot_zero {
298325
int magic;
@@ -308,6 +335,10 @@ struct vchiq_slot_zero {
308335
struct vchiq_slot_info slots[VCHIQ_MAX_SLOTS];
309336
};
310337

338+
/*
339+
* This is the private runtime state used by each side. The same structure was
340+
* originally used by both sides, but implementations have since diverged.
341+
*/
311342
struct vchiq_state {
312343
struct device *dev;
313344
int id;
@@ -329,18 +360,27 @@ struct vchiq_state {
329360
struct mutex mutex;
330361
struct vchiq_instance **instance;
331362

332-
/* Processes incoming messages */
333-
/* TODO: This is the only thread which handles incoming messages
334-
* or just asynchronous messages ?
335-
*/
363+
/* This thread processes all incoming messages which aren't synchronous */
336364
struct task_struct *slot_handler_thread;
337365

338-
/* Processes recycled slots */
339-
/* TODO: Please elaborate more ... (purpose) */
366+
/*
367+
* Slots which have been fully processed and released by the (peer)
368+
* receiver are added to the receiver queue, which is asynchronously
369+
* processed by the recycle thread.
370+
*/
340371
struct task_struct *recycle_thread;
341372

342-
/* Processes synchronous messages */
343-
/* TODO: Please elaborate more ... (direction, purpose) */
373+
/*
374+
* Processes incoming synchronous messagses
375+
*
376+
* The synchronous message channel is shared between all synchronous
377+
* services, and provides a way for urgent messages to bypass potentially
378+
* long queues of asynchronous messages in the normal slots.
379+
*
380+
* There can be only one outstanding synchronous message in each direction,
381+
* and as a precious shared resource synchronous services should be used
382+
* sparingly.
383+
*/
344384
struct task_struct *sync_thread;
345385

346386
/* Local implementation of the trigger remote event */

0 commit comments

Comments
 (0)