-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liaocj
committed
Nov 22, 2024
1 parent
a462cc9
commit 8570f04
Showing
3 changed files
with
107 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,106 @@ | ||
# hwirq 和 irq 的映射 | ||
# hwirq 和 irq 的映射 | ||
```c | ||
int irq_domain_alloc_descs(int virq, unsigned int cnt, irq_hw_number_t hwirq, | ||
int node, const struct irq_affinity_desc *affinity) | ||
{ | ||
unsigned int hint; | ||
|
||
if (virq >= 0) { | ||
virq = __irq_alloc_descs(virq, virq, cnt, node, THIS_MODULE, | ||
affinity); | ||
} else { | ||
hint = hwirq % nr_irqs; | ||
if (hint == 0) | ||
hint++; | ||
virq = __irq_alloc_descs(-1, hint, cnt, node, THIS_MODULE, | ||
affinity); | ||
if (virq <= 0 && hint > 1) { | ||
virq = __irq_alloc_descs(-1, 1, cnt, node, THIS_MODULE, | ||
affinity); | ||
} | ||
} | ||
|
||
return virq; | ||
} | ||
|
||
/** | ||
* __irq_domain_alloc_irqs - Allocate IRQs from domain | ||
* @domain: domain to allocate from | ||
* @irq_base: allocate specified IRQ number if irq_base >= 0 | ||
* @nr_irqs: number of IRQs to allocate | ||
* @node: NUMA node id for memory allocation | ||
* @arg: domain specific argument | ||
* @realloc: IRQ descriptors have already been allocated if true | ||
* @affinity: Optional irq affinity mask for multiqueue devices | ||
* | ||
* Allocate IRQ numbers and initialized all data structures to support | ||
* hierarchy IRQ domains. | ||
* Parameter @realloc is mainly to support legacy IRQs. | ||
* Returns error code or allocated IRQ number | ||
* | ||
* The whole process to setup an IRQ has been split into two steps. | ||
* The first step, __irq_domain_alloc_irqs(), is to allocate IRQ | ||
* descriptor and required hardware resources. The second step, | ||
* irq_domain_activate_irq(), is to program the hardware with preallocated | ||
* resources. In this way, it's easier to rollback when failing to | ||
* allocate resources. | ||
*/ | ||
int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, | ||
unsigned int nr_irqs, int node, void *arg, | ||
bool realloc, const struct irq_affinity_desc *affinity) | ||
{ | ||
int i, ret, virq; | ||
|
||
if (domain == NULL) { | ||
domain = irq_default_domain; | ||
if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n")) | ||
return -EINVAL; | ||
} | ||
|
||
if (realloc && irq_base >= 0) { | ||
virq = irq_base; | ||
} else { | ||
virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node, | ||
affinity); | ||
if (virq < 0) { | ||
pr_debug("cannot allocate IRQ(base %d, count %d)\n", | ||
irq_base, nr_irqs); | ||
return virq; | ||
} | ||
} | ||
|
||
if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) { | ||
pr_debug("cannot allocate memory for IRQ%d\n", virq); | ||
ret = -ENOMEM; | ||
goto out_free_desc; | ||
} | ||
|
||
mutex_lock(&irq_domain_mutex); | ||
ret = irq_domain_alloc_irqs_hierarchy(domain, virq, nr_irqs, arg); | ||
if (ret < 0) { | ||
mutex_unlock(&irq_domain_mutex); | ||
goto out_free_irq_data; | ||
} | ||
|
||
for (i = 0; i < nr_irqs; i++) { | ||
ret = irq_domain_trim_hierarchy(virq + i); | ||
if (ret) { | ||
mutex_unlock(&irq_domain_mutex); | ||
goto out_free_irq_data; | ||
} | ||
} | ||
|
||
for (i = 0; i < nr_irqs; i++) | ||
irq_domain_insert_irq(virq + i); | ||
mutex_unlock(&irq_domain_mutex); | ||
|
||
return virq; | ||
|
||
out_free_irq_data: | ||
irq_domain_free_irq_data(virq, nr_irqs); | ||
out_free_desc: | ||
irq_free_descs(virq, nr_irqs); | ||
return ret; | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters