Re: pci_pool_free from IRQ

Pete Zaitcev (zaitcev@redhat.com)
Thu, 10 May 2001 16:05:50 -0400


How about this (with documentation fixes by David-B):

diff -ur -X dontdiff linux-2.4.4/Documentation/DMA-mapping.txt linux-2.4.4-niph/Documentation/DMA-mapping.txt
--- linux-2.4.4/Documentation/DMA-mapping.txt Thu Apr 19 08:38:48 2001
+++ linux-2.4.4-niph/Documentation/DMA-mapping.txt Thu May 10 12:29:22 2001
@@ -240,6 +240,7 @@

where dev, size are the same as in the above call and cpu_addr and
dma_handle are the values pci_alloc_consistent returned to you.
+This function may not be called in interrupt context.

If your driver needs lots of smaller memory regions, you can write
custom code to subdivide pages returned by pci_alloc_consistent,
@@ -262,7 +263,8 @@
sleeping context (f.e. in_interrupt is true or while holding SMP
locks), pass SLAB_ATOMIC. If your device has no boundary crossing
restrictions, pass 0 for alloc; passing 4096 says memory allocated
-from this pool must not cross 4KByte boundaries.
+from this pool must not cross 4KByte boundaries (but at that time it
+may be better to go for pci_alloc_consistent directly instead).

Allocate memory from a pci pool like this:

@@ -270,21 +272,23 @@

flags are SLAB_KERNEL if blocking is permitted (not in_interrupt nor
holding SMP locks), SLAB_ATOMIC otherwise. Like pci_alloc_consistent,
-this returns two values, cpu_addr and dma_handle,
+this returns two values, cpu_addr and dma_handle.

Free memory that was allocated from a pci_pool like this:

pci_pool_free(pool, cpu_addr, dma_handle);

where pool is what you passed to pci_pool_alloc, and cpu_addr and
-dma_handle are the values pci_pool_alloc returned.
+dma_handle are the values pci_pool_alloc returned. This function
+may be called in interrupt context.

Destroy a pci_pool by calling:

pci_pool_destroy(pool);

Make sure you've called pci_pool_free for all memory allocated
-from a pool before you destroy the pool.
+from a pool before you destroy the pool. This function may not
+be called in interrupt context.

DMA Direction

diff -ur -X dontdiff linux-2.4.4/Documentation/pci.txt linux-2.4.4-niph/Documentation/pci.txt
--- linux-2.4.4/Documentation/pci.txt Sun Sep 17 09:45:06 2000
+++ linux-2.4.4-niph/Documentation/pci.txt Thu May 10 12:33:03 2001
@@ -60,8 +60,8 @@
remove Pointer to a function which gets called whenever a device
being handled by this driver is removed (either during
deregistration of the driver or when it's manually pulled
- out of a hot-pluggable slot). This function can be called
- from interrupt context.
+ out of a hot-pluggable slot). This function always gets
+ called from process context, so it can sleep.
suspend, Power management hooks -- called when the device goes to
resume sleep or is resumed.

--- linux-2.4.4/drivers/pci/pci.c Thu Apr 19 08:38:48 2001
+++ linux-2.4.4-niph/drivers/pci/pci.c Thu May 10 12:36:28 2001
@@ -1701,8 +1701,11 @@
set_bit (block, &page->bitmap [map]);
if (waitqueue_active (&pool->waitq))
wake_up (&pool->waitq);
- else if (!is_page_busy (pool->blocks_per_page, page->bitmap))
- pool_free_page (pool, page);
+ /*
+ * Resist a temptation to do
+ * if (!is_page_busy(bpp, page->bitmap)) pool_free_page(pool, page);
+ * it is not interrupt safe. Better have empty pages hang around.
+ */
spin_unlock_irqrestore (&pool->lock, flags);
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/