···3131 */3232#define PCI_DMA_BUS_IS_PHYS (0)33333434-#include <asm/scatterlist.h>3535-3634struct pci_dev;3737-3838-/* Allocate and map kernel buffer using consistent mode DMA for a device.3939- * hwdev should be valid struct pci_dev pointer for PCI devices.4040- */4141-extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle);4242-4343-/* Free and unmap a consistent DMA buffer.4444- * cpu_addr is what was returned from pci_alloc_consistent,4545- * size must be the same as what as passed into pci_alloc_consistent,4646- * and likewise dma_addr must be the same as what *dma_addrp was set to.4747- *4848- * References to the memory and mappings assosciated with cpu_addr/dma_addr4949- * past this call are illegal.5050- */5151-extern void pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle);5252-5353-/* Map a single buffer of the indicated size for DMA in streaming mode.5454- * The 32-bit bus address to use is returned.5555- *5656- * Once the device is given the dma address, the device owns this memory5757- * until either pci_unmap_single or pci_dma_sync_single_for_cpu is performed.5858- */5959-extern dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction);6060-6161-/* Unmap a single streaming mode DMA translation. The dma_addr and size6262- * must match what was provided for in a previous pci_map_single call. All6363- * other usages are undefined.6464- *6565- * After this call, reads by the cpu to the buffer are guaranteed to see6666- * whatever the device wrote there.6767- */6868-extern void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction);69357036/* pci_unmap_{single,page} is not a nop, thus... */7137#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \···4781#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \4882 (((PTR)->LEN_NAME) = (VAL))49835050-/*5151- * Same as above, only with pages instead of mapped addresses.5252- */5353-extern dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,5454- unsigned long offset, size_t size, int direction);5555-extern void pci_unmap_page(struct pci_dev *hwdev,5656- dma_addr_t dma_address, size_t size, int direction);5757-5858-/* Map a set of buffers described by scatterlist in streaming5959- * mode for DMA. This is the scather-gather version of the6060- * above pci_map_single interface. Here the scatter gather list6161- * elements are each tagged with the appropriate dma address6262- * and length. They are obtained via sg_dma_{address,length}(SG).6363- *6464- * NOTE: An implementation may be able to use a smaller number of6565- * DMA address/length pairs than there are SG table elements.6666- * (for example via virtual mapping capabilities)6767- * The routine returns the number of addr/length pairs actually6868- * used, at most nents.6969- *7070- * Device ownership issues as mentioned above for pci_map_single are7171- * the same here.7272- */7373-extern int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction);7474-7575-/* Unmap a set of streaming mode DMA translations.7676- * Again, cpu read rules concerning calls here are the same as for7777- * pci_unmap_single() above.7878- */7979-extern void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nhwents, int direction);8080-8181-/* Make physical memory consistent for a single8282- * streaming mode DMA translation after a transfer.8383- *8484- * If you perform a pci_map_single() but wish to interrogate the8585- * buffer using the cpu, yet do not wish to teardown the PCI dma8686- * mapping, you must call this function before doing so. At the8787- * next point you give the PCI dma address back to the card, you8888- * must first perform a pci_dma_sync_for_device, and then the device8989- * again owns the buffer.9090- */9191-extern void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction);9292-extern void pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction);9393-9494-/* Make physical memory consistent for a set of streaming9595- * mode DMA translations after a transfer.9696- *9797- * The same as pci_dma_sync_single_* but for a scatter-gather list,9898- * same rules and usage.9999- */100100-extern void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction);101101-extern void pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction);102102-103103-/* Return whether the given PCI device DMA address mask can104104- * be supported properly. For example, if your device can105105- * only drive the low 24-bits during PCI bus mastering, then106106- * you would pass 0x00ffffff as the mask to this function.107107- */108108-static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)109109-{110110- return 1;111111-}112112-11384#ifdef CONFIG_PCI11485static inline void pci_dma_burst_advice(struct pci_dev *pdev,11586 enum pci_dma_burst_strategy *strat,···56153 *strategy_parameter = ~0UL;57154}58155#endif5959-6060-#define PCI_DMA_ERROR_CODE (~(dma_addr_t)0x0)6161-6262-static inline int pci_dma_mapping_error(struct pci_dev *pdev,6363- dma_addr_t dma_addr)6464-{6565- return (dma_addr == PCI_DMA_ERROR_CODE);6666-}6715668157struct device_node;69158extern struct device_node *pci_device_to_OF_node(struct pci_dev *pdev);
-88
arch/sparc/include/asm/pci_64.h
···3535 */3636#define PCI_DMA_BUS_IS_PHYS (0)37373838-static inline void *pci_alloc_consistent(struct pci_dev *pdev, size_t size,3939- dma_addr_t *dma_handle)4040-{4141- return dma_alloc_coherent(&pdev->dev, size, dma_handle, GFP_ATOMIC);4242-}4343-4444-static inline void pci_free_consistent(struct pci_dev *pdev, size_t size,4545- void *vaddr, dma_addr_t dma_handle)4646-{4747- return dma_free_coherent(&pdev->dev, size, vaddr, dma_handle);4848-}4949-5050-static inline dma_addr_t pci_map_single(struct pci_dev *pdev, void *ptr,5151- size_t size, int direction)5252-{5353- return dma_map_single(&pdev->dev, ptr, size,5454- (enum dma_data_direction) direction);5555-}5656-5757-static inline void pci_unmap_single(struct pci_dev *pdev, dma_addr_t dma_addr,5858- size_t size, int direction)5959-{6060- dma_unmap_single(&pdev->dev, dma_addr, size,6161- (enum dma_data_direction) direction);6262-}6363-6464-#define pci_map_page(dev, page, off, size, dir) \6565- pci_map_single(dev, (page_address(page) + (off)), size, dir)6666-#define pci_unmap_page(dev,addr,sz,dir) \6767- pci_unmap_single(dev,addr,sz,dir)6868-6938/* pci_unmap_{single,page} is not a nop, thus... */7039#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \7140 dma_addr_t ADDR_NAME;···4980#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \5081 (((PTR)->LEN_NAME) = (VAL))51825252-static inline int pci_map_sg(struct pci_dev *pdev, struct scatterlist *sg,5353- int nents, int direction)5454-{5555- return dma_map_sg(&pdev->dev, sg, nents,5656- (enum dma_data_direction) direction);5757-}5858-5959-static inline void pci_unmap_sg(struct pci_dev *pdev, struct scatterlist *sg,6060- int nents, int direction)6161-{6262- dma_unmap_sg(&pdev->dev, sg, nents,6363- (enum dma_data_direction) direction);6464-}6565-6666-static inline void pci_dma_sync_single_for_cpu(struct pci_dev *pdev,6767- dma_addr_t dma_handle,6868- size_t size, int direction)6969-{7070- dma_sync_single_for_cpu(&pdev->dev, dma_handle, size,7171- (enum dma_data_direction) direction);7272-}7373-7474-static inline void pci_dma_sync_single_for_device(struct pci_dev *pdev,7575- dma_addr_t dma_handle,7676- size_t size, int direction)7777-{7878- /* No flushing needed to sync cpu writes to the device. */7979-}8080-8181-static inline void pci_dma_sync_sg_for_cpu(struct pci_dev *pdev,8282- struct scatterlist *sg,8383- int nents, int direction)8484-{8585- dma_sync_sg_for_cpu(&pdev->dev, sg, nents,8686- (enum dma_data_direction) direction);8787-}8888-8989-static inline void pci_dma_sync_sg_for_device(struct pci_dev *pdev,9090- struct scatterlist *sg,9191- int nelems, int direction)9292-{9393- /* No flushing needed to sync cpu writes to the device. */9494-}9595-9696-/* Return whether the given PCI device DMA address mask can9797- * be supported properly. For example, if your device can9898- * only drive the low 24-bits during PCI bus mastering, then9999- * you would pass 0x00ffffff as the mask to this function.100100- */101101-extern int pci_dma_supported(struct pci_dev *hwdev, u64 mask);102102-10383/* PCI IOMMU mapping bypass support. */1048410585/* PCI 64-bit addressing works for all slots on all controller···57139 */58140#define PCI64_REQUIRED_MASK (~(dma64_addr_t)0)59141#define PCI64_ADDR_BASE 0xfffc000000000000UL6060-6161-static inline int pci_dma_mapping_error(struct pci_dev *pdev,6262- dma_addr_t dma_addr)6363-{6464- return dma_mapping_error(&pdev->dev, dma_addr);6565-}6614267143#ifdef CONFIG_PCI68144static inline void pci_dma_burst_advice(struct pci_dev *pdev,
···4848#include <asm/iommu.h>4949#include <asm/io-unit.h>50505151-#include "dma.h"5252-5351#define mmu_inval_dma_area(p, l) /* Anton pulled it out for 2.4.0-xx */54525553static struct resource *_sparc_find_resource(struct resource *r,···244246 * Typically devices use them for control blocks.245247 * CPU may access them without any explicit flushing.246248 */247247-void *sbus_alloc_consistent(struct device *dev, long len, u32 *dma_addrp)249249+static void *sbus_alloc_coherent(struct device *dev, size_t len,250250+ dma_addr_t *dma_addrp, gfp_t gfp)248251{249252 struct of_device *op = to_of_device(dev);250253 unsigned long len_total = (len + PAGE_SIZE-1) & PAGE_MASK;···298299 return NULL;299300}300301301301-void sbus_free_consistent(struct device *dev, long n, void *p, u32 ba)302302+static void sbus_free_coherent(struct device *dev, size_t n, void *p,303303+ dma_addr_t ba)302304{303305 struct resource *res;304306 struct page *pgv;···317317318318 n = (n + PAGE_SIZE-1) & PAGE_MASK;319319 if ((res->end-res->start)+1 != n) {320320- printk("sbus_free_consistent: region 0x%lx asked 0x%lx\n",320320+ printk("sbus_free_consistent: region 0x%lx asked 0x%zx\n",321321 (long)((res->end-res->start)+1), n);322322 return;323323 }···337337 * CPU view of this memory may be inconsistent with338338 * a device view and explicit flushing is necessary.339339 */340340-dma_addr_t sbus_map_single(struct device *dev, void *va, size_t len, int direction)340340+static dma_addr_t sbus_map_page(struct device *dev, struct page *page,341341+ unsigned long offset, size_t len,342342+ enum dma_data_direction dir,343343+ struct dma_attrs *attrs)341344{345345+ void *va = page_address(page) + offset;346346+342347 /* XXX why are some lengths signed, others unsigned? */343348 if (len <= 0) {344349 return 0;···355350 return mmu_get_scsi_one(dev, va, len);356351}357352358358-void sbus_unmap_single(struct device *dev, dma_addr_t ba, size_t n, int direction)353353+static void sbus_unmap_page(struct device *dev, dma_addr_t ba, size_t n,354354+ enum dma_data_direction dir, struct dma_attrs *attrs)359355{360356 mmu_release_scsi_one(dev, ba, n);361357}362358363363-int sbus_map_sg(struct device *dev, struct scatterlist *sg, int n, int direction)359359+static int sbus_map_sg(struct device *dev, struct scatterlist *sg, int n,360360+ enum dma_data_direction dir, struct dma_attrs *attrs)364361{365362 mmu_get_scsi_sgl(dev, sg, n);366363···373366 return n;374367}375368376376-void sbus_unmap_sg(struct device *dev, struct scatterlist *sg, int n, int direction)369369+static void sbus_unmap_sg(struct device *dev, struct scatterlist *sg, int n,370370+ enum dma_data_direction dir, struct dma_attrs *attrs)377371{378372 mmu_release_scsi_sgl(dev, sg, n);379373}380374381381-void sbus_dma_sync_single_for_cpu(struct device *dev, dma_addr_t ba, size_t size, int direction)375375+static void sbus_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,376376+ int n, enum dma_data_direction dir)382377{378378+ BUG();383379}384380385385-void sbus_dma_sync_single_for_device(struct device *dev, dma_addr_t ba, size_t size, int direction)381381+static void sbus_sync_sg_for_device(struct device *dev, struct scatterlist *sg,382382+ int n, enum dma_data_direction dir)386383{384384+ BUG();387385}386386+387387+struct dma_map_ops sbus_dma_ops = {388388+ .alloc_coherent = sbus_alloc_coherent,389389+ .free_coherent = sbus_free_coherent,390390+ .map_page = sbus_map_page,391391+ .unmap_page = sbus_unmap_page,392392+ .map_sg = sbus_map_sg,393393+ .unmap_sg = sbus_unmap_sg,394394+ .sync_sg_for_cpu = sbus_sync_sg_for_cpu,395395+ .sync_sg_for_device = sbus_sync_sg_for_device,396396+};397397+398398+struct dma_map_ops *dma_ops = &sbus_dma_ops;399399+EXPORT_SYMBOL(dma_ops);388400389401static int __init sparc_register_ioport(void)390402{···421395/* Allocate and map kernel buffer using consistent mode DMA for a device.422396 * hwdev should be valid struct pci_dev pointer for PCI devices.423397 */424424-void *pci_alloc_consistent(struct pci_dev *pdev, size_t len, dma_addr_t *pba)398398+static void *pci32_alloc_coherent(struct device *dev, size_t len,399399+ dma_addr_t *pba, gfp_t gfp)425400{426401 unsigned long len_total = (len + PAGE_SIZE-1) & PAGE_MASK;427402 unsigned long va;···466439 *pba = virt_to_phys(va); /* equals virt_to_bus (R.I.P.) for us. */467440 return (void *) res->start;468441}469469-EXPORT_SYMBOL(pci_alloc_consistent);470442471443/* Free and unmap a consistent DMA buffer.472444 * cpu_addr is what was returned from pci_alloc_consistent,···475449 * References to the memory and mappings associated with cpu_addr/dma_addr476450 * past this call are illegal.477451 */478478-void pci_free_consistent(struct pci_dev *pdev, size_t n, void *p, dma_addr_t ba)452452+static void pci32_free_coherent(struct device *dev, size_t n, void *p,453453+ dma_addr_t ba)479454{480455 struct resource *res;481456 unsigned long pgp;···508481509482 free_pages(pgp, get_order(n));510483}511511-EXPORT_SYMBOL(pci_free_consistent);512512-513513-/* Map a single buffer of the indicated size for DMA in streaming mode.514514- * The 32-bit bus address to use is returned.515515- *516516- * Once the device is given the dma address, the device owns this memory517517- * until either pci_unmap_single or pci_dma_sync_single_* is performed.518518- */519519-dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size,520520- int direction)521521-{522522- BUG_ON(direction == PCI_DMA_NONE);523523- /* IIep is write-through, not flushing. */524524- return virt_to_phys(ptr);525525-}526526-EXPORT_SYMBOL(pci_map_single);527527-528528-/* Unmap a single streaming mode DMA translation. The dma_addr and size529529- * must match what was provided for in a previous pci_map_single call. All530530- * other usages are undefined.531531- *532532- * After this call, reads by the cpu to the buffer are guaranteed to see533533- * whatever the device wrote there.534534- */535535-void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t ba, size_t size,536536- int direction)537537-{538538- BUG_ON(direction == PCI_DMA_NONE);539539- if (direction != PCI_DMA_TODEVICE) {540540- mmu_inval_dma_area((unsigned long)phys_to_virt(ba),541541- (size + PAGE_SIZE-1) & PAGE_MASK);542542- }543543-}544544-EXPORT_SYMBOL(pci_unmap_single);545484546485/*547486 * Same as pci_map_single, but with pages.548487 */549549-dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,550550- unsigned long offset, size_t size, int direction)488488+static dma_addr_t pci32_map_page(struct device *dev, struct page *page,489489+ unsigned long offset, size_t size,490490+ enum dma_data_direction dir,491491+ struct dma_attrs *attrs)551492{552552- BUG_ON(direction == PCI_DMA_NONE);553493 /* IIep is write-through, not flushing. */554494 return page_to_phys(page) + offset;555495}556556-EXPORT_SYMBOL(pci_map_page);557557-558558-void pci_unmap_page(struct pci_dev *hwdev,559559- dma_addr_t dma_address, size_t size, int direction)560560-{561561- BUG_ON(direction == PCI_DMA_NONE);562562- /* mmu_inval_dma_area XXX */563563-}564564-EXPORT_SYMBOL(pci_unmap_page);565496566497/* Map a set of buffers described by scatterlist in streaming567498 * mode for DMA. This is the scather-gather version of the···536551 * Device ownership issues as mentioned above for pci_map_single are537552 * the same here.538553 */539539-int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sgl, int nents,540540- int direction)554554+static int pci32_map_sg(struct device *device, struct scatterlist *sgl,555555+ int nents, enum dma_data_direction dir,556556+ struct dma_attrs *attrs)541557{542558 struct scatterlist *sg;543559 int n;544560545545- BUG_ON(direction == PCI_DMA_NONE);546561 /* IIep is write-through, not flushing. */547562 for_each_sg(sgl, sg, nents, n) {548563 BUG_ON(page_address(sg_page(sg)) == NULL);···551566 }552567 return nents;553568}554554-EXPORT_SYMBOL(pci_map_sg);555569556570/* Unmap a set of streaming mode DMA translations.557571 * Again, cpu read rules concerning calls here are the same as for558572 * pci_unmap_single() above.559573 */560560-void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sgl, int nents,561561- int direction)574574+static void pci32_unmap_sg(struct device *dev, struct scatterlist *sgl,575575+ int nents, enum dma_data_direction dir,576576+ struct dma_attrs *attrs)562577{563578 struct scatterlist *sg;564579 int n;565580566566- BUG_ON(direction == PCI_DMA_NONE);567567- if (direction != PCI_DMA_TODEVICE) {581581+ if (dir != PCI_DMA_TODEVICE) {568582 for_each_sg(sgl, sg, nents, n) {569583 BUG_ON(page_address(sg_page(sg)) == NULL);570584 mmu_inval_dma_area(···572588 }573589 }574590}575575-EXPORT_SYMBOL(pci_unmap_sg);576591577592/* Make physical memory consistent for a single578593 * streaming mode DMA translation before or after a transfer.···583600 * must first perform a pci_dma_sync_for_device, and then the584601 * device again owns the buffer.585602 */586586-void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t ba, size_t size, int direction)603603+static void pci32_sync_single_for_cpu(struct device *dev, dma_addr_t ba,604604+ size_t size, enum dma_data_direction dir)587605{588588- BUG_ON(direction == PCI_DMA_NONE);589589- if (direction != PCI_DMA_TODEVICE) {606606+ if (dir != PCI_DMA_TODEVICE) {590607 mmu_inval_dma_area((unsigned long)phys_to_virt(ba),591608 (size + PAGE_SIZE-1) & PAGE_MASK);592609 }593610}594594-EXPORT_SYMBOL(pci_dma_sync_single_for_cpu);595611596596-void pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t ba, size_t size, int direction)612612+static void pci32_sync_single_for_device(struct device *dev, dma_addr_t ba,613613+ size_t size, enum dma_data_direction dir)597614{598598- BUG_ON(direction == PCI_DMA_NONE);599599- if (direction != PCI_DMA_TODEVICE) {615615+ if (dir != PCI_DMA_TODEVICE) {600616 mmu_inval_dma_area((unsigned long)phys_to_virt(ba),601617 (size + PAGE_SIZE-1) & PAGE_MASK);602618 }603619}604604-EXPORT_SYMBOL(pci_dma_sync_single_for_device);605620606621/* Make physical memory consistent for a set of streaming607622 * mode DMA translations after a transfer.···607626 * The same as pci_dma_sync_single_* but for a scatter-gather list,608627 * same rules and usage.609628 */610610-void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, int direction)629629+static void pci32_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl,630630+ int nents, enum dma_data_direction dir)611631{612632 struct scatterlist *sg;613633 int n;614634615615- BUG_ON(direction == PCI_DMA_NONE);616616- if (direction != PCI_DMA_TODEVICE) {635635+ if (dir != PCI_DMA_TODEVICE) {617636 for_each_sg(sgl, sg, nents, n) {618637 BUG_ON(page_address(sg_page(sg)) == NULL);619638 mmu_inval_dma_area(···622641 }623642 }624643}625625-EXPORT_SYMBOL(pci_dma_sync_sg_for_cpu);626644627627-void pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, int direction)645645+static void pci32_sync_sg_for_device(struct device *device, struct scatterlist *sgl,646646+ int nents, enum dma_data_direction dir)628647{629648 struct scatterlist *sg;630649 int n;631650632632- BUG_ON(direction == PCI_DMA_NONE);633633- if (direction != PCI_DMA_TODEVICE) {651651+ if (dir != PCI_DMA_TODEVICE) {634652 for_each_sg(sgl, sg, nents, n) {635653 BUG_ON(page_address(sg_page(sg)) == NULL);636654 mmu_inval_dma_area(···638658 }639659 }640660}641641-EXPORT_SYMBOL(pci_dma_sync_sg_for_device);661661+662662+struct dma_map_ops pci32_dma_ops = {663663+ .alloc_coherent = pci32_alloc_coherent,664664+ .free_coherent = pci32_free_coherent,665665+ .map_page = pci32_map_page,666666+ .map_sg = pci32_map_sg,667667+ .unmap_sg = pci32_unmap_sg,668668+ .sync_single_for_cpu = pci32_sync_single_for_cpu,669669+ .sync_single_for_device = pci32_sync_single_for_device,670670+ .sync_sg_for_cpu = pci32_sync_sg_for_cpu,671671+ .sync_sg_for_device = pci32_sync_sg_for_device,672672+};673673+EXPORT_SYMBOL(pci32_dma_ops);674674+642675#endif /* CONFIG_PCI */676676+677677+/*678678+ * Return whether the given PCI device DMA address mask can be679679+ * supported properly. For example, if your device can only drive the680680+ * low 24-bits during PCI bus mastering, then you would pass681681+ * 0x00ffffff as the mask to this function.682682+ */683683+int dma_supported(struct device *dev, u64 mask)684684+{685685+#ifdef CONFIG_PCI686686+ if (dev->bus == &pci_bus_type)687687+ return 1;688688+#endif689689+ return 0;690690+}691691+EXPORT_SYMBOL(dma_supported);692692+693693+int dma_set_mask(struct device *dev, u64 dma_mask)694694+{695695+#ifdef CONFIG_PCI696696+ if (dev->bus == &pci_bus_type)697697+ return pci_set_dma_mask(to_pci_dev(dev), dma_mask);698698+#endif699699+ return -EOPNOTSUPP;700700+}701701+EXPORT_SYMBOL(dma_set_mask);702702+643703644704#ifdef CONFIG_PROC_FS645705