pci_dma.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 678 行 · 第 1/2 页
C
678 行
* * We map this to the one step pcibr_dmamap_trans interface rather than * the two step pcibr_dmamap_alloc/pcibr_dmamap_addr because we have * no way of saving the dmamap handle from the alloc to later free * (which is pretty much unacceptable). * * TODO: simplify our interface; * get rid of dev_desc and vhdl (seems redundant given a pci_dev); * figure out how to save dmamap handle so can use two step. */dma_addr_tsn_pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction){ vertex_hdl_t vhdl; dma_addr_t dma_addr; unsigned long phys_addr; struct sn_device_sysdata *device_sysdata; pcibr_dmamap_t dma_map = NULL; unsigned dma_flag; if (direction == PCI_DMA_NONE) BUG(); /* * find vertex for the device */ device_sysdata = SN_DEVICE_SYSDATA(hwdev); vhdl = device_sysdata->vhdl; phys_addr = __pa(ptr); /* * 64 bit DMA mask can use direct translations * PCI only * 32 bit DMA mask might be able to use direct, otherwise use dma map * PCI-X * only 64 bit DMA mask supported; both direct and dma map will fail */ if (hwdev->dma_mask == ~0UL) dma_flag = PCIIO_DMA_DATA | PCIIO_DMA_A64; else dma_flag = PCIIO_DMA_DATA; dma_addr = pcibr_dmatrans_addr(vhdl, NULL, phys_addr, size, dma_flag); if (dma_addr) return dma_addr; /* * It's a 32 bit card and we cannot do direct mapping so * let's use the PMU instead. */ dma_map = NULL; dma_map = pcibr_dmamap_alloc(vhdl, NULL, size, PCIIO_DMA_DATA | MINIMAL_ATE_FLAG(phys_addr, size)); /* PMU out of entries */ if (!dma_map) return 0; dma_addr = (dma_addr_t) pcibr_dmamap_addr(dma_map, phys_addr, size); dma_map->bd_dma_addr = dma_addr; return ((dma_addr_t)dma_addr);}/** * sn_pci_unmap_single - unmap a region used for DMA * @hwdev: device to unmap * @dma_addr: DMA address to unmap * @size: size of region * @direction: DMA direction * * Unmaps the region pointed to by @dma_addr. Also known as * platform_pci_unmap_single() by the IA64 machvec code. */voidsn_pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction){ struct pcibr_dmamap_s *dma_map = NULL; if (direction == PCI_DMA_NONE) BUG(); /* * Get the sn_dma_map entry. */ if (IS_PCI32_MAPPED(dma_addr)) dma_map = find_sn_dma_map(dma_addr, hwdev->bus->number); /* * and free it if necessary... */ if (dma_map) { pcibr_dmamap_done(dma_map); pcibr_dmamap_free(dma_map); }}/** * sn_pci_dma_sync_single_* - make sure all DMAs or CPU accesses * have completed * @hwdev: device to sync * @dma_handle: DMA address to sync * @size: size of region * @direction: DMA direction * * This routine is supposed to sync the DMA region specified * by @dma_handle into the 'coherence domain'. We do not need to do * anything on our platform. */voidsn_pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction){ return;}voidsn_pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction){ return;}/** * sn_pci_dma_sync_sg_* - make sure all DMAs or CPU accesses have completed * @hwdev: device to sync * @sg: scatterlist to sync * @nents: number of entries in the scatterlist * @direction: DMA direction * * This routine is supposed to sync the DMA regions specified * by @sg into the 'coherence domain'. We do not need to do anything * on our platform. */voidsn_pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction){ return;}voidsn_pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction){ return;}/** * sn_dma_supported - test a DMA mask * @hwdev: device to test * @mask: DMA mask to test * * Return whether the given PCI device DMA address mask can be supported * properly. For example, if your device can only drive the low 24-bits * during PCI bus mastering, then you would pass 0x00ffffff as the mask to * this function. Of course, SN only supports devices that have 32 or more * address bits when using the PMU. We could theoretically support <32 bit * cards using direct mapping, but we'll worry about that later--on the off * chance that someone actually wants to use such a card. */intsn_pci_dma_supported(struct pci_dev *hwdev, u64 mask){ if (mask < 0xffffffff) return 0; return 1;}/* * New generic DMA routines just wrap sn2 PCI routines until we * support other bus types (if ever). */intsn_dma_supported(struct device *dev, u64 mask){ BUG_ON(dev->bus != &pci_bus_type); return sn_pci_dma_supported(to_pci_dev(dev), mask);}EXPORT_SYMBOL(sn_dma_supported);intsn_dma_set_mask(struct device *dev, u64 dma_mask){ BUG_ON(dev->bus != &pci_bus_type); if (!sn_dma_supported(dev, dma_mask)) return 0; *dev->dma_mask = dma_mask; return 1;}EXPORT_SYMBOL(sn_dma_set_mask);void *sn_dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, int flag){ BUG_ON(dev->bus != &pci_bus_type); return sn_pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);}EXPORT_SYMBOL(sn_dma_alloc_coherent);voidsn_dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_handle){ BUG_ON(dev->bus != &pci_bus_type); sn_pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);}EXPORT_SYMBOL(sn_dma_free_coherent);dma_addr_tsn_dma_map_single(struct device *dev, void *cpu_addr, size_t size, int direction){ BUG_ON(dev->bus != &pci_bus_type); return sn_pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);}EXPORT_SYMBOL(sn_dma_map_single);voidsn_dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, int direction){ BUG_ON(dev->bus != &pci_bus_type); sn_pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);}EXPORT_SYMBOL(sn_dma_unmap_single);dma_addr_tsn_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, int direction){ BUG_ON(dev->bus != &pci_bus_type); return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);}EXPORT_SYMBOL(sn_dma_map_page);voidsn_dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size, int direction){ BUG_ON(dev->bus != &pci_bus_type); pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);}EXPORT_SYMBOL(sn_dma_unmap_page);intsn_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, int direction){ BUG_ON(dev->bus != &pci_bus_type); return sn_pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);}EXPORT_SYMBOL(sn_dma_map_sg);voidsn_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries, int direction){ BUG_ON(dev->bus != &pci_bus_type); sn_pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);}EXPORT_SYMBOL(sn_dma_unmap_sg);voidsn_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, int direction){ BUG_ON(dev->bus != &pci_bus_type); sn_pci_dma_sync_single_for_cpu(to_pci_dev(dev), dma_handle, size, (int)direction);}EXPORT_SYMBOL(sn_dma_sync_single_for_cpu);voidsn_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size, int direction){ BUG_ON(dev->bus != &pci_bus_type); sn_pci_dma_sync_single_for_device(to_pci_dev(dev), dma_handle, size, (int)direction);}EXPORT_SYMBOL(sn_dma_sync_single_for_device);voidsn_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems, int direction){ BUG_ON(dev->bus != &pci_bus_type); sn_pci_dma_sync_sg_for_cpu(to_pci_dev(dev), sg, nelems, (int)direction);}EXPORT_SYMBOL(sn_dma_sync_sg_for_cpu);voidsn_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems, int direction){ BUG_ON(dev->bus != &pci_bus_type); sn_pci_dma_sync_sg_for_device(to_pci_dev(dev), sg, nelems, (int)direction);}EXPORT_SYMBOL(sn_dma_sync_sg_for_device);intsn_dma_mapping_error(dma_addr_t dma_addr){ /* * We can only run out of page mapping entries, so if there's * an error, tell the caller to try again later. */ if (!dma_addr) return -EAGAIN; return 0;}EXPORT_SYMBOL(sn_dma_mapping_error);EXPORT_SYMBOL(sn_pci_unmap_single);EXPORT_SYMBOL(sn_pci_map_single);EXPORT_SYMBOL(sn_pci_dma_sync_single_for_cpu);EXPORT_SYMBOL(sn_pci_dma_sync_single_for_device);EXPORT_SYMBOL(sn_pci_dma_sync_sg_for_cpu);EXPORT_SYMBOL(sn_pci_dma_sync_sg_for_device);EXPORT_SYMBOL(sn_pci_map_sg);EXPORT_SYMBOL(sn_pci_unmap_sg);EXPORT_SYMBOL(sn_pci_alloc_consistent);EXPORT_SYMBOL(sn_pci_free_consistent);EXPORT_SYMBOL(sn_pci_dma_supported);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?