获得连续物理内存的方法有很多,在很多地方搜了但是自己拿过来用就是用不了,这里展示几个亲测能用的。包括dma_alloc_coherent和kmalloc等。
代码:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/dma-mapping.h>
#include <linux/dmapool.h>
#include <linux/device.h>
// int direction = PCI_DMA_TODEVICE ;
// int direction = PCI_DMA_FROMDEVICE ;
static int direction = PCI_DMA_BIDIRECTIONAL;
//int direction = PCI_DMA_NONE;
static char *kbuf;
static dma_addr_t handle;
static size_t size = (10 * PAGE_SIZE);
static struct dma_pool *mypool;
static size_t pool_size = 1024;
static size_t pool_align = 8;
static void my_release(struct device *dev)
{
pr_info("releasing DMA device\n");
}
static struct device dev = {
.release = my_release
};
static void output(char *kbuf, dma_addr_t handle, size_t size, char *string)
{
unsign