diff options
author | linyuny <linyuny@google.com> | 2022-12-15 04:22:35 +0000 |
---|---|---|
committer | Holmes Chou <holmeschou@google.com> | 2023-02-13 00:54:03 +0000 |
commit | 0d199c865f426ea408346b160c1798df731afc3d (patch) | |
tree | be691c29dd5d58ec2c8b2f08cdc86751bc8be61b | |
parent | 3e4841ac3fb822ebdb98d0e95451bf4b43758002 (diff) | |
download | lwis-android-gs-raviole-5.10-u-preview-2.tar.gz |
LWIS: Using kernel functions to determine current contextandroid-u-preview-2_r0.2android-gs-raviole-5.10-u-preview-2
Using kernel functions to determine current context
Bug: 176192392
Test: Pixel camera test checklist
Change-Id: I673cef1fc161bd864fbc845d940425dbf5579f4b
Signed-off-by: linyuny <linyuny@google.com>
-rw-r--r-- | lwis_allocator.c | 1 | ||||
-rw-r--r-- | lwis_device.c | 3 | ||||
-rw-r--r-- | lwis_device.h | 2 | ||||
-rw-r--r-- | lwis_device_i2c.c | 1 | ||||
-rw-r--r-- | lwis_device_top.c | 9 | ||||
-rw-r--r-- | lwis_event.c | 24 | ||||
-rw-r--r-- | lwis_event.h | 7 | ||||
-rw-r--r-- | lwis_interrupt.c | 7 | ||||
-rw-r--r-- | lwis_io_entry.c | 7 | ||||
-rw-r--r-- | lwis_io_entry.h | 3 | ||||
-rw-r--r-- | lwis_ioctl.c | 2 | ||||
-rw-r--r-- | lwis_periodic_io.c | 6 | ||||
-rw-r--r-- | lwis_transaction.c | 40 | ||||
-rw-r--r-- | lwis_transaction.h | 3 |
14 files changed, 49 insertions, 66 deletions
diff --git a/lwis_allocator.c b/lwis_allocator.c index e56527e..66e738a 100644 --- a/lwis_allocator.c +++ b/lwis_allocator.c @@ -13,7 +13,6 @@ #include <linux/mm.h> #include <linux/mutex.h> -#include <linux/preempt.h> #include <linux/slab.h> #include "lwis_allocator.h" #include "lwis_commands.h" diff --git a/lwis_device.c b/lwis_device.c index fc8fa3e..203d2ff 100644 --- a/lwis_device.c +++ b/lwis_device.c @@ -1105,8 +1105,7 @@ static void event_heartbeat_timer(struct timer_list *t) int64_t event_id = LWIS_EVENT_ID_HEARTBEAT | (int64_t)lwis_dev->id << LWIS_EVENT_ID_EVENT_CODE_LEN; - lwis_device_event_emit(lwis_dev, event_id, NULL, 0, - /*in_irq=*/false); + lwis_device_event_emit(lwis_dev, event_id, NULL, 0); mod_timer(t, jiffies + msecs_to_jiffies(LWIS_HEARTBEAT_EVENT_INTERVAL_MS)); } diff --git a/lwis_device.h b/lwis_device.h index 2e19917..59e7b25 100644 --- a/lwis_device.h +++ b/lwis_device.h @@ -120,7 +120,7 @@ struct lwis_event_subscribe_operations { /* Notify subscriber when an event is happening */ void (*notify_event_subscriber)(struct lwis_device *lwis_dev, int64_t trigger_event_id, int64_t trigger_event_count, - int64_t trigger_event_timestamp, bool in_irq); + int64_t trigger_event_timestamp); /* Clean up event subscription hash table when unloading top device */ void (*release)(struct lwis_device *lwis_dev); }; diff --git a/lwis_device_i2c.c b/lwis_device_i2c.c index 7cdd890..0cc3d30 100644 --- a/lwis_device_i2c.c +++ b/lwis_device_i2c.c @@ -20,7 +20,6 @@ #include <linux/module.h> #include <linux/platform_device.h> #include <linux/pm.h> -#include <linux/preempt.h> #include <linux/sched.h> #include <linux/sched/types.h> #include <linux/slab.h> diff --git a/lwis_device_top.c b/lwis_device_top.c index b56f0f5..63fe211 100644 --- a/lwis_device_top.c +++ b/lwis_device_top.c @@ -48,8 +48,7 @@ static int lwis_top_event_subscribe(struct lwis_device *lwis_dev, int64_t trigge static int lwis_top_event_unsubscribe(struct lwis_device *lwis_dev, int64_t trigger_event_id, int subscriber_device_id); static void lwis_top_event_notify(struct lwis_device *lwis_dev, int64_t trigger_event_id, - int64_t trigger_event_count, int64_t trigger_event_timestamp, - bool in_irq); + int64_t trigger_event_count, int64_t trigger_event_timestamp); static void lwis_top_event_subscribe_release(struct lwis_device *lwis_dev); static struct lwis_event_subscribe_operations top_subscribe_ops = { .subscribe_event = lwis_top_event_subscribe, @@ -160,8 +159,7 @@ static void subscribe_work_func(struct kthread_work *work) lwis_device_external_event_emit(subscribe_info->subscriber_dev, trigger_event->trigger_event_id, trigger_event->trigger_event_count, - trigger_event->trigger_event_timestamp, - false); + trigger_event->trigger_event_timestamp); } kfree(trigger_event); } @@ -169,8 +167,7 @@ static void subscribe_work_func(struct kthread_work *work) } static void lwis_top_event_notify(struct lwis_device *lwis_dev, int64_t trigger_event_id, - int64_t trigger_event_count, int64_t trigger_event_timestamp, - bool in_irq) + int64_t trigger_event_count, int64_t trigger_event_timestamp) { struct lwis_top_device *lwis_top_dev = container_of(lwis_dev, struct lwis_top_device, base_dev); diff --git a/lwis_event.c b/lwis_event.c index 128280a..dd34e44 100644 --- a/lwis_event.c +++ b/lwis_event.c @@ -800,7 +800,7 @@ int lwis_device_event_enable(struct lwis_device *lwis_dev, int64_t event_id, boo static int lwis_device_event_emit_impl(struct lwis_device *lwis_dev, int64_t event_id, void *payload, size_t payload_size, - struct list_head *pending_events, bool in_irq) + struct list_head *pending_events) { struct lwis_client_event_state *client_event_state; struct lwis_device_event_state *device_event_state; @@ -842,7 +842,7 @@ static int lwis_device_event_emit_impl(struct lwis_device *lwis_dev, int64_t eve /* Emit event to subscriber via top device */ if (has_subscriber) { lwis_dev->top_dev->subscribe_ops.notify_event_subscriber( - lwis_dev->top_dev, event_id, event_counter, timestamp, in_irq); + lwis_dev->top_dev, event_id, event_counter, timestamp); } /* Run internal handler if any */ @@ -903,7 +903,7 @@ static int lwis_device_event_emit_impl(struct lwis_device *lwis_dev, int64_t eve /* Trigger transactions, if there's any that matches this event ID and counter */ if (lwis_transaction_event_trigger(lwis_client, event_id, event_counter, - pending_events, in_irq)) { + pending_events)) { dev_warn(lwis_dev->dev, "Failed to process transactions: Event ID: 0x%llx Counter: %lld\n", event_id, event_counter); @@ -914,7 +914,7 @@ static int lwis_device_event_emit_impl(struct lwis_device *lwis_dev, int64_t eve } int lwis_device_event_emit(struct lwis_device *lwis_dev, int64_t event_id, void *payload, - size_t payload_size, bool in_irq) + size_t payload_size) { int ret; struct list_head pending_events; @@ -925,7 +925,7 @@ int lwis_device_event_emit(struct lwis_device *lwis_dev, int64_t event_id, void /* Emit the original event */ ret = lwis_device_event_emit_impl(lwis_dev, event_id, payload, payload_size, - &pending_events, in_irq); + &pending_events); if (ret) { lwis_dev_err_ratelimited(lwis_dev->dev, "lwis_device_event_emit_impl failed: event ID 0x%llx\n", @@ -934,7 +934,7 @@ int lwis_device_event_emit(struct lwis_device *lwis_dev, int64_t event_id, void } /* Emit pending events */ - return lwis_pending_events_emit(lwis_dev, &pending_events, in_irq); + return lwis_pending_events_emit(lwis_dev, &pending_events); } int lwis_pending_event_push(struct list_head *pending_events, int64_t event_id, void *payload, @@ -962,8 +962,7 @@ int lwis_pending_event_push(struct list_head *pending_events, int64_t event_id, return 0; } -int lwis_pending_events_emit(struct lwis_device *lwis_dev, struct list_head *pending_events, - bool in_irq) +int lwis_pending_events_emit(struct lwis_device *lwis_dev, struct list_head *pending_events) { int return_val = 0, emit_result = 0; struct lwis_event_entry *event; @@ -973,7 +972,7 @@ int lwis_pending_events_emit(struct lwis_device *lwis_dev, struct list_head *pen emit_result = lwis_device_event_emit_impl(lwis_dev, event->event_info.event_id, event->event_info.payload_buffer, event->event_info.payload_size, - pending_events, in_irq); + pending_events); if (emit_result) { return_val = emit_result; dev_warn_ratelimited(lwis_dev->dev, @@ -1011,7 +1010,7 @@ out: } void lwis_device_external_event_emit(struct lwis_device *lwis_dev, int64_t event_id, - int64_t event_counter, int64_t timestamp, bool in_irq) + int64_t event_counter, int64_t timestamp) { struct lwis_client_event_state *client_event_state; struct lwis_device_event_state *device_event_state; @@ -1080,14 +1079,13 @@ void lwis_device_external_event_emit(struct lwis_device *lwis_dev, int64_t event } if (lwis_transaction_event_trigger(lwis_client, event_id, event_counter, - &pending_events, in_irq)) + &pending_events)) dev_warn( lwis_dev->dev, "Failed to process transactions: external event ID: 0x%llx counter: %lld\n", event_id, event_counter); } - - lwis_pending_events_emit(lwis_dev, &pending_events, in_irq); + lwis_pending_events_emit(lwis_dev, &pending_events); } void lwis_device_error_event_emit(struct lwis_device *lwis_dev, int64_t event_id, void *payload, diff --git a/lwis_event.h b/lwis_event.h index c8e2642..86f8fa5 100644 --- a/lwis_event.h +++ b/lwis_event.h @@ -232,7 +232,7 @@ int lwis_device_event_enable(struct lwis_device *lwis_dev, int64_t event_id, boo * Returns: 0 on success */ int lwis_device_event_emit(struct lwis_device *lwis_dev, int64_t event_id, void *payload, - size_t payload_size, bool in_irq); + size_t payload_size); /* * lwis_device_external_event_emit: Emits an subscribed event to device. @@ -243,7 +243,7 @@ int lwis_device_event_emit(struct lwis_device *lwis_dev, int64_t event_id, void * 4. Not supported chain transaction */ void lwis_device_external_event_emit(struct lwis_device *lwis_dev, int64_t event_id, - int64_t event_counter, int64_t timestamp, bool in_irq); + int64_t event_counter, int64_t timestamp); /* * lwis_device_error_event_emit: Emits an error event for all clients. @@ -311,8 +311,7 @@ int lwis_pending_event_push(struct list_head *pending_events, int64_t event_id, * * Returns: 0 on success */ -int lwis_pending_events_emit(struct lwis_device *lwis_dev, struct list_head *pending_events, - bool in_irq); +int lwis_pending_events_emit(struct lwis_device *lwis_dev, struct list_head *pending_events); /* * lwis_device_event_update_subscriber: The function to notify an event has been subscribed/unsubscribed. diff --git a/lwis_interrupt.c b/lwis_interrupt.c index f5ae034..da6fec7 100644 --- a/lwis_interrupt.c +++ b/lwis_interrupt.c @@ -300,8 +300,8 @@ static irqreturn_t lwis_interrupt_event_isr(int irq_number, void *data) /* Check if this event needs to be emitted */ if ((source_value >> event->int_reg_bit) & 0x1) { /* Emit the event */ - lwis_device_event_emit(irq->lwis_dev, event->event_id, NULL, 0, - /*in_irq=*/true); + lwis_device_event_emit(irq->lwis_dev, event->event_id, + NULL, 0); /* Clear this interrupt */ reset_value |= (1ULL << event->int_reg_bit); @@ -374,7 +374,8 @@ static irqreturn_t lwis_interrupt_gpios_event_isr(int irq_number, void *data) list_for_each (p, &irq->enabled_event_infos) { event = list_entry(p, struct lwis_single_event_info, node_enabled); /* Emit the event */ - lwis_device_event_emit(irq->lwis_dev, event->event_id, NULL, 0, /*in_irq=*/true); + lwis_device_event_emit(irq->lwis_dev, event->event_id, + NULL, 0); } spin_unlock_irqrestore(&irq->lock, flags); diff --git a/lwis_io_entry.c b/lwis_io_entry.c index ab7d5bb..df50f96 100644 --- a/lwis_io_entry.c +++ b/lwis_io_entry.c @@ -11,18 +11,19 @@ #define pr_fmt(fmt) KBUILD_MODNAME "-ioentry: " fmt #include <linux/delay.h> +#include <linux/preempt.h> #include "lwis_io_entry.h" #include "lwis_util.h" -int lwis_io_entry_poll(struct lwis_device *lwis_dev, struct lwis_io_entry *entry, bool non_blocking) +int lwis_io_entry_poll(struct lwis_device *lwis_dev, struct lwis_io_entry *entry) { uint64_t val, start; uint64_t timeout_ms = entry->read_assert.timeout_ms; int ret = 0; - /* Only read and check once if non_blocking */ - if (non_blocking) { + /* Only read and check once if in_irq() */ + if (in_irq()) { timeout_ms = 0; } diff --git a/lwis_io_entry.h b/lwis_io_entry.h index a2679da..ae1b2cc 100644 --- a/lwis_io_entry.h +++ b/lwis_io_entry.h @@ -18,8 +18,7 @@ * lwis_io_entry_poll: * Polls a register for a specified time or until it reaches the expected value. */ -int lwis_io_entry_poll(struct lwis_device *lwis_dev, struct lwis_io_entry *entry, - bool non_blocking); +int lwis_io_entry_poll(struct lwis_device *lwis_dev, struct lwis_io_entry *entry); /* * lwis_io_entry_read_assert: diff --git a/lwis_ioctl.c b/lwis_ioctl.c index f58a4f3..f70bb97 100644 --- a/lwis_ioctl.c +++ b/lwis_ioctl.c @@ -406,7 +406,7 @@ int lwis_ioctl_util_synchronous_process_io_entries(struct lwis_device *lwis_dev, ret = register_write(lwis_dev, &io_entries[i]); break; case LWIS_IO_ENTRY_POLL: - ret = lwis_io_entry_poll(lwis_dev, &io_entries[i], /*non_blocking=*/false); + ret = lwis_io_entry_poll(lwis_dev, &io_entries[i]); break; case LWIS_IO_ENTRY_READ_ASSERT: ret = lwis_io_entry_read_assert(lwis_dev, &io_entries[i]); diff --git a/lwis_periodic_io.c b/lwis_periodic_io.c index 5751745..8de0049 100644 --- a/lwis_periodic_io.c +++ b/lwis_periodic_io.c @@ -234,7 +234,7 @@ static int process_io_entries(struct lwis_client *client, read_buf += sizeof(struct lwis_periodic_io_result) + io_result->io_result.num_value_bytes; } else if (entry->type == LWIS_IO_ENTRY_POLL) { - ret = lwis_io_entry_poll(lwis_dev, entry, /*non_blocking=*/false); + ret = lwis_io_entry_poll(lwis_dev, entry); if (ret) { resp->error_code = ret; goto event_push; @@ -329,9 +329,7 @@ static void periodic_io_work_func(struct kthread_work *work) kfree(periodic_io_proxy); } spin_unlock_irqrestore(&client->periodic_io_lock, flags); - - lwis_pending_events_emit(client->lwis_dev, &pending_events, - /*in_irq=*/false); + lwis_pending_events_emit(client->lwis_dev, &pending_events); } static int prepare_emit_events(struct lwis_client *client, struct lwis_periodic_io *periodic_io) diff --git a/lwis_transaction.c b/lwis_transaction.c index 05aa3b6..b644c77 100644 --- a/lwis_transaction.c +++ b/lwis_transaction.c @@ -15,6 +15,7 @@ #include <linux/delay.h> #include <linux/kernel.h> #include <linux/mm.h> +#include <linux/preempt.h> #include <linux/slab.h> #include <linux/workqueue.h> @@ -152,7 +153,7 @@ void lwis_transaction_free(struct lwis_device *lwis_dev, struct lwis_transaction static int process_transaction(struct lwis_client *client, struct lwis_transaction *transaction, struct list_head *pending_events, struct list_head *pending_fences, - bool in_irq, bool skip_err) + bool skip_err) { int i; int ret = 0; @@ -240,7 +241,7 @@ static int process_transaction(struct lwis_client *client, struct lwis_transacti } read_buf += sizeof(struct lwis_io_result) + io_result->num_value_bytes; } else if (entry->type == LWIS_IO_ENTRY_POLL) { - ret = lwis_io_entry_poll(lwis_dev, entry, in_irq); + ret = lwis_io_entry_poll(lwis_dev, entry); if (ret) { resp->error_code = ret; if (skip_err) { @@ -371,15 +372,13 @@ static void transaction_work_func(struct kthread_work *work) &pending_fences); } else { spin_unlock_irqrestore(&client->transaction_lock, flags); - process_transaction(client, transaction, &pending_events, &pending_fences, - /*in_irq=*/false, - /*skip_err=*/false); + process_transaction(client, transaction, &pending_events, + &pending_fences, /*skip_err=*/false); spin_lock_irqsave(&client->transaction_lock, flags); } } spin_unlock_irqrestore(&client->transaction_lock, flags); - - lwis_pending_events_emit(client->lwis_dev, &pending_events, /*in_irq=*/false); + lwis_pending_events_emit(client->lwis_dev, &pending_events); lwis_fences_pending_signal_emit(client->lwis_dev, &pending_fences); } @@ -497,7 +496,6 @@ int lwis_transaction_client_cleanup(struct lwis_client *client) struct lwis_transaction *transaction; struct lwis_transaction_event_list *it_evt_list; struct list_head pending_events; - bool in_irq = false; struct lwis_event_entry *event; INIT_LIST_HEAD(&pending_events); @@ -525,8 +523,8 @@ int lwis_transaction_client_cleanup(struct lwis_client *client) cancel_transaction(client->lwis_dev, transaction, -ECANCELED, NULL, NULL); } else { spin_unlock_irqrestore(&client->transaction_lock, flags); - process_transaction(client, transaction, &pending_events, NULL, in_irq, - /*skip_err=*/true); + process_transaction(client, transaction, &pending_events, NULL, + /*skip_err=*/true); spin_lock_irqsave(&client->transaction_lock, flags); } } @@ -830,7 +828,7 @@ new_repeating_transaction_iteration(struct lwis_client *client, static void defer_transaction_locked(struct lwis_client *client, struct lwis_transaction *transaction, struct list_head *pending_events, - struct list_head *pending_fences, bool in_irq, + struct list_head *pending_fences, bool del_event_list_node) { unsigned long flags = 0; @@ -839,15 +837,15 @@ static void defer_transaction_locked(struct lwis_client *client, } /* I2C read/write cannot be executed in IRQ context */ - if (in_irq && client->lwis_dev->type == DEVICE_TYPE_I2C) { + if (in_irq() && client->lwis_dev->type == DEVICE_TYPE_I2C) { list_add_tail(&transaction->process_queue_node, &client->transaction_process_queue); return; } if (transaction->info.run_in_event_context) { spin_unlock_irqrestore(&client->transaction_lock, flags); - process_transaction(client, transaction, pending_events, pending_fences, in_irq, - /*skip_err=*/false); + process_transaction(client, transaction, pending_events, + pending_fences, /*skip_err=*/false); spin_lock_irqsave(&client->transaction_lock, flags); } else { list_add_tail(&transaction->process_queue_node, &client->transaction_process_queue); @@ -855,8 +853,7 @@ static void defer_transaction_locked(struct lwis_client *client, } int lwis_transaction_event_trigger(struct lwis_client *client, int64_t event_id, - int64_t event_counter, struct list_head *pending_events, - bool in_irq) + int64_t event_counter, struct list_head *pending_events) { unsigned long flags; struct lwis_transaction_event_list *event_list; @@ -905,8 +902,7 @@ int lwis_transaction_event_trigger(struct lwis_client *client, int64_t event_id, #endif hash_del(&transaction->pending_map_node); defer_transaction_locked(client, transaction, pending_events, - &pending_fences, in_irq, - /* del_event_list_node */ false); + &pending_fences, /* del_event_list_node */ false); } continue; } @@ -924,8 +920,7 @@ int lwis_transaction_event_trigger(struct lwis_client *client, int64_t event_id, if (trigger_counter == LWIS_EVENT_COUNTER_ON_NEXT_OCCURRENCE || trigger_counter == event_counter) { defer_transaction_locked(client, transaction, pending_events, - &pending_fences, in_irq, - /* del_event_list_node */ true); + &pending_fences, /* del_event_list_node */ true); } else if (trigger_counter == LWIS_EVENT_COUNTER_EVERY_TIME) { new_instance = new_repeating_transaction_iteration(client, transaction); if (!new_instance) { @@ -936,8 +931,7 @@ int lwis_transaction_event_trigger(struct lwis_client *client, int64_t event_id, continue; } defer_transaction_locked(client, new_instance, pending_events, - &pending_fences, in_irq, - /* del_event_list_node */ false); + &pending_fences, /* del_event_list_node */ false); } } @@ -1020,7 +1014,7 @@ void lwis_transaction_fence_trigger(struct lwis_client *client, struct lwis_fenc spin_unlock_irqrestore(&client->transaction_lock, flags); - lwis_pending_events_emit(client->lwis_dev, &pending_events, /*in_irq=*/false); + lwis_pending_events_emit(client->lwis_dev, &pending_events); lwis_fences_pending_signal_emit(client->lwis_dev, &pending_fences); } diff --git a/lwis_transaction.h b/lwis_transaction.h index cc17837..1b5cef8 100644 --- a/lwis_transaction.h +++ b/lwis_transaction.h @@ -73,8 +73,7 @@ int lwis_transaction_client_flush(struct lwis_client *client); int lwis_transaction_client_cleanup(struct lwis_client *client); int lwis_transaction_event_trigger(struct lwis_client *client, int64_t event_id, - int64_t event_counter, struct list_head *pending_events, - bool in_irq); + int64_t event_counter, struct list_head *pending_events); void lwis_transaction_fence_trigger(struct lwis_client *client, struct lwis_fence *fence, struct list_head *transaction_list); |