^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * IRQ offload/bypass manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2015 Red Hat, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2015 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Various virtualization hardware acceleration techniques allow bypassing or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * offloading interrupts received from devices around the host kernel. Posted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Interrupts on Intel VT-d systems can allow interrupts to be received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * directly by a virtual machine. ARM IRQ Forwarding allows forwarded physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * interrupts to be directly deactivated by the guest. This manager allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * interrupt producers and consumers to find each other to enable this sort of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * bypass.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/irqbypass.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) MODULE_DESCRIPTION("IRQ bypass manager utility module");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static LIST_HEAD(producers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static LIST_HEAD(consumers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static DEFINE_MUTEX(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* @lock must be held when calling connect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int __connect(struct irq_bypass_producer *prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct irq_bypass_consumer *cons)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (prod->stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) prod->stop(prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (cons->stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) cons->stop(cons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (prod->add_consumer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ret = prod->add_consumer(prod, cons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ret = cons->add_producer(cons, prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (ret && prod->del_consumer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) prod->del_consumer(prod, cons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (cons->start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) cons->start(cons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (prod->start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) prod->start(prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* @lock must be held when calling disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static void __disconnect(struct irq_bypass_producer *prod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct irq_bypass_consumer *cons)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (prod->stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) prod->stop(prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (cons->stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) cons->stop(cons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) cons->del_producer(cons, prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (prod->del_consumer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) prod->del_consumer(prod, cons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (cons->start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) cons->start(cons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (prod->start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) prod->start(prod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * irq_bypass_register_producer - register IRQ bypass producer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @producer: pointer to producer structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * Add the provided IRQ producer to the list of producers and connect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * with any matching token found on the IRQ consumers list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int irq_bypass_register_producer(struct irq_bypass_producer *producer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct irq_bypass_producer *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct irq_bypass_consumer *consumer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!producer->token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) might_sleep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) mutex_lock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) list_for_each_entry(tmp, &producers, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (tmp->token == producer->token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) list_for_each_entry(consumer, &consumers, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (consumer->token == producer->token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) ret = __connect(producer, consumer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) list_add(&producer->node, &producers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) mutex_unlock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) mutex_unlock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) EXPORT_SYMBOL_GPL(irq_bypass_register_producer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * irq_bypass_unregister_producer - unregister IRQ bypass producer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * @producer: pointer to producer structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * Remove a previously registered IRQ producer from the list of producers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * and disconnect it from any connected IRQ consumer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) void irq_bypass_unregister_producer(struct irq_bypass_producer *producer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct irq_bypass_producer *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct irq_bypass_consumer *consumer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (!producer->token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) might_sleep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return; /* nothing in the list anyway */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) mutex_lock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) list_for_each_entry(tmp, &producers, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (tmp->token != producer->token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) list_for_each_entry(consumer, &consumers, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (consumer->token == producer->token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) __disconnect(producer, consumer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) list_del(&producer->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) mutex_unlock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) EXPORT_SYMBOL_GPL(irq_bypass_unregister_producer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * irq_bypass_register_consumer - register IRQ bypass consumer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * @consumer: pointer to consumer structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * Add the provided IRQ consumer to the list of consumers and connect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * with any matching token found on the IRQ producer list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct irq_bypass_consumer *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct irq_bypass_producer *producer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (!consumer->token ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) !consumer->add_producer || !consumer->del_producer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) might_sleep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) mutex_lock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) list_for_each_entry(tmp, &consumers, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (tmp->token == consumer->token || tmp == consumer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) list_for_each_entry(producer, &producers, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (producer->token == consumer->token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ret = __connect(producer, consumer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) list_add(&consumer->node, &consumers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) mutex_unlock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) mutex_unlock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) EXPORT_SYMBOL_GPL(irq_bypass_register_consumer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * irq_bypass_unregister_consumer - unregister IRQ bypass consumer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * @consumer: pointer to consumer structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * Remove a previously registered IRQ consumer from the list of consumers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * and disconnect it from any connected IRQ producer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) void irq_bypass_unregister_consumer(struct irq_bypass_consumer *consumer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct irq_bypass_consumer *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct irq_bypass_producer *producer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (!consumer->token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) might_sleep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return; /* nothing in the list anyway */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) mutex_lock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) list_for_each_entry(tmp, &consumers, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (tmp != consumer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) list_for_each_entry(producer, &producers, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (producer->token == consumer->token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) __disconnect(producer, consumer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) list_del(&consumer->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) mutex_unlock(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) EXPORT_SYMBOL_GPL(irq_bypass_unregister_consumer);