mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-18 09:44:18 +08:00
8d8bb39b9e
Add per-device dma_mapping_ops support for CONFIG_X86_64 as POWER architecture does: This enables us to cleanly fix the Calgary IOMMU issue that some devices are not behind the IOMMU (http://lkml.org/lkml/2008/5/8/423). I think that per-device dma_mapping_ops support would be also helpful for KVM people to support PCI passthrough but Andi thinks that this makes it difficult to support the PCI passthrough (see the above thread). So I CC'ed this to KVM camp. Comments are appreciated. A pointer to dma_mapping_ops to struct dev_archdata is added. If the pointer is non NULL, DMA operations in asm/dma-mapping.h use it. If it's NULL, the system-wide dma_ops pointer is used as before. If it's useful for KVM people, I plan to implement a mechanism to register a hook called when a new pci (or dma capable) device is created (it works with hot plugging). It enables IOMMUs to set up an appropriate dma_mapping_ops per device. The major obstacle is that dma_mapping_error doesn't take a pointer to the device unlike other DMA operations. So x86 can't have dma_mapping_ops per device. Note all the POWER IOMMUs use the same dma_mapping_error function so this is not a problem for POWER but x86 IOMMUs use different dma_mapping_error functions. The first patch adds the device argument to dma_mapping_error. The patch is trivial but large since it touches lots of drivers and dma-mapping.h in all the architecture. This patch: dma_mapping_error() doesn't take a pointer to the device unlike other DMA operations. So we can't have dma_mapping_ops per device. Note that POWER already has dma_mapping_ops per device but all the POWER IOMMUs use the same dma_mapping_error function. x86 IOMMUs use device argument. [akpm@linux-foundation.org: fix sge] [akpm@linux-foundation.org: fix svc_rdma] [akpm@linux-foundation.org: build fix] [akpm@linux-foundation.org: fix bnx2x] [akpm@linux-foundation.org: fix s2io] [akpm@linux-foundation.org: fix pasemi_mac] [akpm@linux-foundation.org: fix sdhci] [akpm@linux-foundation.org: build fix] [akpm@linux-foundation.org: fix sparc] [akpm@linux-foundation.org: fix ibmvscsi] Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Muli Ben-Yehuda <muli@il.ibm.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@elte.hu> Cc: Avi Kivity <avi@qumranet.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
159 lines
3.9 KiB
C
159 lines
3.9 KiB
C
/*
|
|
* Isochronous IO functionality
|
|
*
|
|
* Copyright (C) 2006 Kristian Hoegsberg <krh@bitplanet.net>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/mm.h>
|
|
|
|
#include "fw-transaction.h"
|
|
#include "fw-topology.h"
|
|
#include "fw-device.h"
|
|
|
|
int
|
|
fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
|
|
int page_count, enum dma_data_direction direction)
|
|
{
|
|
int i, j, retval = -ENOMEM;
|
|
dma_addr_t address;
|
|
|
|
buffer->page_count = page_count;
|
|
buffer->direction = direction;
|
|
|
|
buffer->pages = kmalloc(page_count * sizeof(buffer->pages[0]),
|
|
GFP_KERNEL);
|
|
if (buffer->pages == NULL)
|
|
goto out;
|
|
|
|
for (i = 0; i < buffer->page_count; i++) {
|
|
buffer->pages[i] = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
|
|
if (buffer->pages[i] == NULL)
|
|
goto out_pages;
|
|
|
|
address = dma_map_page(card->device, buffer->pages[i],
|
|
0, PAGE_SIZE, direction);
|
|
if (dma_mapping_error(card->device, address)) {
|
|
__free_page(buffer->pages[i]);
|
|
goto out_pages;
|
|
}
|
|
set_page_private(buffer->pages[i], address);
|
|
}
|
|
|
|
return 0;
|
|
|
|
out_pages:
|
|
for (j = 0; j < i; j++) {
|
|
address = page_private(buffer->pages[j]);
|
|
dma_unmap_page(card->device, address,
|
|
PAGE_SIZE, DMA_TO_DEVICE);
|
|
__free_page(buffer->pages[j]);
|
|
}
|
|
kfree(buffer->pages);
|
|
out:
|
|
buffer->pages = NULL;
|
|
return retval;
|
|
}
|
|
|
|
int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma)
|
|
{
|
|
unsigned long uaddr;
|
|
int i, retval;
|
|
|
|
uaddr = vma->vm_start;
|
|
for (i = 0; i < buffer->page_count; i++) {
|
|
retval = vm_insert_page(vma, uaddr, buffer->pages[i]);
|
|
if (retval)
|
|
return retval;
|
|
uaddr += PAGE_SIZE;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
|
|
struct fw_card *card)
|
|
{
|
|
int i;
|
|
dma_addr_t address;
|
|
|
|
for (i = 0; i < buffer->page_count; i++) {
|
|
address = page_private(buffer->pages[i]);
|
|
dma_unmap_page(card->device, address,
|
|
PAGE_SIZE, DMA_TO_DEVICE);
|
|
__free_page(buffer->pages[i]);
|
|
}
|
|
|
|
kfree(buffer->pages);
|
|
buffer->pages = NULL;
|
|
}
|
|
|
|
struct fw_iso_context *
|
|
fw_iso_context_create(struct fw_card *card, int type,
|
|
int channel, int speed, size_t header_size,
|
|
fw_iso_callback_t callback, void *callback_data)
|
|
{
|
|
struct fw_iso_context *ctx;
|
|
|
|
ctx = card->driver->allocate_iso_context(card, type, header_size);
|
|
if (IS_ERR(ctx))
|
|
return ctx;
|
|
|
|
ctx->card = card;
|
|
ctx->type = type;
|
|
ctx->channel = channel;
|
|
ctx->speed = speed;
|
|
ctx->header_size = header_size;
|
|
ctx->callback = callback;
|
|
ctx->callback_data = callback_data;
|
|
|
|
return ctx;
|
|
}
|
|
|
|
void fw_iso_context_destroy(struct fw_iso_context *ctx)
|
|
{
|
|
struct fw_card *card = ctx->card;
|
|
|
|
card->driver->free_iso_context(ctx);
|
|
}
|
|
|
|
int
|
|
fw_iso_context_start(struct fw_iso_context *ctx, int cycle, int sync, int tags)
|
|
{
|
|
return ctx->card->driver->start_iso(ctx, cycle, sync, tags);
|
|
}
|
|
|
|
int
|
|
fw_iso_context_queue(struct fw_iso_context *ctx,
|
|
struct fw_iso_packet *packet,
|
|
struct fw_iso_buffer *buffer,
|
|
unsigned long payload)
|
|
{
|
|
struct fw_card *card = ctx->card;
|
|
|
|
return card->driver->queue_iso(ctx, packet, buffer, payload);
|
|
}
|
|
|
|
int
|
|
fw_iso_context_stop(struct fw_iso_context *ctx)
|
|
{
|
|
return ctx->card->driver->stop_iso(ctx);
|
|
}
|