2 * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
3 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The names of the above-listed copyright holders may not be used
15 * to endorse or promote products derived from this software without
16 * specific prior written permission.
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") version 2, as published by the Free
20 * Software Foundation.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/sched/signal.h>
38 #include <linux/types.h>
39 #include <linux/errno.h>
40 #include <linux/cdev.h>
42 #include <linux/device.h>
44 #include <linux/highmem.h>
45 #include <linux/pagemap.h>
46 #include <linux/bug.h>
47 #include <linux/semaphore.h>
48 #include <linux/list.h>
50 #include <linux/platform_device.h>
51 #include <linux/compat.h>
52 #include <soc/bcm2835/raspberrypi-firmware.h>
54 #include "vchiq_core.h"
55 #include "vchiq_ioctl.h"
56 #include "vchiq_arm.h"
57 #include "vchiq_debugfs.h"
58 #include "vchiq_killable.h"
60 #define DEVICE_NAME "vchiq"
62 /* Override the default prefix, which would be vchiq_arm (from the filename) */
63 #undef MODULE_PARAM_PREFIX
64 #define MODULE_PARAM_PREFIX DEVICE_NAME "."
68 /* Some per-instance constants */
69 #define MAX_COMPLETIONS 128
70 #define MAX_SERVICES 64
71 #define MAX_ELEMENTS 8
72 #define MSG_QUEUE_SIZE 128
74 #define KEEPALIVE_VER 1
75 #define KEEPALIVE_VER_MIN KEEPALIVE_VER
77 /* Run time control of log level, based on KERN_XXX level. */
78 int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
79 int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
81 #define SUSPEND_TIMER_TIMEOUT_MS 100
82 #define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
84 #define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
85 static const char *const suspend_state_names[] = {
86 "VC_SUSPEND_FORCE_CANCELED",
87 "VC_SUSPEND_REJECTED",
90 "VC_SUSPEND_REQUESTED",
91 "VC_SUSPEND_IN_PROGRESS",
92 "VC_SUSPEND_SUSPENDED"
94 #define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
95 static const char *const resume_state_names[] = {
98 "VC_RESUME_REQUESTED",
99 "VC_RESUME_IN_PROGRESS",
102 /* The number of times we allow force suspend to timeout before actually
103 ** _forcing_ suspend. This is to cater for SW which fails to release vchiq
104 ** correctly - we don't want to prevent ARM suspend indefinitely in this case.
106 #define FORCE_SUSPEND_FAIL_MAX 8
108 /* The time in ms allowed for videocore to go idle when force suspend has been
110 #define FORCE_SUSPEND_TIMEOUT_MS 200
112 static void suspend_timer_callback(struct timer_list *t);
114 typedef struct user_service_struct {
115 VCHIQ_SERVICE_T *service;
117 VCHIQ_INSTANCE_T instance;
119 char dequeue_pending;
121 int message_available_pos;
124 struct semaphore insert_event;
125 struct semaphore remove_event;
126 struct semaphore close_event;
127 VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
130 struct bulk_waiter_node {
131 struct bulk_waiter bulk_waiter;
133 struct list_head list;
136 struct vchiq_instance_struct {
137 VCHIQ_STATE_T *state;
138 VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
139 int completion_insert;
140 int completion_remove;
141 struct semaphore insert_event;
142 struct semaphore remove_event;
143 struct mutex completion_mutex;
149 int use_close_delivered;
152 struct list_head bulk_waiter_list;
153 struct mutex bulk_waiter_list_mutex;
155 VCHIQ_DEBUGFS_NODE_T debugfs_node;
158 typedef struct dump_context_struct {
165 static struct cdev vchiq_cdev;
166 static dev_t vchiq_devid;
167 static VCHIQ_STATE_T g_state;
168 static struct class *vchiq_class;
169 static struct device *vchiq_dev;
170 static DEFINE_SPINLOCK(msg_queue_spinlock);
172 static const char *const ioctl_names[] = {
178 "QUEUE_BULK_TRANSMIT",
179 "QUEUE_BULK_RECEIVE",
187 "SET_SERVICE_OPTION",
193 vchiq_static_assert(ARRAY_SIZE(ioctl_names) ==
194 (VCHIQ_IOC_MAX + 1));
196 /****************************************************************************
200 ***************************************************************************/
202 static VCHIQ_STATUS_T
203 add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
204 VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
207 VCHIQ_COMPLETION_DATA_T *completion;
210 DEBUG_INITIALISE(g_state.local)
212 insert = instance->completion_insert;
213 while ((insert - instance->completion_remove) >= MAX_COMPLETIONS) {
214 /* Out of space - wait for the client */
215 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
216 vchiq_log_trace(vchiq_arm_log_level,
217 "add_completion - completion queue full");
218 DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
219 if (down_interruptible(&instance->remove_event) != 0) {
220 vchiq_log_info(vchiq_arm_log_level,
221 "service_callback interrupted");
223 } else if (instance->closing) {
224 vchiq_log_info(vchiq_arm_log_level,
225 "service_callback closing");
226 return VCHIQ_SUCCESS;
228 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
231 completion = &instance->completions[insert & (MAX_COMPLETIONS - 1)];
233 completion->header = header;
234 completion->reason = reason;
235 /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
236 completion->service_userdata = user_service->service;
237 completion->bulk_userdata = bulk_userdata;
239 if (reason == VCHIQ_SERVICE_CLOSED) {
240 /* Take an extra reference, to be held until
241 this CLOSED notification is delivered. */
242 lock_service(user_service->service);
243 if (instance->use_close_delivered)
244 user_service->close_pending = 1;
247 /* A write barrier is needed here to ensure that the entire completion
248 record is written out before the insert point. */
251 if (reason == VCHIQ_MESSAGE_AVAILABLE)
252 user_service->message_available_pos = insert;
255 instance->completion_insert = insert;
257 up(&instance->insert_event);
259 return VCHIQ_SUCCESS;
262 /****************************************************************************
266 ***************************************************************************/
268 static VCHIQ_STATUS_T
269 service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
270 VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
272 /* How do we ensure the callback goes to the right client?
273 ** The service_user data points to a USER_SERVICE_T record containing
274 ** the original callback and the user state structure, which contains a
275 ** circular buffer for completion records.
277 USER_SERVICE_T *user_service;
278 VCHIQ_SERVICE_T *service;
279 VCHIQ_INSTANCE_T instance;
280 bool skip_completion = false;
282 DEBUG_INITIALISE(g_state.local)
284 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
286 service = handle_to_service(handle);
288 user_service = (USER_SERVICE_T *)service->base.userdata;
289 instance = user_service->instance;
291 if (!instance || instance->closing)
292 return VCHIQ_SUCCESS;
294 vchiq_log_trace(vchiq_arm_log_level,
295 "service_callback - service %lx(%d,%p), reason %d, header %lx, "
296 "instance %lx, bulk_userdata %lx",
297 (unsigned long)user_service,
298 service->localport, user_service->userdata,
299 reason, (unsigned long)header,
300 (unsigned long)instance, (unsigned long)bulk_userdata);
302 if (header && user_service->is_vchi) {
303 spin_lock(&msg_queue_spinlock);
304 while (user_service->msg_insert ==
305 (user_service->msg_remove + MSG_QUEUE_SIZE)) {
306 spin_unlock(&msg_queue_spinlock);
307 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
308 DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
309 vchiq_log_trace(vchiq_arm_log_level,
310 "service_callback - msg queue full");
311 /* If there is no MESSAGE_AVAILABLE in the completion
314 if ((user_service->message_available_pos -
315 instance->completion_remove) < 0) {
316 VCHIQ_STATUS_T status;
318 vchiq_log_info(vchiq_arm_log_level,
319 "Inserting extra MESSAGE_AVAILABLE");
320 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
321 status = add_completion(instance, reason,
322 NULL, user_service, bulk_userdata);
323 if (status != VCHIQ_SUCCESS) {
324 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
329 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
330 if (down_interruptible(&user_service->remove_event)
332 vchiq_log_info(vchiq_arm_log_level,
333 "service_callback interrupted");
334 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
336 } else if (instance->closing) {
337 vchiq_log_info(vchiq_arm_log_level,
338 "service_callback closing");
339 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
342 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
343 spin_lock(&msg_queue_spinlock);
346 user_service->msg_queue[user_service->msg_insert &
347 (MSG_QUEUE_SIZE - 1)] = header;
348 user_service->msg_insert++;
350 /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
351 ** there is a MESSAGE_AVAILABLE in the completion queue then
352 ** bypass the completion queue.
354 if (((user_service->message_available_pos -
355 instance->completion_remove) >= 0) ||
356 user_service->dequeue_pending) {
357 user_service->dequeue_pending = 0;
358 skip_completion = true;
361 spin_unlock(&msg_queue_spinlock);
362 up(&user_service->insert_event);
366 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
369 return VCHIQ_SUCCESS;
371 return add_completion(instance, reason, header, user_service,
375 /****************************************************************************
379 ***************************************************************************/
381 user_service_free(void *userdata)
386 /****************************************************************************
390 ***************************************************************************/
391 static void close_delivered(USER_SERVICE_T *user_service)
393 vchiq_log_info(vchiq_arm_log_level,
394 "close_delivered(handle=%x)",
395 user_service->service->handle);
397 if (user_service->close_pending) {
398 /* Allow the underlying service to be culled */
399 unlock_service(user_service->service);
401 /* Wake the user-thread blocked in close_ or remove_service */
402 up(&user_service->close_event);
404 user_service->close_pending = 0;
408 struct vchiq_io_copy_callback_context {
409 struct vchiq_element *current_element;
410 size_t current_element_offset;
411 unsigned long elements_to_go;
412 size_t current_offset;
416 vchiq_ioc_copy_element_data(
423 size_t bytes_this_round;
424 struct vchiq_io_copy_callback_context *copy_context =
425 (struct vchiq_io_copy_callback_context *)context;
427 if (offset != copy_context->current_offset)
430 if (!copy_context->elements_to_go)
434 * Complex logic here to handle the case of 0 size elements
435 * in the middle of the array of elements.
437 * Need to skip over these 0 size elements.
440 bytes_this_round = min(copy_context->current_element->size -
441 copy_context->current_element_offset,
444 if (bytes_this_round)
447 copy_context->elements_to_go--;
448 copy_context->current_element++;
449 copy_context->current_element_offset = 0;
451 if (!copy_context->elements_to_go)
455 res = copy_from_user(dest,
456 copy_context->current_element->data +
457 copy_context->current_element_offset,
463 copy_context->current_element_offset += bytes_this_round;
464 copy_context->current_offset += bytes_this_round;
467 * Check if done with current element, and if so advance to the next.
469 if (copy_context->current_element_offset ==
470 copy_context->current_element->size) {
471 copy_context->elements_to_go--;
472 copy_context->current_element++;
473 copy_context->current_element_offset = 0;
476 return bytes_this_round;
479 /**************************************************************************
481 * vchiq_ioc_queue_message
483 **************************************************************************/
484 static VCHIQ_STATUS_T
485 vchiq_ioc_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
486 struct vchiq_element *elements,
489 struct vchiq_io_copy_callback_context context;
491 size_t total_size = 0;
493 context.current_element = elements;
494 context.current_element_offset = 0;
495 context.elements_to_go = count;
496 context.current_offset = 0;
498 for (i = 0; i < count; i++) {
499 if (!elements[i].data && elements[i].size != 0)
502 total_size += elements[i].size;
505 return vchiq_queue_message(handle, vchiq_ioc_copy_element_data,
506 &context, total_size);
509 /****************************************************************************
513 ***************************************************************************/
515 vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
517 VCHIQ_INSTANCE_T instance = file->private_data;
518 VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
519 VCHIQ_SERVICE_T *service = NULL;
523 DEBUG_INITIALISE(g_state.local)
525 vchiq_log_trace(vchiq_arm_log_level,
526 "vchiq_ioctl - instance %pK, cmd %s, arg %lx",
528 ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
529 (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
530 ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
533 case VCHIQ_IOC_SHUTDOWN:
534 if (!instance->connected)
537 /* Remove all services */
539 while ((service = next_service_by_instance(instance->state,
540 instance, &i)) != NULL) {
541 status = vchiq_remove_service(service->handle);
542 unlock_service(service);
543 if (status != VCHIQ_SUCCESS)
548 if (status == VCHIQ_SUCCESS) {
549 /* Wake the completion thread and ask it to exit */
550 instance->closing = 1;
551 up(&instance->insert_event);
556 case VCHIQ_IOC_CONNECT:
557 if (instance->connected) {
561 rc = mutex_lock_killable(&instance->state->mutex);
563 vchiq_log_error(vchiq_arm_log_level,
564 "vchiq: connect: could not lock mutex for "
566 instance->state->id, rc);
570 status = vchiq_connect_internal(instance->state, instance);
571 mutex_unlock(&instance->state->mutex);
573 if (status == VCHIQ_SUCCESS)
574 instance->connected = 1;
576 vchiq_log_error(vchiq_arm_log_level,
577 "vchiq: could not connect: %d", status);
580 case VCHIQ_IOC_CREATE_SERVICE: {
581 VCHIQ_CREATE_SERVICE_T args;
582 USER_SERVICE_T *user_service = NULL;
587 (&args, (const void __user *)arg,
588 sizeof(args)) != 0) {
593 user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
600 if (!instance->connected) {
605 srvstate = VCHIQ_SRVSTATE_OPENING;
608 instance->connected ?
609 VCHIQ_SRVSTATE_LISTENING :
610 VCHIQ_SRVSTATE_HIDDEN;
613 userdata = args.params.userdata;
614 args.params.callback = service_callback;
615 args.params.userdata = user_service;
616 service = vchiq_add_service_internal(
618 &args.params, srvstate,
619 instance, user_service_free);
621 if (service != NULL) {
622 user_service->service = service;
623 user_service->userdata = userdata;
624 user_service->instance = instance;
625 user_service->is_vchi = (args.is_vchi != 0);
626 user_service->dequeue_pending = 0;
627 user_service->close_pending = 0;
628 user_service->message_available_pos =
629 instance->completion_remove - 1;
630 user_service->msg_insert = 0;
631 user_service->msg_remove = 0;
632 sema_init(&user_service->insert_event, 0);
633 sema_init(&user_service->remove_event, 0);
634 sema_init(&user_service->close_event, 0);
637 status = vchiq_open_service_internal
638 (service, instance->pid);
639 if (status != VCHIQ_SUCCESS) {
640 vchiq_remove_service(service->handle);
642 ret = (status == VCHIQ_RETRY) ?
648 if (copy_to_user((void __user *)
649 &(((VCHIQ_CREATE_SERVICE_T __user *)
651 (const void *)&service->handle,
652 sizeof(service->handle)) != 0) {
654 vchiq_remove_service(service->handle);
664 case VCHIQ_IOC_CLOSE_SERVICE: {
665 VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
667 service = find_service_for_instance(instance, handle);
668 if (service != NULL) {
669 USER_SERVICE_T *user_service =
670 (USER_SERVICE_T *)service->base.userdata;
671 /* close_pending is false on first entry, and when the
672 wait in vchiq_close_service has been interrupted. */
673 if (!user_service->close_pending) {
674 status = vchiq_close_service(service->handle);
675 if (status != VCHIQ_SUCCESS)
679 /* close_pending is true once the underlying service
680 has been closed until the client library calls the
681 CLOSE_DELIVERED ioctl, signalling close_event. */
682 if (user_service->close_pending &&
683 down_interruptible(&user_service->close_event))
684 status = VCHIQ_RETRY;
690 case VCHIQ_IOC_REMOVE_SERVICE: {
691 VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
693 service = find_service_for_instance(instance, handle);
694 if (service != NULL) {
695 USER_SERVICE_T *user_service =
696 (USER_SERVICE_T *)service->base.userdata;
697 /* close_pending is false on first entry, and when the
698 wait in vchiq_close_service has been interrupted. */
699 if (!user_service->close_pending) {
700 status = vchiq_remove_service(service->handle);
701 if (status != VCHIQ_SUCCESS)
705 /* close_pending is true once the underlying service
706 has been closed until the client library calls the
707 CLOSE_DELIVERED ioctl, signalling close_event. */
708 if (user_service->close_pending &&
709 down_interruptible(&user_service->close_event))
710 status = VCHIQ_RETRY;
716 case VCHIQ_IOC_USE_SERVICE:
717 case VCHIQ_IOC_RELEASE_SERVICE: {
718 VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
720 service = find_service_for_instance(instance, handle);
721 if (service != NULL) {
722 status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
723 vchiq_use_service_internal(service) :
724 vchiq_release_service_internal(service);
725 if (status != VCHIQ_SUCCESS) {
726 vchiq_log_error(vchiq_susp_log_level,
727 "%s: cmd %s returned error %d for "
728 "service %c%c%c%c:%03d",
730 (cmd == VCHIQ_IOC_USE_SERVICE) ?
731 "VCHIQ_IOC_USE_SERVICE" :
732 "VCHIQ_IOC_RELEASE_SERVICE",
734 VCHIQ_FOURCC_AS_4CHARS(
735 service->base.fourcc),
743 case VCHIQ_IOC_QUEUE_MESSAGE: {
744 VCHIQ_QUEUE_MESSAGE_T args;
747 (&args, (const void __user *)arg,
748 sizeof(args)) != 0) {
753 service = find_service_for_instance(instance, args.handle);
755 if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
756 /* Copy elements into kernel space */
757 struct vchiq_element elements[MAX_ELEMENTS];
759 if (copy_from_user(elements, args.elements,
760 args.count * sizeof(struct vchiq_element)) == 0)
761 status = vchiq_ioc_queue_message
763 elements, args.count);
771 case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
772 case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
773 VCHIQ_QUEUE_BULK_TRANSFER_T args;
774 struct bulk_waiter_node *waiter = NULL;
776 VCHIQ_BULK_DIR_T dir =
777 (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
778 VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
781 (&args, (const void __user *)arg,
782 sizeof(args)) != 0) {
787 service = find_service_for_instance(instance, args.handle);
793 if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
794 waiter = kzalloc(sizeof(struct bulk_waiter_node),
800 args.userdata = &waiter->bulk_waiter;
801 } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
802 struct list_head *pos;
804 mutex_lock(&instance->bulk_waiter_list_mutex);
805 list_for_each(pos, &instance->bulk_waiter_list) {
806 if (list_entry(pos, struct bulk_waiter_node,
807 list)->pid == current->pid) {
808 waiter = list_entry(pos,
809 struct bulk_waiter_node,
816 mutex_unlock(&instance->bulk_waiter_list_mutex);
818 vchiq_log_error(vchiq_arm_log_level,
819 "no bulk_waiter found for pid %d",
824 vchiq_log_info(vchiq_arm_log_level,
825 "found bulk_waiter %pK for pid %d", waiter,
827 args.userdata = &waiter->bulk_waiter;
829 status = vchiq_bulk_transfer
831 VCHI_MEM_HANDLE_INVALID,
832 args.data, args.size,
833 args.userdata, args.mode,
837 if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
838 !waiter->bulk_waiter.bulk) {
839 if (waiter->bulk_waiter.bulk) {
840 /* Cancel the signal when the transfer
842 spin_lock(&bulk_waiter_spinlock);
843 waiter->bulk_waiter.bulk->userdata = NULL;
844 spin_unlock(&bulk_waiter_spinlock);
848 const VCHIQ_BULK_MODE_T mode_waiting =
849 VCHIQ_BULK_MODE_WAITING;
850 waiter->pid = current->pid;
851 mutex_lock(&instance->bulk_waiter_list_mutex);
852 list_add(&waiter->list, &instance->bulk_waiter_list);
853 mutex_unlock(&instance->bulk_waiter_list_mutex);
854 vchiq_log_info(vchiq_arm_log_level,
855 "saved bulk_waiter %pK for pid %d",
856 waiter, current->pid);
858 if (copy_to_user((void __user *)
859 &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
861 (const void *)&mode_waiting,
862 sizeof(mode_waiting)) != 0)
867 case VCHIQ_IOC_AWAIT_COMPLETION: {
868 VCHIQ_AWAIT_COMPLETION_T args;
870 DEBUG_TRACE(AWAIT_COMPLETION_LINE);
871 if (!instance->connected) {
876 if (copy_from_user(&args, (const void __user *)arg,
877 sizeof(args)) != 0) {
882 mutex_lock(&instance->completion_mutex);
884 DEBUG_TRACE(AWAIT_COMPLETION_LINE);
885 while ((instance->completion_remove ==
886 instance->completion_insert)
887 && !instance->closing) {
890 DEBUG_TRACE(AWAIT_COMPLETION_LINE);
891 mutex_unlock(&instance->completion_mutex);
892 rc = down_interruptible(&instance->insert_event);
893 mutex_lock(&instance->completion_mutex);
895 DEBUG_TRACE(AWAIT_COMPLETION_LINE);
896 vchiq_log_info(vchiq_arm_log_level,
897 "AWAIT_COMPLETION interrupted");
902 DEBUG_TRACE(AWAIT_COMPLETION_LINE);
905 int msgbufcount = args.msgbufcount;
906 int remove = instance->completion_remove;
908 for (ret = 0; ret < args.count; ret++) {
909 VCHIQ_COMPLETION_DATA_T *completion;
910 VCHIQ_SERVICE_T *service;
911 USER_SERVICE_T *user_service;
912 VCHIQ_HEADER_T *header;
914 if (remove == instance->completion_insert)
917 completion = &instance->completions[
918 remove & (MAX_COMPLETIONS - 1)];
921 * A read memory barrier is needed to stop
922 * prefetch of a stale completion record
926 service = completion->service_userdata;
927 user_service = service->base.userdata;
928 completion->service_userdata =
929 user_service->userdata;
931 header = completion->header;
936 msglen = header->size +
937 sizeof(VCHIQ_HEADER_T);
938 /* This must be a VCHIQ-style service */
939 if (args.msgbufsize < msglen) {
942 "header %pK: msgbufsize %x < msglen %x",
943 header, args.msgbufsize,
945 WARN(1, "invalid message "
951 if (msgbufcount <= 0)
952 /* Stall here for lack of a
953 ** buffer for the message. */
955 /* Get the pointer from user space */
957 if (copy_from_user(&msgbuf,
958 (const void __user *)
959 &args.msgbufs[msgbufcount],
960 sizeof(msgbuf)) != 0) {
966 /* Copy the message to user space */
967 if (copy_to_user(msgbuf, header,
974 /* Now it has been copied, the message
975 ** can be released. */
976 vchiq_release_message(service->handle,
979 /* The completion must point to the
981 completion->header = msgbuf;
984 if ((completion->reason ==
985 VCHIQ_SERVICE_CLOSED) &&
986 !instance->use_close_delivered)
987 unlock_service(service);
989 if (copy_to_user((void __user *)(
991 ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
993 sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
1000 * Ensure that the above copy has completed
1001 * before advancing the remove pointer.
1005 instance->completion_remove = remove;
1008 if (msgbufcount != args.msgbufcount) {
1009 if (copy_to_user((void __user *)
1010 &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
1013 sizeof(msgbufcount)) != 0) {
1020 up(&instance->remove_event);
1021 mutex_unlock(&instance->completion_mutex);
1022 DEBUG_TRACE(AWAIT_COMPLETION_LINE);
1025 case VCHIQ_IOC_DEQUEUE_MESSAGE: {
1026 VCHIQ_DEQUEUE_MESSAGE_T args;
1027 USER_SERVICE_T *user_service;
1028 VCHIQ_HEADER_T *header;
1030 DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
1032 (&args, (const void __user *)arg,
1033 sizeof(args)) != 0) {
1037 service = find_service_for_instance(instance, args.handle);
1042 user_service = (USER_SERVICE_T *)service->base.userdata;
1043 if (user_service->is_vchi == 0) {
1048 spin_lock(&msg_queue_spinlock);
1049 if (user_service->msg_remove == user_service->msg_insert) {
1050 if (!args.blocking) {
1051 spin_unlock(&msg_queue_spinlock);
1052 DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
1056 user_service->dequeue_pending = 1;
1058 spin_unlock(&msg_queue_spinlock);
1059 DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
1060 if (down_interruptible(
1061 &user_service->insert_event) != 0) {
1062 vchiq_log_info(vchiq_arm_log_level,
1063 "DEQUEUE_MESSAGE interrupted");
1067 spin_lock(&msg_queue_spinlock);
1068 } while (user_service->msg_remove ==
1069 user_service->msg_insert);
1075 BUG_ON((int)(user_service->msg_insert -
1076 user_service->msg_remove) < 0);
1078 header = user_service->msg_queue[user_service->msg_remove &
1079 (MSG_QUEUE_SIZE - 1)];
1080 user_service->msg_remove++;
1081 spin_unlock(&msg_queue_spinlock);
1083 up(&user_service->remove_event);
1086 else if (header->size <= args.bufsize) {
1087 /* Copy to user space if msgbuf is not NULL */
1088 if ((args.buf == NULL) ||
1089 (copy_to_user((void __user *)args.buf,
1091 header->size) == 0)) {
1093 vchiq_release_message(
1099 vchiq_log_error(vchiq_arm_log_level,
1100 "header %pK: bufsize %x < size %x",
1101 header, args.bufsize, header->size);
1102 WARN(1, "invalid size\n");
1105 DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
1108 case VCHIQ_IOC_GET_CLIENT_ID: {
1109 VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
1111 ret = vchiq_get_client_id(handle);
1114 case VCHIQ_IOC_GET_CONFIG: {
1115 VCHIQ_GET_CONFIG_T args;
1116 VCHIQ_CONFIG_T config;
1118 if (copy_from_user(&args, (const void __user *)arg,
1119 sizeof(args)) != 0) {
1123 if (args.config_size > sizeof(config)) {
1127 status = vchiq_get_config(instance, args.config_size, &config);
1128 if (status == VCHIQ_SUCCESS) {
1129 if (copy_to_user((void __user *)args.pconfig,
1130 &config, args.config_size) != 0) {
1137 case VCHIQ_IOC_SET_SERVICE_OPTION: {
1138 VCHIQ_SET_SERVICE_OPTION_T args;
1141 &args, (const void __user *)arg,
1142 sizeof(args)) != 0) {
1147 service = find_service_for_instance(instance, args.handle);
1153 status = vchiq_set_service_option(
1154 args.handle, args.option, args.value);
1157 case VCHIQ_IOC_LIB_VERSION: {
1158 unsigned int lib_version = (unsigned int)arg;
1160 if (lib_version < VCHIQ_VERSION_MIN)
1162 else if (lib_version >= VCHIQ_VERSION_CLOSE_DELIVERED)
1163 instance->use_close_delivered = 1;
1166 case VCHIQ_IOC_CLOSE_DELIVERED: {
1167 VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
1169 service = find_closed_service_for_instance(instance, handle);
1170 if (service != NULL) {
1171 USER_SERVICE_T *user_service =
1172 (USER_SERVICE_T *)service->base.userdata;
1173 close_delivered(user_service);
1185 unlock_service(service);
1188 if (status == VCHIQ_ERROR)
1190 else if (status == VCHIQ_RETRY)
1194 if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
1195 (ret != -EWOULDBLOCK))
1196 vchiq_log_info(vchiq_arm_log_level,
1197 " ioctl instance %lx, cmd %s -> status %d, %ld",
1198 (unsigned long)instance,
1199 (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
1200 ioctl_names[_IOC_NR(cmd)] :
1204 vchiq_log_trace(vchiq_arm_log_level,
1205 " ioctl instance %lx, cmd %s -> status %d, %ld",
1206 (unsigned long)instance,
1207 (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
1208 ioctl_names[_IOC_NR(cmd)] :
1215 #if defined(CONFIG_COMPAT)
1217 struct vchiq_service_params32 {
1219 compat_uptr_t callback;
1220 compat_uptr_t userdata;
1221 short version; /* Increment for non-trivial changes */
1222 short version_min; /* Update for incompatible changes */
1225 struct vchiq_create_service32 {
1226 struct vchiq_service_params32 params;
1229 unsigned int handle; /* OUT */
1232 #define VCHIQ_IOC_CREATE_SERVICE32 \
1233 _IOWR(VCHIQ_IOC_MAGIC, 2, struct vchiq_create_service32)
1236 vchiq_compat_ioctl_create_service(
1241 VCHIQ_CREATE_SERVICE_T __user *args;
1242 struct vchiq_create_service32 __user *ptrargs32 =
1243 (struct vchiq_create_service32 __user *)arg;
1244 struct vchiq_create_service32 args32;
1247 args = compat_alloc_user_space(sizeof(*args));
1251 if (copy_from_user(&args32,
1252 (struct vchiq_create_service32 __user *)arg,
1256 if (put_user(args32.params.fourcc, &args->params.fourcc) ||
1257 put_user(compat_ptr(args32.params.callback),
1258 &args->params.callback) ||
1259 put_user(compat_ptr(args32.params.userdata),
1260 &args->params.userdata) ||
1261 put_user(args32.params.version, &args->params.version) ||
1262 put_user(args32.params.version_min,
1263 &args->params.version_min) ||
1264 put_user(args32.is_open, &args->is_open) ||
1265 put_user(args32.is_vchi, &args->is_vchi) ||
1266 put_user(args32.handle, &args->handle))
1269 ret = vchiq_ioctl(file, VCHIQ_IOC_CREATE_SERVICE, (unsigned long)args);
1274 if (get_user(args32.handle, &args->handle))
1277 if (copy_to_user(&ptrargs32->handle,
1279 sizeof(args32.handle)))
1285 struct vchiq_element32 {
1290 struct vchiq_queue_message32 {
1291 unsigned int handle;
1293 compat_uptr_t elements;
1296 #define VCHIQ_IOC_QUEUE_MESSAGE32 \
1297 _IOW(VCHIQ_IOC_MAGIC, 4, struct vchiq_queue_message32)
1300 vchiq_compat_ioctl_queue_message(struct file *file,
1304 VCHIQ_QUEUE_MESSAGE_T *args;
1305 struct vchiq_element *elements;
1306 struct vchiq_queue_message32 args32;
1309 if (copy_from_user(&args32,
1310 (struct vchiq_queue_message32 __user *)arg,
1314 args = compat_alloc_user_space(sizeof(*args) +
1315 (sizeof(*elements) * MAX_ELEMENTS));
1320 if (put_user(args32.handle, &args->handle) ||
1321 put_user(args32.count, &args->count) ||
1322 put_user(compat_ptr(args32.elements), &args->elements))
1325 if (args32.count > MAX_ELEMENTS)
1328 if (args32.elements && args32.count) {
1329 struct vchiq_element32 tempelement32[MAX_ELEMENTS];
1331 elements = (struct vchiq_element __user *)(args + 1);
1333 if (copy_from_user(&tempelement32,
1334 compat_ptr(args32.elements),
1335 sizeof(tempelement32)))
1338 for (count = 0; count < args32.count; count++) {
1339 if (put_user(compat_ptr(tempelement32[count].data),
1340 &elements[count].data) ||
1341 put_user(tempelement32[count].size,
1342 &elements[count].size))
1346 if (put_user(elements, &args->elements))
1350 return vchiq_ioctl(file, VCHIQ_IOC_QUEUE_MESSAGE, (unsigned long)args);
1353 struct vchiq_queue_bulk_transfer32 {
1354 unsigned int handle;
1357 compat_uptr_t userdata;
1358 VCHIQ_BULK_MODE_T mode;
1361 #define VCHIQ_IOC_QUEUE_BULK_TRANSMIT32 \
1362 _IOWR(VCHIQ_IOC_MAGIC, 5, struct vchiq_queue_bulk_transfer32)
1363 #define VCHIQ_IOC_QUEUE_BULK_RECEIVE32 \
1364 _IOWR(VCHIQ_IOC_MAGIC, 6, struct vchiq_queue_bulk_transfer32)
1367 vchiq_compat_ioctl_queue_bulk(struct file *file,
1371 VCHIQ_QUEUE_BULK_TRANSFER_T *args;
1372 struct vchiq_queue_bulk_transfer32 args32;
1373 struct vchiq_queue_bulk_transfer32 *ptrargs32 =
1374 (struct vchiq_queue_bulk_transfer32 *)arg;
1377 args = compat_alloc_user_space(sizeof(*args));
1381 if (copy_from_user(&args32,
1382 (struct vchiq_queue_bulk_transfer32 __user *)arg,
1386 if (put_user(args32.handle, &args->handle) ||
1387 put_user(compat_ptr(args32.data), &args->data) ||
1388 put_user(args32.size, &args->size) ||
1389 put_user(compat_ptr(args32.userdata), &args->userdata) ||
1390 put_user(args32.mode, &args->mode))
1393 if (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT32)
1394 cmd = VCHIQ_IOC_QUEUE_BULK_TRANSMIT;
1396 cmd = VCHIQ_IOC_QUEUE_BULK_RECEIVE;
1398 ret = vchiq_ioctl(file, cmd, (unsigned long)args);
1403 if (get_user(args32.mode, &args->mode))
1406 if (copy_to_user(&ptrargs32->mode,
1408 sizeof(args32.mode)))
1414 struct vchiq_completion_data32 {
1415 VCHIQ_REASON_T reason;
1416 compat_uptr_t header;
1417 compat_uptr_t service_userdata;
1418 compat_uptr_t bulk_userdata;
1421 struct vchiq_await_completion32 {
1424 unsigned int msgbufsize;
1425 unsigned int msgbufcount; /* IN/OUT */
1426 compat_uptr_t msgbufs;
1429 #define VCHIQ_IOC_AWAIT_COMPLETION32 \
1430 _IOWR(VCHIQ_IOC_MAGIC, 7, struct vchiq_await_completion32)
1433 vchiq_compat_ioctl_await_completion(struct file *file,
1437 VCHIQ_AWAIT_COMPLETION_T *args;
1438 VCHIQ_COMPLETION_DATA_T *completion;
1439 VCHIQ_COMPLETION_DATA_T completiontemp;
1440 struct vchiq_await_completion32 args32;
1441 struct vchiq_completion_data32 completion32;
1442 unsigned int *msgbufcount32;
1443 compat_uptr_t msgbuf32;
1448 args = compat_alloc_user_space(sizeof(*args) +
1449 sizeof(*completion) +
1450 sizeof(*msgbufptr));
1454 completion = (VCHIQ_COMPLETION_DATA_T *)(args + 1);
1455 msgbufptr = (void __user **)(completion + 1);
1457 if (copy_from_user(&args32,
1458 (struct vchiq_completion_data32 *)arg,
1462 if (put_user(args32.count, &args->count) ||
1463 put_user(compat_ptr(args32.buf), &args->buf) ||
1464 put_user(args32.msgbufsize, &args->msgbufsize) ||
1465 put_user(args32.msgbufcount, &args->msgbufcount) ||
1466 put_user(compat_ptr(args32.msgbufs), &args->msgbufs))
1469 /* These are simple cases, so just fall into the native handler */
1470 if (!args32.count || !args32.buf || !args32.msgbufcount)
1471 return vchiq_ioctl(file,
1472 VCHIQ_IOC_AWAIT_COMPLETION,
1473 (unsigned long)args);
1476 * These are the more complex cases. Typical applications of this
1477 * ioctl will use a very large count, with a very large msgbufcount.
1478 * Since the native ioctl can asynchronously fill in the returned
1479 * buffers and the application can in theory begin processing messages
1480 * even before the ioctl returns, a bit of a trick is used here.
1482 * By forcing both count and msgbufcount to be 1, it forces the native
1483 * ioctl to only claim at most 1 message is available. This tricks
1484 * the calling application into thinking only 1 message was actually
1485 * available in the queue so like all good applications it will retry
1486 * waiting until all the required messages are received.
1488 * This trick has been tested and proven to work with vchiq_test,
1489 * Minecraft_PI, the "hello pi" examples, and various other
1490 * applications that are included in Raspbian.
1493 if (copy_from_user(&msgbuf32,
1494 compat_ptr(args32.msgbufs) +
1495 (sizeof(compat_uptr_t) *
1496 (args32.msgbufcount - 1)),
1500 msgbuf = compat_ptr(msgbuf32);
1502 if (copy_to_user(msgbufptr,
1507 if (copy_to_user(&args->msgbufs,
1512 if (put_user(1U, &args->count) ||
1513 put_user(completion, &args->buf) ||
1514 put_user(1U, &args->msgbufcount))
1517 ret = vchiq_ioctl(file,
1518 VCHIQ_IOC_AWAIT_COMPLETION,
1519 (unsigned long)args);
1522 * An return value of 0 here means that no messages where available
1523 * in the message queue. In this case the native ioctl does not
1524 * return any data to the application at all. Not even to update
1525 * msgbufcount. This functionality needs to be kept here for
1528 * Of course, < 0 means that an error occurred and no data is being
1531 * Since count and msgbufcount was forced to 1, that means
1532 * the only other possible return value is 1. Meaning that 1 message
1533 * was available, so that multiple message case does not need to be
1539 if (copy_from_user(&completiontemp, completion, sizeof(*completion)))
1542 completion32.reason = completiontemp.reason;
1543 completion32.header = ptr_to_compat(completiontemp.header);
1544 completion32.service_userdata =
1545 ptr_to_compat(completiontemp.service_userdata);
1546 completion32.bulk_userdata =
1547 ptr_to_compat(completiontemp.bulk_userdata);
1549 if (copy_to_user(compat_ptr(args32.buf),
1551 sizeof(completion32)))
1554 args32.msgbufcount--;
1557 &((struct vchiq_await_completion32 __user *)arg)->msgbufcount;
1559 if (copy_to_user(msgbufcount32,
1560 &args32.msgbufcount,
1561 sizeof(args32.msgbufcount)))
1567 struct vchiq_dequeue_message32 {
1568 unsigned int handle;
1570 unsigned int bufsize;
1574 #define VCHIQ_IOC_DEQUEUE_MESSAGE32 \
1575 _IOWR(VCHIQ_IOC_MAGIC, 8, struct vchiq_dequeue_message32)
1578 vchiq_compat_ioctl_dequeue_message(struct file *file,
1582 VCHIQ_DEQUEUE_MESSAGE_T *args;
1583 struct vchiq_dequeue_message32 args32;
1585 args = compat_alloc_user_space(sizeof(*args));
1589 if (copy_from_user(&args32,
1590 (struct vchiq_dequeue_message32 *)arg,
1594 if (put_user(args32.handle, &args->handle) ||
1595 put_user(args32.blocking, &args->blocking) ||
1596 put_user(args32.bufsize, &args->bufsize) ||
1597 put_user(compat_ptr(args32.buf), &args->buf))
1600 return vchiq_ioctl(file, VCHIQ_IOC_DEQUEUE_MESSAGE,
1601 (unsigned long)args);
1604 struct vchiq_get_config32 {
1605 unsigned int config_size;
1606 compat_uptr_t pconfig;
1609 #define VCHIQ_IOC_GET_CONFIG32 \
1610 _IOWR(VCHIQ_IOC_MAGIC, 10, struct vchiq_get_config32)
1613 vchiq_compat_ioctl_get_config(struct file *file,
1617 VCHIQ_GET_CONFIG_T *args;
1618 struct vchiq_get_config32 args32;
1620 args = compat_alloc_user_space(sizeof(*args));
1624 if (copy_from_user(&args32,
1625 (struct vchiq_get_config32 *)arg,
1629 if (put_user(args32.config_size, &args->config_size) ||
1630 put_user(compat_ptr(args32.pconfig), &args->pconfig))
1633 return vchiq_ioctl(file, VCHIQ_IOC_GET_CONFIG, (unsigned long)args);
1637 vchiq_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1640 case VCHIQ_IOC_CREATE_SERVICE32:
1641 return vchiq_compat_ioctl_create_service(file, cmd, arg);
1642 case VCHIQ_IOC_QUEUE_MESSAGE32:
1643 return vchiq_compat_ioctl_queue_message(file, cmd, arg);
1644 case VCHIQ_IOC_QUEUE_BULK_TRANSMIT32:
1645 case VCHIQ_IOC_QUEUE_BULK_RECEIVE32:
1646 return vchiq_compat_ioctl_queue_bulk(file, cmd, arg);
1647 case VCHIQ_IOC_AWAIT_COMPLETION32:
1648 return vchiq_compat_ioctl_await_completion(file, cmd, arg);
1649 case VCHIQ_IOC_DEQUEUE_MESSAGE32:
1650 return vchiq_compat_ioctl_dequeue_message(file, cmd, arg);
1651 case VCHIQ_IOC_GET_CONFIG32:
1652 return vchiq_compat_ioctl_get_config(file, cmd, arg);
1654 return vchiq_ioctl(file, cmd, arg);
1660 /****************************************************************************
1664 ***************************************************************************/
1667 vchiq_open(struct inode *inode, struct file *file)
1669 int dev = iminor(inode) & 0x0f;
1671 vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
1675 VCHIQ_STATE_T *state = vchiq_get_state();
1676 VCHIQ_INSTANCE_T instance;
1679 vchiq_log_error(vchiq_arm_log_level,
1680 "vchiq has no connection to VideoCore");
1684 instance = kzalloc(sizeof(*instance), GFP_KERNEL);
1688 instance->state = state;
1689 instance->pid = current->tgid;
1691 ret = vchiq_debugfs_add_instance(instance);
1697 sema_init(&instance->insert_event, 0);
1698 sema_init(&instance->remove_event, 0);
1699 mutex_init(&instance->completion_mutex);
1700 mutex_init(&instance->bulk_waiter_list_mutex);
1701 INIT_LIST_HEAD(&instance->bulk_waiter_list);
1703 file->private_data = instance;
1707 vchiq_log_error(vchiq_arm_log_level,
1708 "Unknown minor device: %d", dev);
1715 /****************************************************************************
1719 ***************************************************************************/
1722 vchiq_release(struct inode *inode, struct file *file)
1724 int dev = iminor(inode) & 0x0f;
1729 VCHIQ_INSTANCE_T instance = file->private_data;
1730 VCHIQ_STATE_T *state = vchiq_get_state();
1731 VCHIQ_SERVICE_T *service;
1734 vchiq_log_info(vchiq_arm_log_level,
1735 "vchiq_release: instance=%lx",
1736 (unsigned long)instance);
1743 /* Ensure videocore is awake to allow termination. */
1744 vchiq_use_internal(instance->state, NULL,
1747 mutex_lock(&instance->completion_mutex);
1749 /* Wake the completion thread and ask it to exit */
1750 instance->closing = 1;
1751 up(&instance->insert_event);
1753 mutex_unlock(&instance->completion_mutex);
1755 /* Wake the slot handler if the completion queue is full. */
1756 up(&instance->remove_event);
1758 /* Mark all services for termination... */
1760 while ((service = next_service_by_instance(state, instance,
1762 USER_SERVICE_T *user_service = service->base.userdata;
1764 /* Wake the slot handler if the msg queue is full. */
1765 up(&user_service->remove_event);
1767 vchiq_terminate_service_internal(service);
1768 unlock_service(service);
1771 /* ...and wait for them to die */
1773 while ((service = next_service_by_instance(state, instance, &i))
1775 USER_SERVICE_T *user_service = service->base.userdata;
1777 down(&service->remove_event);
1779 BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
1781 spin_lock(&msg_queue_spinlock);
1783 while (user_service->msg_remove !=
1784 user_service->msg_insert) {
1785 VCHIQ_HEADER_T *header = user_service->
1786 msg_queue[user_service->msg_remove &
1787 (MSG_QUEUE_SIZE - 1)];
1788 user_service->msg_remove++;
1789 spin_unlock(&msg_queue_spinlock);
1792 vchiq_release_message(
1795 spin_lock(&msg_queue_spinlock);
1798 spin_unlock(&msg_queue_spinlock);
1800 unlock_service(service);
1803 /* Release any closed services */
1804 while (instance->completion_remove !=
1805 instance->completion_insert) {
1806 VCHIQ_COMPLETION_DATA_T *completion;
1807 VCHIQ_SERVICE_T *service;
1809 completion = &instance->completions[
1810 instance->completion_remove &
1811 (MAX_COMPLETIONS - 1)];
1812 service = completion->service_userdata;
1813 if (completion->reason == VCHIQ_SERVICE_CLOSED)
1815 USER_SERVICE_T *user_service =
1816 service->base.userdata;
1818 /* Wake any blocked user-thread */
1819 if (instance->use_close_delivered)
1820 up(&user_service->close_event);
1821 unlock_service(service);
1823 instance->completion_remove++;
1826 /* Release the PEER service count. */
1827 vchiq_release_internal(instance->state, NULL);
1830 struct list_head *pos, *next;
1832 list_for_each_safe(pos, next,
1833 &instance->bulk_waiter_list) {
1834 struct bulk_waiter_node *waiter;
1836 waiter = list_entry(pos,
1837 struct bulk_waiter_node,
1840 vchiq_log_info(vchiq_arm_log_level,
1841 "bulk_waiter - cleaned up %pK for pid %d",
1842 waiter, waiter->pid);
1847 vchiq_debugfs_remove_instance(instance);
1850 file->private_data = NULL;
1854 vchiq_log_error(vchiq_arm_log_level,
1855 "Unknown minor device: %d", dev);
1863 /****************************************************************************
1867 ***************************************************************************/
1870 vchiq_dump(void *dump_context, const char *str, int len)
1872 DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
1874 if (context->actual < context->space) {
1877 if (context->offset > 0) {
1878 int skip_bytes = min(len, (int)context->offset);
1882 context->offset -= skip_bytes;
1883 if (context->offset > 0)
1886 copy_bytes = min(len, (int)(context->space - context->actual));
1887 if (copy_bytes == 0)
1889 if (copy_to_user(context->buf + context->actual, str,
1891 context->actual = -EFAULT;
1892 context->actual += copy_bytes;
1895 /* If tne terminating NUL is included in the length, then it
1896 ** marks the end of a line and should be replaced with a
1897 ** carriage return. */
1898 if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
1901 if (copy_to_user(context->buf + context->actual - 1,
1903 context->actual = -EFAULT;
1908 /****************************************************************************
1910 * vchiq_dump_platform_instance_state
1912 ***************************************************************************/
1915 vchiq_dump_platform_instances(void *dump_context)
1917 VCHIQ_STATE_T *state = vchiq_get_state();
1922 /* There is no list of instances, so instead scan all services,
1923 marking those that have been dumped. */
1925 for (i = 0; i < state->unused_service; i++) {
1926 VCHIQ_SERVICE_T *service = state->services[i];
1927 VCHIQ_INSTANCE_T instance;
1929 if (service && (service->base.callback == service_callback)) {
1930 instance = service->instance;
1936 for (i = 0; i < state->unused_service; i++) {
1937 VCHIQ_SERVICE_T *service = state->services[i];
1938 VCHIQ_INSTANCE_T instance;
1940 if (service && (service->base.callback == service_callback)) {
1941 instance = service->instance;
1942 if (instance && !instance->mark) {
1943 len = snprintf(buf, sizeof(buf),
1944 "Instance %pK: pid %d,%s completions %d/%d",
1945 instance, instance->pid,
1946 instance->connected ? " connected, " :
1948 instance->completion_insert -
1949 instance->completion_remove,
1952 vchiq_dump(dump_context, buf, len + 1);
1960 /****************************************************************************
1962 * vchiq_dump_platform_service_state
1964 ***************************************************************************/
1967 vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
1969 USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
1973 len = snprintf(buf, sizeof(buf), " instance %pK", service->instance);
1975 if ((service->base.callback == service_callback) &&
1976 user_service->is_vchi) {
1977 len += snprintf(buf + len, sizeof(buf) - len,
1979 user_service->msg_insert - user_service->msg_remove,
1982 if (user_service->dequeue_pending)
1983 len += snprintf(buf + len, sizeof(buf) - len,
1984 " (dequeue pending)");
1987 vchiq_dump(dump_context, buf, len + 1);
1990 /****************************************************************************
1994 ***************************************************************************/
1997 vchiq_read(struct file *file, char __user *buf,
1998 size_t count, loff_t *ppos)
2000 DUMP_CONTEXT_T context;
2004 context.space = count;
2005 context.offset = *ppos;
2007 vchiq_dump_state(&context, &g_state);
2009 *ppos += context.actual;
2011 return context.actual;
2015 vchiq_get_state(void)
2018 if (g_state.remote == NULL)
2019 printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
2020 else if (g_state.remote->initialised != 1)
2021 printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
2022 __func__, g_state.remote->initialised);
2024 return ((g_state.remote != NULL) &&
2025 (g_state.remote->initialised == 1)) ? &g_state : NULL;
2028 static const struct file_operations
2030 .owner = THIS_MODULE,
2031 .unlocked_ioctl = vchiq_ioctl,
2032 #if defined(CONFIG_COMPAT)
2033 .compat_ioctl = vchiq_compat_ioctl,
2036 .release = vchiq_release,
2041 * Autosuspend related functionality
2045 vchiq_videocore_wanted(VCHIQ_STATE_T *state)
2047 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2050 /* autosuspend not supported - always return wanted */
2052 else if (arm_state->blocked_count)
2054 else if (!arm_state->videocore_use_count)
2055 /* usage count zero - check for override unless we're forcing */
2056 if (arm_state->resume_blocked)
2059 return vchiq_platform_videocore_wanted(state);
2061 /* non-zero usage count - videocore still required */
2065 static VCHIQ_STATUS_T
2066 vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
2067 VCHIQ_HEADER_T *header,
2068 VCHIQ_SERVICE_HANDLE_T service_user,
2071 vchiq_log_error(vchiq_susp_log_level,
2072 "%s callback reason %d", __func__, reason);
2077 vchiq_keepalive_thread_func(void *v)
2079 VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
2080 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2082 VCHIQ_STATUS_T status;
2083 VCHIQ_INSTANCE_T instance;
2084 VCHIQ_SERVICE_HANDLE_T ka_handle;
2086 VCHIQ_SERVICE_PARAMS_T params = {
2087 .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
2088 .callback = vchiq_keepalive_vchiq_callback,
2089 .version = KEEPALIVE_VER,
2090 .version_min = KEEPALIVE_VER_MIN
2093 status = vchiq_initialise(&instance);
2094 if (status != VCHIQ_SUCCESS) {
2095 vchiq_log_error(vchiq_susp_log_level,
2096 "%s vchiq_initialise failed %d", __func__, status);
2100 status = vchiq_connect(instance);
2101 if (status != VCHIQ_SUCCESS) {
2102 vchiq_log_error(vchiq_susp_log_level,
2103 "%s vchiq_connect failed %d", __func__, status);
2107 status = vchiq_add_service(instance, ¶ms, &ka_handle);
2108 if (status != VCHIQ_SUCCESS) {
2109 vchiq_log_error(vchiq_susp_log_level,
2110 "%s vchiq_open_service failed %d", __func__, status);
2115 long rc = 0, uc = 0;
2117 if (wait_for_completion_interruptible(&arm_state->ka_evt)
2119 vchiq_log_error(vchiq_susp_log_level,
2120 "%s interrupted", __func__);
2121 flush_signals(current);
2125 /* read and clear counters. Do release_count then use_count to
2126 * prevent getting more releases than uses */
2127 rc = atomic_xchg(&arm_state->ka_release_count, 0);
2128 uc = atomic_xchg(&arm_state->ka_use_count, 0);
2130 /* Call use/release service the requisite number of times.
2131 * Process use before release so use counts don't go negative */
2133 atomic_inc(&arm_state->ka_use_ack_count);
2134 status = vchiq_use_service(ka_handle);
2135 if (status != VCHIQ_SUCCESS) {
2136 vchiq_log_error(vchiq_susp_log_level,
2137 "%s vchiq_use_service error %d",
2142 status = vchiq_release_service(ka_handle);
2143 if (status != VCHIQ_SUCCESS) {
2144 vchiq_log_error(vchiq_susp_log_level,
2145 "%s vchiq_release_service error %d",
2152 vchiq_shutdown(instance);
2158 vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
2161 rwlock_init(&arm_state->susp_res_lock);
2163 init_completion(&arm_state->ka_evt);
2164 atomic_set(&arm_state->ka_use_count, 0);
2165 atomic_set(&arm_state->ka_use_ack_count, 0);
2166 atomic_set(&arm_state->ka_release_count, 0);
2168 init_completion(&arm_state->vc_suspend_complete);
2170 init_completion(&arm_state->vc_resume_complete);
2171 /* Initialise to 'done' state. We only want to block on resume
2172 * completion while videocore is suspended. */
2173 set_resume_state(arm_state, VC_RESUME_RESUMED);
2175 init_completion(&arm_state->resume_blocker);
2176 /* Initialise to 'done' state. We only want to block on this
2177 * completion while resume is blocked */
2178 complete_all(&arm_state->resume_blocker);
2180 init_completion(&arm_state->blocked_blocker);
2181 /* Initialise to 'done' state. We only want to block on this
2182 * completion while things are waiting on the resume blocker */
2183 complete_all(&arm_state->blocked_blocker);
2185 arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
2186 arm_state->suspend_timer_running = 0;
2187 arm_state->state = state;
2188 timer_setup(&arm_state->suspend_timer, suspend_timer_callback,
2191 arm_state->first_connect = 0;
2194 return VCHIQ_SUCCESS;
2198 ** Functions to modify the state variables;
2199 ** set_suspend_state
2202 ** There are more state variables than we might like, so ensure they remain in
2203 ** step. Suspend and resume state are maintained separately, since most of
2204 ** these state machines can operate independently. However, there are a few
2205 ** states where state transitions in one state machine cause a reset to the
2206 ** other state machine. In addition, there are some completion events which
2207 ** need to occur on state machine reset and end-state(s), so these are also
2208 ** dealt with in these functions.
2210 ** In all states we set the state variable according to the input, but in some
2211 ** cases we perform additional steps outlined below;
2213 ** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
2214 ** The suspend completion is completed after any suspend
2215 ** attempt. When we reset the state machine we also reset
2216 ** the completion. This reset occurs when videocore is
2217 ** resumed, and also if we initiate suspend after a suspend
2220 ** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
2221 ** suspend - ie from this point on we must try to suspend
2222 ** before resuming can occur. We therefore also reset the
2223 ** resume state machine to VC_RESUME_IDLE in this state.
2225 ** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
2226 ** complete_all on the suspend completion to notify
2227 ** anything waiting for suspend to happen.
2229 ** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
2230 ** initiate resume, so no need to alter resume state.
2231 ** We call complete_all on the suspend completion to notify
2232 ** of suspend rejection.
2234 ** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
2235 ** suspend completion and reset the resume state machine.
2237 ** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
2238 ** resume completion is in it's 'done' state whenever
2239 ** videcore is running. Therefore, the VC_RESUME_IDLE
2240 ** state implies that videocore is suspended.
2241 ** Hence, any thread which needs to wait until videocore is
2242 ** running can wait on this completion - it will only block
2243 ** if videocore is suspended.
2245 ** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
2246 ** Call complete_all on the resume completion to unblock
2247 ** any threads waiting for resume. Also reset the suspend
2248 ** state machine to it's idle state.
2250 ** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
2254 set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
2255 enum vc_suspend_status new_state)
2257 /* set the state in all cases */
2258 arm_state->vc_suspend_state = new_state;
2260 /* state specific additional actions */
2261 switch (new_state) {
2262 case VC_SUSPEND_FORCE_CANCELED:
2263 complete_all(&arm_state->vc_suspend_complete);
2265 case VC_SUSPEND_REJECTED:
2266 complete_all(&arm_state->vc_suspend_complete);
2268 case VC_SUSPEND_FAILED:
2269 complete_all(&arm_state->vc_suspend_complete);
2270 arm_state->vc_resume_state = VC_RESUME_RESUMED;
2271 complete_all(&arm_state->vc_resume_complete);
2273 case VC_SUSPEND_IDLE:
2274 reinit_completion(&arm_state->vc_suspend_complete);
2276 case VC_SUSPEND_REQUESTED:
2278 case VC_SUSPEND_IN_PROGRESS:
2279 set_resume_state(arm_state, VC_RESUME_IDLE);
2281 case VC_SUSPEND_SUSPENDED:
2282 complete_all(&arm_state->vc_suspend_complete);
2291 set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
2292 enum vc_resume_status new_state)
2294 /* set the state in all cases */
2295 arm_state->vc_resume_state = new_state;
2297 /* state specific additional actions */
2298 switch (new_state) {
2299 case VC_RESUME_FAILED:
2301 case VC_RESUME_IDLE:
2302 reinit_completion(&arm_state->vc_resume_complete);
2304 case VC_RESUME_REQUESTED:
2306 case VC_RESUME_IN_PROGRESS:
2308 case VC_RESUME_RESUMED:
2309 complete_all(&arm_state->vc_resume_complete);
2310 set_suspend_state(arm_state, VC_SUSPEND_IDLE);
2318 /* should be called with the write lock held */
2320 start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
2322 del_timer(&arm_state->suspend_timer);
2323 arm_state->suspend_timer.expires = jiffies +
2324 msecs_to_jiffies(arm_state->
2325 suspend_timer_timeout);
2326 add_timer(&arm_state->suspend_timer);
2327 arm_state->suspend_timer_running = 1;
2330 /* should be called with the write lock held */
2332 stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
2334 if (arm_state->suspend_timer_running) {
2335 del_timer(&arm_state->suspend_timer);
2336 arm_state->suspend_timer_running = 0;
2341 need_resume(VCHIQ_STATE_T *state)
2343 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2345 return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
2346 (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
2347 vchiq_videocore_wanted(state);
2351 block_resume(VCHIQ_ARM_STATE_T *arm_state)
2353 int status = VCHIQ_SUCCESS;
2354 const unsigned long timeout_val =
2355 msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
2356 int resume_count = 0;
2358 /* Allow any threads which were blocked by the last force suspend to
2359 * complete if they haven't already. Only give this one shot; if
2360 * blocked_count is incremented after blocked_blocker is completed
2361 * (which only happens when blocked_count hits 0) then those threads
2362 * will have to wait until next time around */
2363 if (arm_state->blocked_count) {
2364 reinit_completion(&arm_state->blocked_blocker);
2365 write_unlock_bh(&arm_state->susp_res_lock);
2366 vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
2367 "blocked clients", __func__);
2368 if (wait_for_completion_interruptible_timeout(
2369 &arm_state->blocked_blocker, timeout_val)
2371 vchiq_log_error(vchiq_susp_log_level, "%s wait for "
2372 "previously blocked clients failed", __func__);
2373 status = VCHIQ_ERROR;
2374 write_lock_bh(&arm_state->susp_res_lock);
2377 vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
2378 "clients resumed", __func__);
2379 write_lock_bh(&arm_state->susp_res_lock);
2382 /* We need to wait for resume to complete if it's in process */
2383 while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
2384 arm_state->vc_resume_state > VC_RESUME_IDLE) {
2385 if (resume_count > 1) {
2386 status = VCHIQ_ERROR;
2387 vchiq_log_error(vchiq_susp_log_level, "%s waited too "
2388 "many times for resume", __func__);
2391 write_unlock_bh(&arm_state->susp_res_lock);
2392 vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
2394 if (wait_for_completion_interruptible_timeout(
2395 &arm_state->vc_resume_complete, timeout_val)
2397 vchiq_log_error(vchiq_susp_log_level, "%s wait for "
2398 "resume failed (%s)", __func__,
2399 resume_state_names[arm_state->vc_resume_state +
2400 VC_RESUME_NUM_OFFSET]);
2401 status = VCHIQ_ERROR;
2402 write_lock_bh(&arm_state->susp_res_lock);
2405 vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
2406 write_lock_bh(&arm_state->susp_res_lock);
2409 reinit_completion(&arm_state->resume_blocker);
2410 arm_state->resume_blocked = 1;
2417 unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
2419 complete_all(&arm_state->resume_blocker);
2420 arm_state->resume_blocked = 0;
2423 /* Initiate suspend via slot handler. Should be called with the write lock
2426 vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
2428 VCHIQ_STATUS_T status = VCHIQ_ERROR;
2429 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2434 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2435 status = VCHIQ_SUCCESS;
2437 switch (arm_state->vc_suspend_state) {
2438 case VC_SUSPEND_REQUESTED:
2439 vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
2440 "requested", __func__);
2442 case VC_SUSPEND_IN_PROGRESS:
2443 vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
2444 "progress", __func__);
2448 /* We don't expect to be in other states, so log but continue
2450 vchiq_log_error(vchiq_susp_log_level,
2451 "%s unexpected suspend state %s", __func__,
2452 suspend_state_names[arm_state->vc_suspend_state +
2453 VC_SUSPEND_NUM_OFFSET]);
2455 case VC_SUSPEND_REJECTED:
2456 case VC_SUSPEND_FAILED:
2457 /* Ensure any idle state actions have been run */
2458 set_suspend_state(arm_state, VC_SUSPEND_IDLE);
2460 case VC_SUSPEND_IDLE:
2461 vchiq_log_info(vchiq_susp_log_level,
2462 "%s: suspending", __func__);
2463 set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
2464 /* kick the slot handler thread to initiate suspend */
2465 request_poll(state, NULL, 0);
2470 vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
2475 vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
2477 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2483 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2485 write_lock_bh(&arm_state->susp_res_lock);
2486 if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
2487 arm_state->vc_resume_state == VC_RESUME_RESUMED) {
2488 set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
2491 write_unlock_bh(&arm_state->susp_res_lock);
2494 vchiq_platform_suspend(state);
2497 vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
2502 output_timeout_error(VCHIQ_STATE_T *state)
2504 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2506 int vc_use_count = arm_state->videocore_use_count;
2507 int active_services = state->unused_service;
2510 if (!arm_state->videocore_use_count) {
2511 snprintf(err, sizeof(err), " Videocore usecount is 0");
2514 for (i = 0; i < active_services; i++) {
2515 VCHIQ_SERVICE_T *service_ptr = state->services[i];
2517 if (service_ptr && service_ptr->service_use_count &&
2518 (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
2519 snprintf(err, sizeof(err), " %c%c%c%c(%d) service has "
2520 "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
2521 service_ptr->base.fourcc),
2522 service_ptr->client_id,
2523 service_ptr->service_use_count,
2524 service_ptr->service_use_count ==
2525 vc_use_count ? "" : " (+ more)");
2531 vchiq_log_error(vchiq_susp_log_level,
2532 "timed out waiting for vc suspend (%d).%s",
2533 arm_state->autosuspend_override, err);
2537 /* Try to get videocore into suspended state, regardless of autosuspend state.
2538 ** We don't actually force suspend, since videocore may get into a bad state
2539 ** if we force suspend at a bad time. Instead, we wait for autosuspend to
2540 ** determine a good point to suspend. If this doesn't happen within 100ms we
2543 ** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
2544 ** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
2547 vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
2549 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2550 VCHIQ_STATUS_T status = VCHIQ_ERROR;
2557 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2559 write_lock_bh(&arm_state->susp_res_lock);
2561 status = block_resume(arm_state);
2562 if (status != VCHIQ_SUCCESS)
2564 if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
2565 /* Already suspended - just block resume and exit */
2566 vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
2568 status = VCHIQ_SUCCESS;
2570 } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
2571 /* initiate suspend immediately in the case that we're waiting
2572 * for the timeout */
2573 stop_suspend_timer(arm_state);
2574 if (!vchiq_videocore_wanted(state)) {
2575 vchiq_log_info(vchiq_susp_log_level, "%s videocore "
2576 "idle, initiating suspend", __func__);
2577 status = vchiq_arm_vcsuspend(state);
2578 } else if (arm_state->autosuspend_override <
2579 FORCE_SUSPEND_FAIL_MAX) {
2580 vchiq_log_info(vchiq_susp_log_level, "%s letting "
2581 "videocore go idle", __func__);
2582 status = VCHIQ_SUCCESS;
2584 vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
2585 "many times - attempting suspend", __func__);
2586 status = vchiq_arm_vcsuspend(state);
2589 vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
2590 "in progress - wait for completion", __func__);
2591 status = VCHIQ_SUCCESS;
2594 /* Wait for suspend to happen due to system idle (not forced..) */
2595 if (status != VCHIQ_SUCCESS)
2596 goto unblock_resume;
2599 write_unlock_bh(&arm_state->susp_res_lock);
2601 rc = wait_for_completion_interruptible_timeout(
2602 &arm_state->vc_suspend_complete,
2603 msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
2605 write_lock_bh(&arm_state->susp_res_lock);
2607 vchiq_log_warning(vchiq_susp_log_level, "%s "
2608 "interrupted waiting for suspend", __func__);
2609 status = VCHIQ_ERROR;
2610 goto unblock_resume;
2611 } else if (rc == 0) {
2612 if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
2613 /* Repeat timeout once if in progress */
2619 arm_state->autosuspend_override++;
2620 output_timeout_error(state);
2622 status = VCHIQ_RETRY;
2623 goto unblock_resume;
2625 } while (0 < (repeat--));
2627 /* Check and report state in case we need to abort ARM suspend */
2628 if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
2629 status = VCHIQ_RETRY;
2630 vchiq_log_error(vchiq_susp_log_level,
2631 "%s videocore suspend failed (state %s)", __func__,
2632 suspend_state_names[arm_state->vc_suspend_state +
2633 VC_SUSPEND_NUM_OFFSET]);
2634 /* Reset the state only if it's still in an error state.
2635 * Something could have already initiated another suspend. */
2636 if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
2637 set_suspend_state(arm_state, VC_SUSPEND_IDLE);
2639 goto unblock_resume;
2642 /* successfully suspended - unlock and exit */
2646 /* all error states need to unblock resume before exit */
2647 unblock_resume(arm_state);
2650 write_unlock_bh(&arm_state->susp_res_lock);
2653 vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
2658 vchiq_check_suspend(VCHIQ_STATE_T *state)
2660 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2665 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2667 write_lock_bh(&arm_state->susp_res_lock);
2668 if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
2669 arm_state->first_connect &&
2670 !vchiq_videocore_wanted(state)) {
2671 vchiq_arm_vcsuspend(state);
2673 write_unlock_bh(&arm_state->susp_res_lock);
2676 vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
2681 vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
2683 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2690 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2692 write_lock_bh(&arm_state->susp_res_lock);
2693 unblock_resume(arm_state);
2694 resume = vchiq_check_resume(state);
2695 write_unlock_bh(&arm_state->susp_res_lock);
2698 if (wait_for_completion_interruptible(
2699 &arm_state->vc_resume_complete) < 0) {
2700 vchiq_log_error(vchiq_susp_log_level,
2701 "%s interrupted", __func__);
2702 /* failed, cannot accurately derive suspend
2703 * state, so exit early. */
2708 read_lock_bh(&arm_state->susp_res_lock);
2709 if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
2710 vchiq_log_info(vchiq_susp_log_level,
2711 "%s: Videocore remains suspended", __func__);
2713 vchiq_log_info(vchiq_susp_log_level,
2714 "%s: Videocore resumed", __func__);
2717 read_unlock_bh(&arm_state->susp_res_lock);
2719 vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
2723 /* This function should be called with the write lock held */
2725 vchiq_check_resume(VCHIQ_STATE_T *state)
2727 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2733 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2735 if (need_resume(state)) {
2736 set_resume_state(arm_state, VC_RESUME_REQUESTED);
2737 request_poll(state, NULL, 0);
2742 vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
2747 vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
2748 enum USE_TYPE_E use_type)
2750 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2751 VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
2754 int local_uc, local_entity_uc;
2759 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2761 if (use_type == USE_TYPE_VCHIQ) {
2762 sprintf(entity, "VCHIQ: ");
2763 entity_uc = &arm_state->peer_use_count;
2764 } else if (service) {
2765 sprintf(entity, "%c%c%c%c:%03d",
2766 VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
2767 service->client_id);
2768 entity_uc = &service->service_use_count;
2770 vchiq_log_error(vchiq_susp_log_level, "%s null service "
2776 write_lock_bh(&arm_state->susp_res_lock);
2777 while (arm_state->resume_blocked) {
2778 /* If we call 'use' while force suspend is waiting for suspend,
2779 * then we're about to block the thread which the force is
2780 * waiting to complete, so we're bound to just time out. In this
2781 * case, set the suspend state such that the wait will be
2782 * canceled, so we can complete as quickly as possible. */
2783 if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
2785 set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
2788 /* If suspend is already in progress then we need to block */
2789 if (!try_wait_for_completion(&arm_state->resume_blocker)) {
2790 /* Indicate that there are threads waiting on the resume
2791 * blocker. These need to be allowed to complete before
2792 * a _second_ call to force suspend can complete,
2793 * otherwise low priority threads might never actually
2795 arm_state->blocked_count++;
2796 write_unlock_bh(&arm_state->susp_res_lock);
2797 vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
2798 "blocked - waiting...", __func__, entity);
2799 if (wait_for_completion_killable(
2800 &arm_state->resume_blocker) != 0) {
2801 vchiq_log_error(vchiq_susp_log_level, "%s %s "
2802 "wait for resume blocker interrupted",
2805 write_lock_bh(&arm_state->susp_res_lock);
2806 arm_state->blocked_count--;
2807 write_unlock_bh(&arm_state->susp_res_lock);
2810 vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
2811 "unblocked", __func__, entity);
2812 write_lock_bh(&arm_state->susp_res_lock);
2813 if (--arm_state->blocked_count == 0)
2814 complete_all(&arm_state->blocked_blocker);
2818 stop_suspend_timer(arm_state);
2820 local_uc = ++arm_state->videocore_use_count;
2821 local_entity_uc = ++(*entity_uc);
2823 /* If there's a pending request which hasn't yet been serviced then
2824 * just clear it. If we're past VC_SUSPEND_REQUESTED state then
2825 * vc_resume_complete will block until we either resume or fail to
2827 if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
2828 set_suspend_state(arm_state, VC_SUSPEND_IDLE);
2830 if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
2831 set_resume_state(arm_state, VC_RESUME_REQUESTED);
2832 vchiq_log_info(vchiq_susp_log_level,
2833 "%s %s count %d, state count %d",
2834 __func__, entity, local_entity_uc, local_uc);
2835 request_poll(state, NULL, 0);
2837 vchiq_log_trace(vchiq_susp_log_level,
2838 "%s %s count %d, state count %d",
2839 __func__, entity, *entity_uc, local_uc);
2841 write_unlock_bh(&arm_state->susp_res_lock);
2843 /* Completion is in a done state when we're not suspended, so this won't
2844 * block for the non-suspended case. */
2845 if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
2846 vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
2848 if (wait_for_completion_killable(
2849 &arm_state->vc_resume_complete) != 0) {
2850 vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
2851 "resume interrupted", __func__, entity);
2855 vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
2859 if (ret == VCHIQ_SUCCESS) {
2860 VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
2861 long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
2863 while (ack_cnt && (status == VCHIQ_SUCCESS)) {
2864 /* Send the use notify to videocore */
2865 status = vchiq_send_remote_use_active(state);
2866 if (status == VCHIQ_SUCCESS)
2870 &arm_state->ka_use_ack_count);
2875 vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
2880 vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
2882 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2883 VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
2886 int local_uc, local_entity_uc;
2891 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2894 sprintf(entity, "%c%c%c%c:%03d",
2895 VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
2896 service->client_id);
2897 entity_uc = &service->service_use_count;
2899 sprintf(entity, "PEER: ");
2900 entity_uc = &arm_state->peer_use_count;
2903 write_lock_bh(&arm_state->susp_res_lock);
2904 if (!arm_state->videocore_use_count || !(*entity_uc)) {
2905 /* Don't use BUG_ON - don't allow user thread to crash kernel */
2906 WARN_ON(!arm_state->videocore_use_count);
2907 WARN_ON(!(*entity_uc));
2911 local_uc = --arm_state->videocore_use_count;
2912 local_entity_uc = --(*entity_uc);
2914 if (!vchiq_videocore_wanted(state)) {
2915 if (vchiq_platform_use_suspend_timer() &&
2916 !arm_state->resume_blocked) {
2917 /* Only use the timer if we're not trying to force
2918 * suspend (=> resume_blocked) */
2919 start_suspend_timer(arm_state);
2921 vchiq_log_info(vchiq_susp_log_level,
2922 "%s %s count %d, state count %d - suspending",
2923 __func__, entity, *entity_uc,
2924 arm_state->videocore_use_count);
2925 vchiq_arm_vcsuspend(state);
2928 vchiq_log_trace(vchiq_susp_log_level,
2929 "%s %s count %d, state count %d",
2930 __func__, entity, *entity_uc,
2931 arm_state->videocore_use_count);
2934 write_unlock_bh(&arm_state->susp_res_lock);
2937 vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
2942 vchiq_on_remote_use(VCHIQ_STATE_T *state)
2944 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2946 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2947 atomic_inc(&arm_state->ka_use_count);
2948 complete(&arm_state->ka_evt);
2952 vchiq_on_remote_release(VCHIQ_STATE_T *state)
2954 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2956 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2957 atomic_inc(&arm_state->ka_release_count);
2958 complete(&arm_state->ka_evt);
2962 vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
2964 return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
2968 vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
2970 return vchiq_release_internal(service->state, service);
2973 VCHIQ_DEBUGFS_NODE_T *
2974 vchiq_instance_get_debugfs_node(VCHIQ_INSTANCE_T instance)
2976 return &instance->debugfs_node;
2980 vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
2982 VCHIQ_SERVICE_T *service;
2983 int use_count = 0, i;
2986 while ((service = next_service_by_instance(instance->state,
2987 instance, &i)) != NULL) {
2988 use_count += service->service_use_count;
2989 unlock_service(service);
2995 vchiq_instance_get_pid(VCHIQ_INSTANCE_T instance)
2997 return instance->pid;
3001 vchiq_instance_get_trace(VCHIQ_INSTANCE_T instance)
3003 return instance->trace;
3007 vchiq_instance_set_trace(VCHIQ_INSTANCE_T instance, int trace)
3009 VCHIQ_SERVICE_T *service;
3013 while ((service = next_service_by_instance(instance->state,
3014 instance, &i)) != NULL) {
3015 service->trace = trace;
3016 unlock_service(service);
3018 instance->trace = (trace != 0);
3021 static void suspend_timer_callback(struct timer_list *t)
3023 VCHIQ_ARM_STATE_T *arm_state = from_timer(arm_state, t, suspend_timer);
3024 VCHIQ_STATE_T *state = arm_state->state;
3026 vchiq_log_info(vchiq_susp_log_level,
3027 "%s - suspend timer expired - check suspend", __func__);
3028 vchiq_check_suspend(state);
3032 vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
3034 VCHIQ_STATUS_T ret = VCHIQ_ERROR;
3035 VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
3038 ret = vchiq_use_internal(service->state, service,
3039 USE_TYPE_SERVICE_NO_RESUME);
3040 unlock_service(service);
3046 vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
3048 VCHIQ_STATUS_T ret = VCHIQ_ERROR;
3049 VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
3052 ret = vchiq_use_internal(service->state, service,
3054 unlock_service(service);
3060 vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
3062 VCHIQ_STATUS_T ret = VCHIQ_ERROR;
3063 VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
3066 ret = vchiq_release_internal(service->state, service);
3067 unlock_service(service);
3073 vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
3075 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
3077 /* Only dump 64 services */
3078 static const int local_max_services = 64;
3079 /* If there's more than 64 services, only dump ones with
3080 * non-zero counts */
3081 int only_nonzero = 0;
3082 static const char *nz = "<-- preventing suspend";
3084 enum vc_suspend_status vc_suspend_state;
3085 enum vc_resume_status vc_resume_state;
3088 int active_services;
3089 struct service_data_struct {
3093 } service_data[local_max_services];
3098 read_lock_bh(&arm_state->susp_res_lock);
3099 vc_suspend_state = arm_state->vc_suspend_state;
3100 vc_resume_state = arm_state->vc_resume_state;
3101 peer_count = arm_state->peer_use_count;
3102 vc_use_count = arm_state->videocore_use_count;
3103 active_services = state->unused_service;
3104 if (active_services > local_max_services)
3107 for (i = 0; (i < active_services) && (j < local_max_services); i++) {
3108 VCHIQ_SERVICE_T *service_ptr = state->services[i];
3113 if (only_nonzero && !service_ptr->service_use_count)
3116 if (service_ptr->srvstate == VCHIQ_SRVSTATE_FREE)
3119 service_data[j].fourcc = service_ptr->base.fourcc;
3120 service_data[j].clientid = service_ptr->client_id;
3121 service_data[j++].use_count = service_ptr->service_use_count;
3124 read_unlock_bh(&arm_state->susp_res_lock);
3126 vchiq_log_warning(vchiq_susp_log_level,
3127 "-- Videcore suspend state: %s --",
3128 suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
3129 vchiq_log_warning(vchiq_susp_log_level,
3130 "-- Videcore resume state: %s --",
3131 resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
3134 vchiq_log_warning(vchiq_susp_log_level, "Too many active "
3135 "services (%d). Only dumping up to first %d services "
3136 "with non-zero use-count", active_services,
3137 local_max_services);
3139 for (i = 0; i < j; i++) {
3140 vchiq_log_warning(vchiq_susp_log_level,
3141 "----- %c%c%c%c:%d service count %d %s",
3142 VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
3143 service_data[i].clientid,
3144 service_data[i].use_count,
3145 service_data[i].use_count ? nz : "");
3147 vchiq_log_warning(vchiq_susp_log_level,
3148 "----- VCHIQ use count count %d", peer_count);
3149 vchiq_log_warning(vchiq_susp_log_level,
3150 "--- Overall vchiq instance use count %d", vc_use_count);
3152 vchiq_dump_platform_use_state(state);
3156 vchiq_check_service(VCHIQ_SERVICE_T *service)
3158 VCHIQ_ARM_STATE_T *arm_state;
3159 VCHIQ_STATUS_T ret = VCHIQ_ERROR;
3161 if (!service || !service->state)
3164 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
3166 arm_state = vchiq_platform_get_arm_state(service->state);
3168 read_lock_bh(&arm_state->susp_res_lock);
3169 if (service->service_use_count)
3170 ret = VCHIQ_SUCCESS;
3171 read_unlock_bh(&arm_state->susp_res_lock);
3173 if (ret == VCHIQ_ERROR) {
3174 vchiq_log_error(vchiq_susp_log_level,
3175 "%s ERROR - %c%c%c%c:%d service count %d, "
3176 "state count %d, videocore suspend state %s", __func__,
3177 VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
3178 service->client_id, service->service_use_count,
3179 arm_state->videocore_use_count,
3180 suspend_state_names[arm_state->vc_suspend_state +
3181 VC_SUSPEND_NUM_OFFSET]);
3182 vchiq_dump_service_use_state(service->state);
3188 /* stub functions */
3189 void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
3194 void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
3195 VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
3197 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
3199 vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
3200 get_conn_state_name(oldstate), get_conn_state_name(newstate));
3201 if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
3202 write_lock_bh(&arm_state->susp_res_lock);
3203 if (!arm_state->first_connect) {
3204 char threadname[16];
3206 arm_state->first_connect = 1;
3207 write_unlock_bh(&arm_state->susp_res_lock);
3208 snprintf(threadname, sizeof(threadname), "vchiq-keep/%d",
3210 arm_state->ka_thread = kthread_create(
3211 &vchiq_keepalive_thread_func,
3214 if (IS_ERR(arm_state->ka_thread)) {
3215 vchiq_log_error(vchiq_susp_log_level,
3216 "vchiq: FATAL: couldn't create thread %s",
3219 wake_up_process(arm_state->ka_thread);
3222 write_unlock_bh(&arm_state->susp_res_lock);
3226 static int vchiq_probe(struct platform_device *pdev)
3228 struct device_node *fw_node;
3229 struct rpi_firmware *fw;
3232 fw_node = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
3234 dev_err(&pdev->dev, "Missing firmware node\n");
3238 fw = rpi_firmware_get(fw_node);
3239 of_node_put(fw_node);
3241 return -EPROBE_DEFER;
3243 platform_set_drvdata(pdev, fw);
3245 err = vchiq_platform_init(pdev, &g_state);
3247 goto failed_platform_init;
3249 err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
3251 vchiq_log_error(vchiq_arm_log_level,
3252 "Unable to allocate device number");
3253 goto failed_platform_init;
3255 cdev_init(&vchiq_cdev, &vchiq_fops);
3256 vchiq_cdev.owner = THIS_MODULE;
3257 err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
3259 vchiq_log_error(vchiq_arm_log_level,
3260 "Unable to register device");
3261 goto failed_cdev_add;
3264 /* create sysfs entries */
3265 vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
3266 err = PTR_ERR(vchiq_class);
3267 if (IS_ERR(vchiq_class))
3268 goto failed_class_create;
3270 vchiq_dev = device_create(vchiq_class, NULL,
3271 vchiq_devid, NULL, "vchiq");
3272 err = PTR_ERR(vchiq_dev);
3273 if (IS_ERR(vchiq_dev))
3274 goto failed_device_create;
3276 /* create debugfs entries */
3277 err = vchiq_debugfs_init();
3279 goto failed_debugfs_init;
3281 vchiq_log_info(vchiq_arm_log_level,
3282 "vchiq: initialised - version %d (min %d), device %d.%d",
3283 VCHIQ_VERSION, VCHIQ_VERSION_MIN,
3284 MAJOR(vchiq_devid), MINOR(vchiq_devid));
3288 failed_debugfs_init:
3289 device_destroy(vchiq_class, vchiq_devid);
3290 failed_device_create:
3291 class_destroy(vchiq_class);
3292 failed_class_create:
3293 cdev_del(&vchiq_cdev);
3295 unregister_chrdev_region(vchiq_devid, 1);
3296 failed_platform_init:
3297 vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
3301 static int vchiq_remove(struct platform_device *pdev)
3303 vchiq_debugfs_deinit();
3304 device_destroy(vchiq_class, vchiq_devid);
3305 class_destroy(vchiq_class);
3306 cdev_del(&vchiq_cdev);
3307 unregister_chrdev_region(vchiq_devid, 1);
3312 static const struct of_device_id vchiq_of_match[] = {
3313 { .compatible = "brcm,bcm2835-vchiq", },
3316 MODULE_DEVICE_TABLE(of, vchiq_of_match);
3318 static struct platform_driver vchiq_driver = {
3320 .name = "bcm2835_vchiq",
3321 .of_match_table = vchiq_of_match,
3323 .probe = vchiq_probe,
3324 .remove = vchiq_remove,
3326 module_platform_driver(vchiq_driver);
3328 MODULE_LICENSE("Dual BSD/GPL");
3329 MODULE_DESCRIPTION("Videocore VCHIQ driver");
3330 MODULE_AUTHOR("Broadcom Corporation");