Skip to content

Commit 17adb46

Browse files
furquan-googgregkh
authored andcommitted
firmware: gsmi: Drop the use of dma_pool_* API functions
GSMI driver uses dma_pool_* API functions for buffer allocation because it requires that the SMI buffers are allocated within 32-bit physical address space. However, this does not work well with IOMMU since there is no real device and hence no domain associated with the device. Since this is not a real device, it does not require any device address(IOVA) for the buffer allocations. The only requirement is to ensure that the physical address allocated to the buffer is within 32-bit physical address space. This is because the buffers have nothing to do with DMA at all. It is required for communication with firmware executing in SMI mode which has access only to the bottom 4GiB of memory. Hence, this change switches to using a SLAB cache created with SLAB_CACHE_DMA32 that guarantees that the allocation happens from the DMA32 memory zone. All calls to dma_pool_* are replaced with kmem_cache_*. In addition to that, all the code for managing the dma_pool for GSMI platform device is dropped. Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20201022071550.1192947-1-furquan@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 88f6c77 commit 17adb46

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

drivers/firmware/google/gsmi.c

+19-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <linux/string.h>
1818
#include <linux/spinlock.h>
1919
#include <linux/dma-mapping.h>
20-
#include <linux/dmapool.h>
2120
#include <linux/fs.h>
2221
#include <linux/slab.h>
2322
#include <linux/ioctl.h>
@@ -85,7 +84,6 @@
8584
struct gsmi_buf {
8685
u8 *start; /* start of buffer */
8786
size_t length; /* length of buffer */
88-
dma_addr_t handle; /* dma allocation handle */
8987
u32 address; /* physical address of buffer */
9088
};
9189

@@ -97,7 +95,7 @@ static struct gsmi_device {
9795
spinlock_t lock; /* serialize access to SMIs */
9896
u16 smi_cmd; /* SMI command port */
9997
int handshake_type; /* firmware handler interlock type */
100-
struct dma_pool *dma_pool; /* DMA buffer pool */
98+
struct kmem_cache *mem_pool; /* kmem cache for gsmi_buf allocations */
10199
} gsmi_dev;
102100

103101
/* Packed structures for communicating with the firmware */
@@ -157,8 +155,7 @@ static struct gsmi_buf *gsmi_buf_alloc(void)
157155
}
158156

159157
/* allocate buffer in 32bit address space */
160-
smibuf->start = dma_pool_alloc(gsmi_dev.dma_pool, GFP_KERNEL,
161-
&smibuf->handle);
158+
smibuf->start = kmem_cache_alloc(gsmi_dev.mem_pool, GFP_KERNEL);
162159
if (!smibuf->start) {
163160
printk(KERN_ERR "gsmi: failed to allocate name buffer\n");
164161
kfree(smibuf);
@@ -176,8 +173,7 @@ static void gsmi_buf_free(struct gsmi_buf *smibuf)
176173
{
177174
if (smibuf) {
178175
if (smibuf->start)
179-
dma_pool_free(gsmi_dev.dma_pool, smibuf->start,
180-
smibuf->handle);
176+
kmem_cache_free(gsmi_dev.mem_pool, smibuf->start);
181177
kfree(smibuf);
182178
}
183179
}
@@ -914,9 +910,20 @@ static __init int gsmi_init(void)
914910
spin_lock_init(&gsmi_dev.lock);
915911

916912
ret = -ENOMEM;
917-
gsmi_dev.dma_pool = dma_pool_create("gsmi", &gsmi_dev.pdev->dev,
918-
GSMI_BUF_SIZE, GSMI_BUF_ALIGN, 0);
919-
if (!gsmi_dev.dma_pool)
913+
914+
/*
915+
* SLAB cache is created using SLAB_CACHE_DMA32 to ensure that the
916+
* allocations for gsmi_buf come from the DMA32 memory zone. These
917+
* buffers have nothing to do with DMA. They are required for
918+
* communication with firmware executing in SMI mode which can only
919+
* access the bottom 4GiB of physical memory. Since DMA32 memory zone
920+
* guarantees allocation under the 4GiB boundary, this driver creates
921+
* a SLAB cache with SLAB_CACHE_DMA32 flag.
922+
*/
923+
gsmi_dev.mem_pool = kmem_cache_create("gsmi", GSMI_BUF_SIZE,
924+
GSMI_BUF_ALIGN,
925+
SLAB_CACHE_DMA32, NULL);
926+
if (!gsmi_dev.mem_pool)
920927
goto out_err;
921928

922929
/*
@@ -1032,7 +1039,7 @@ static __init int gsmi_init(void)
10321039
gsmi_buf_free(gsmi_dev.param_buf);
10331040
gsmi_buf_free(gsmi_dev.data_buf);
10341041
gsmi_buf_free(gsmi_dev.name_buf);
1035-
dma_pool_destroy(gsmi_dev.dma_pool);
1042+
kmem_cache_destroy(gsmi_dev.mem_pool);
10361043
platform_device_unregister(gsmi_dev.pdev);
10371044
pr_info("gsmi: failed to load: %d\n", ret);
10381045
#ifdef CONFIG_PM
@@ -1057,7 +1064,7 @@ static void __exit gsmi_exit(void)
10571064
gsmi_buf_free(gsmi_dev.param_buf);
10581065
gsmi_buf_free(gsmi_dev.data_buf);
10591066
gsmi_buf_free(gsmi_dev.name_buf);
1060-
dma_pool_destroy(gsmi_dev.dma_pool);
1067+
kmem_cache_destroy(gsmi_dev.mem_pool);
10611068
platform_device_unregister(gsmi_dev.pdev);
10621069
#ifdef CONFIG_PM
10631070
platform_driver_unregister(&gsmi_driver_info);

0 commit comments

Comments
 (0)