···7979 struct dmabounce_pool large;80808181 rwlock_t lock;8282+8383+ int (*needs_bounce)(struct device *, dma_addr_t, size_t);8284};83858486#ifdef STATS···212210 if (!dev || !dev->archdata.dmabounce)213211 return NULL;214212 if (dma_mapping_error(dev, dma_addr)) {215215- if (dev)216216- dev_err(dev, "Trying to %s invalid mapping\n", where);217217- else218218- pr_err("unknown device: Trying to %s invalid mapping\n", where);213213+ dev_err(dev, "Trying to %s invalid mapping\n", where);219214 return NULL;220215 }221216 return find_safe_buffer(dev->archdata.dmabounce, dma_addr);217217+}218218+219219+static int needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)220220+{221221+ if (!dev || !dev->archdata.dmabounce)222222+ return 0;223223+224224+ if (dev->dma_mask) {225225+ unsigned long limit, mask = *dev->dma_mask;226226+227227+ limit = (mask + 1) & ~mask;228228+ if (limit && size > limit) {229229+ dev_err(dev, "DMA mapping too big (requested %#x "230230+ "mask %#Lx)\n", size, *dev->dma_mask);231231+ return -E2BIG;232232+ }233233+234234+ /* Figure out if we need to bounce from the DMA mask. */235235+ if ((dma_addr | (dma_addr + size - 1)) & ~mask)236236+ return 1;237237+ }238238+239239+ return !!dev->archdata.dmabounce->needs_bounce(dev, dma_addr, size);222240}223241224242static inline dma_addr_t map_single(struct device *dev, void *ptr, size_t size,225243 enum dma_data_direction dir)226244{227245 struct dmabounce_device_info *device_info = dev->archdata.dmabounce;228228- dma_addr_t dma_addr;229229- int needs_bounce = 0;246246+ struct safe_buffer *buf;230247231248 if (device_info)232249 DO_STATS ( device_info->map_op_count++ );233250234234- dma_addr = virt_to_dma(dev, ptr);235235-236236- if (dev->dma_mask) {237237- unsigned long mask = *dev->dma_mask;238238- unsigned long limit;239239-240240- limit = (mask + 1) & ~mask;241241- if (limit && size > limit) {242242- dev_err(dev, "DMA mapping too big (requested %#x "243243- "mask %#Lx)\n", size, *dev->dma_mask);244244- return ~0;245245- }246246-247247- /*248248- * Figure out if we need to bounce from the DMA mask.249249- */250250- needs_bounce = (dma_addr | (dma_addr + size - 1)) & ~mask;251251+ buf = alloc_safe_buffer(device_info, ptr, size, dir);252252+ if (buf == NULL) {253253+ dev_err(dev, "%s: unable to map unsafe buffer %p!\n",254254+ __func__, ptr);255255+ return ~0;251256 }252257253253- if (device_info && (needs_bounce || dma_needs_bounce(dev, dma_addr, size))) {254254- struct safe_buffer *buf;258258+ dev_dbg(dev, "%s: unsafe buffer %p (dma=%#x) mapped to %p (dma=%#x)\n",259259+ __func__, buf->ptr, virt_to_dma(dev, buf->ptr),260260+ buf->safe, buf->safe_dma_addr);255261256256- buf = alloc_safe_buffer(device_info, ptr, size, dir);257257- if (buf == 0) {258258- dev_err(dev, "%s: unable to map unsafe buffer %p!\n",259259- __func__, ptr);260260- return ~0;261261- }262262-263263- dev_dbg(dev,264264- "%s: unsafe buffer %p (dma=%#x) mapped to %p (dma=%#x)\n",265265- __func__, buf->ptr, virt_to_dma(dev, buf->ptr),266266- buf->safe, buf->safe_dma_addr);267267-268268- if ((dir == DMA_TO_DEVICE) ||269269- (dir == DMA_BIDIRECTIONAL)) {270270- dev_dbg(dev, "%s: copy unsafe %p to safe %p, size %d\n",271271- __func__, ptr, buf->safe, size);272272- memcpy(buf->safe, ptr, size);273273- }274274- ptr = buf->safe;275275-276276- dma_addr = buf->safe_dma_addr;277277- } else {278278- /*279279- * We don't need to sync the DMA buffer since280280- * it was allocated via the coherent allocators.281281- */282282- __dma_single_cpu_to_dev(ptr, size, dir);262262+ if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL) {263263+ dev_dbg(dev, "%s: copy unsafe %p to safe %p, size %d\n",264264+ __func__, ptr, buf->safe, size);265265+ memcpy(buf->safe, ptr, size);283266 }284267285285- return dma_addr;268268+ return buf->safe_dma_addr;286269}287270288288-static inline void unmap_single(struct device *dev, dma_addr_t dma_addr,271271+static inline void unmap_single(struct device *dev, struct safe_buffer *buf,289272 size_t size, enum dma_data_direction dir)290273{291291- struct safe_buffer *buf = find_safe_buffer_dev(dev, dma_addr, "unmap");274274+ BUG_ON(buf->size != size);275275+ BUG_ON(buf->direction != dir);292276293293- if (buf) {294294- BUG_ON(buf->size != size);295295- BUG_ON(buf->direction != dir);277277+ dev_dbg(dev, "%s: unsafe buffer %p (dma=%#x) mapped to %p (dma=%#x)\n",278278+ __func__, buf->ptr, virt_to_dma(dev, buf->ptr),279279+ buf->safe, buf->safe_dma_addr);296280297297- dev_dbg(dev,298298- "%s: unsafe buffer %p (dma=%#x) mapped to %p (dma=%#x)\n",299299- __func__, buf->ptr, virt_to_dma(dev, buf->ptr),300300- buf->safe, buf->safe_dma_addr);281281+ DO_STATS(dev->archdata.dmabounce->bounce_count++);301282302302- DO_STATS(dev->archdata.dmabounce->bounce_count++);283283+ if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL) {284284+ void *ptr = buf->ptr;303285304304- if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL) {305305- void *ptr = buf->ptr;286286+ dev_dbg(dev, "%s: copy back safe %p to unsafe %p size %d\n",287287+ __func__, buf->safe, ptr, size);288288+ memcpy(ptr, buf->safe, size);306289307307- dev_dbg(dev,308308- "%s: copy back safe %p to unsafe %p size %d\n",309309- __func__, buf->safe, ptr, size);310310- memcpy(ptr, buf->safe, size);311311-312312- /*313313- * Since we may have written to a page cache page,314314- * we need to ensure that the data will be coherent315315- * with user mappings.316316- */317317- __cpuc_flush_dcache_area(ptr, size);318318- }319319- free_safe_buffer(dev->archdata.dmabounce, buf);320320- } else {321321- __dma_single_dev_to_cpu(dma_to_virt(dev, dma_addr), size, dir);290290+ /*291291+ * Since we may have written to a page cache page,292292+ * we need to ensure that the data will be coherent293293+ * with user mappings.294294+ */295295+ __cpuc_flush_dcache_area(ptr, size);322296 }297297+ free_safe_buffer(dev->archdata.dmabounce, buf);323298}324299325300/* ************************************************** */···307328 * substitute the safe buffer for the unsafe one.308329 * (basically move the buffer from an unsafe area to a safe one)309330 */310310-dma_addr_t __dma_map_single(struct device *dev, void *ptr, size_t size,311311- enum dma_data_direction dir)312312-{313313- dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",314314- __func__, ptr, size, dir);315315-316316- BUG_ON(!valid_dma_direction(dir));317317-318318- return map_single(dev, ptr, size, dir);319319-}320320-EXPORT_SYMBOL(__dma_map_single);321321-322322-/*323323- * see if a mapped address was really a "safe" buffer and if so, copy324324- * the data from the safe buffer back to the unsafe buffer and free up325325- * the safe buffer. (basically return things back to the way they326326- * should be)327327- */328328-void __dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,329329- enum dma_data_direction dir)330330-{331331- dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",332332- __func__, (void *) dma_addr, size, dir);333333-334334- unmap_single(dev, dma_addr, size, dir);335335-}336336-EXPORT_SYMBOL(__dma_unmap_single);337337-338331dma_addr_t __dma_map_page(struct device *dev, struct page *page,339332 unsigned long offset, size_t size, enum dma_data_direction dir)340333{334334+ dma_addr_t dma_addr;335335+ int ret;336336+341337 dev_dbg(dev, "%s(page=%p,off=%#lx,size=%zx,dir=%x)\n",342338 __func__, page, offset, size, dir);343339344344- BUG_ON(!valid_dma_direction(dir));340340+ dma_addr = pfn_to_dma(dev, page_to_pfn(page)) + offset;341341+342342+ ret = needs_bounce(dev, dma_addr, size);343343+ if (ret < 0)344344+ return ~0;345345+346346+ if (ret == 0) {347347+ __dma_page_cpu_to_dev(page, offset, size, dir);348348+ return dma_addr;349349+ }345350346351 if (PageHighMem(page)) {347347- dev_err(dev, "DMA buffer bouncing of HIGHMEM pages "348348- "is not supported\n");352352+ dev_err(dev, "DMA buffer bouncing of HIGHMEM pages is not supported\n");349353 return ~0;350354 }351355···345383void __dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,346384 enum dma_data_direction dir)347385{348348- dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",349349- __func__, (void *) dma_addr, size, dir);386386+ struct safe_buffer *buf;350387351351- unmap_single(dev, dma_addr, size, dir);388388+ dev_dbg(dev, "%s(dma=%#x,size=%d,dir=%x)\n",389389+ __func__, dma_addr, size, dir);390390+391391+ buf = find_safe_buffer_dev(dev, dma_addr, __func__);392392+ if (!buf) {393393+ __dma_page_dev_to_cpu(pfn_to_page(dma_to_pfn(dev, dma_addr)),394394+ dma_addr & ~PAGE_MASK, size, dir);395395+ return;396396+ }397397+398398+ unmap_single(dev, buf, size, dir);352399}353400EXPORT_SYMBOL(__dma_unmap_page);354401···432461}433462434463int dmabounce_register_dev(struct device *dev, unsigned long small_buffer_size,435435- unsigned long large_buffer_size)464464+ unsigned long large_buffer_size,465465+ int (*needs_bounce_fn)(struct device *, dma_addr_t, size_t))436466{437467 struct dmabounce_device_info *device_info;438468 int ret;···469497 device_info->dev = dev;470498 INIT_LIST_HEAD(&device_info->safe_buffers);471499 rwlock_init(&device_info->lock);500500+ device_info->needs_bounce = needs_bounce_fn;472501473502#ifdef STATS474503 device_info->total_allocs = 0;
+7-9
arch/arm/common/it8152.c
···243243 * ITE8152 chip can address up to 64MByte, so all the devices244244 * connected to ITE8152 (PCI and USB) should have limited DMA window245245 */246246+static int it8152_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)247247+{248248+ dev_dbg(dev, "%s: dma_addr %08x, size %08x\n",249249+ __func__, dma_addr, size);250250+ return (dma_addr + size - PHYS_OFFSET) >= SZ_64M;251251+}246252247253/*248254 * Setup DMA mask to 64MB on devices connected to ITE8152. Ignore all···260254 if (dev->dma_mask)261255 *dev->dma_mask = (SZ_64M - 1) | PHYS_OFFSET;262256 dev->coherent_dma_mask = (SZ_64M - 1) | PHYS_OFFSET;263263- dmabounce_register_dev(dev, 2048, 4096);257257+ dmabounce_register_dev(dev, 2048, 4096, it8152_needs_bounce);264258 }265259 return 0;266260}···271265 dmabounce_unregister_dev(dev);272266273267 return 0;274274-}275275-276276-int dma_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)277277-{278278- dev_dbg(dev, "%s: dma_addr %08x, size %08x\n",279279- __func__, dma_addr, size);280280- return (dev->bus == &pci_bus_type) &&281281- ((dma_addr + size - PHYS_OFFSET) >= SZ_64M);282268}283269284270int dma_set_coherent_mask(struct device *dev, u64 mask)
+31-29
arch/arm/common/sa1111.c
···579579580580 sachip->dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2];581581}582582+#endif582583584584+#ifdef CONFIG_DMABOUNCE585585+/*586586+ * According to the "Intel StrongARM SA-1111 Microprocessor Companion587587+ * Chip Specification Update" (June 2000), erratum #7, there is a588588+ * significant bug in the SA1111 SDRAM shared memory controller. If589589+ * an access to a region of memory above 1MB relative to the bank base,590590+ * it is important that address bit 10 _NOT_ be asserted. Depending591591+ * on the configuration of the RAM, bit 10 may correspond to one592592+ * of several different (processor-relative) address bits.593593+ *594594+ * This routine only identifies whether or not a given DMA address595595+ * is susceptible to the bug.596596+ *597597+ * This should only get called for sa1111_device types due to the598598+ * way we configure our device dma_masks.599599+ */600600+static int sa1111_needs_bounce(struct device *dev, dma_addr_t addr, size_t size)601601+{602602+ /*603603+ * Section 4.6 of the "Intel StrongARM SA-1111 Development Module604604+ * User's Guide" mentions that jumpers R51 and R52 control the605605+ * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or606606+ * SDRAM bank 1 on Neponset). The default configuration selects607607+ * Assabet, so any address in bank 1 is necessarily invalid.608608+ */609609+ return (machine_is_assabet() || machine_is_pfs168()) &&610610+ (addr >= 0xc8000000 || (addr + size) >= 0xc8000000);611611+}583612#endif584613585614static void sa1111_dev_release(struct device *_dev)···673644 dev->dev.dma_mask = &dev->dma_mask;674645675646 if (dev->dma_mask != 0xffffffffUL) {676676- ret = dmabounce_register_dev(&dev->dev, 1024, 4096);647647+ ret = dmabounce_register_dev(&dev->dev, 1024, 4096,648648+ sa1111_needs_bounce);677649 if (ret) {678650 dev_err(&dev->dev, "SA1111: Failed to register"679651 " with dmabounce\n");···846816 iounmap(sachip->base);847817 clk_put(sachip->clk);848818 kfree(sachip);849849-}850850-851851-/*852852- * According to the "Intel StrongARM SA-1111 Microprocessor Companion853853- * Chip Specification Update" (June 2000), erratum #7, there is a854854- * significant bug in the SA1111 SDRAM shared memory controller. If855855- * an access to a region of memory above 1MB relative to the bank base,856856- * it is important that address bit 10 _NOT_ be asserted. Depending857857- * on the configuration of the RAM, bit 10 may correspond to one858858- * of several different (processor-relative) address bits.859859- *860860- * This routine only identifies whether or not a given DMA address861861- * is susceptible to the bug.862862- *863863- * This should only get called for sa1111_device types due to the864864- * way we configure our device dma_masks.865865- */866866-int dma_needs_bounce(struct device *dev, dma_addr_t addr, size_t size)867867-{868868- /*869869- * Section 4.6 of the "Intel StrongARM SA-1111 Development Module870870- * User's Guide" mentions that jumpers R51 and R52 control the871871- * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or872872- * SDRAM bank 1 on Neponset). The default configuration selects873873- * Assabet, so any address in bank 1 is necessarily invalid.874874- */875875- return ((machine_is_assabet() || machine_is_pfs168()) &&876876- (addr >= 0xc8000000 || (addr + size) >= 0xc8000000));877819}878820879821struct sa1111_save_data {
+13-75
arch/arm/include/asm/dma-mapping.h
···115115 ___dma_page_dev_to_cpu(page, off, size, dir);116116}117117118118-/*119119- * Return whether the given device DMA address mask can be supported120120- * properly. For example, if your device can only drive the low 24-bits121121- * during bus mastering, then you would pass 0x00ffffff as the mask122122- * to this function.123123- *124124- * FIXME: This should really be a platform specific issue - we should125125- * return false if GFP_DMA allocations may not satisfy the supplied 'mask'.126126- */127127-static inline int dma_supported(struct device *dev, u64 mask)128128-{129129- if (mask < ISA_DMA_THRESHOLD)130130- return 0;131131- return 1;132132-}133133-134134-static inline int dma_set_mask(struct device *dev, u64 dma_mask)135135-{136136-#ifdef CONFIG_DMABOUNCE137137- if (dev->archdata.dmabounce) {138138- if (dma_mask >= ISA_DMA_THRESHOLD)139139- return 0;140140- else141141- return -EIO;142142- }143143-#endif144144- if (!dev->dma_mask || !dma_supported(dev, dma_mask))145145- return -EIO;146146-147147- *dev->dma_mask = dma_mask;148148-149149- return 0;150150-}118118+extern int dma_supported(struct device *, u64);119119+extern int dma_set_mask(struct device *, u64);151120152121/*153122 * DMA errors are defined by all-bits-set in the DMA address.···225256 * @dev: valid struct device pointer226257 * @small_buf_size: size of buffers to use with small buffer pool227258 * @large_buf_size: size of buffers to use with large buffer pool (can be 0)259259+ * @needs_bounce_fn: called to determine whether buffer needs bouncing228260 *229261 * This function should be called by low-level platform code to register230262 * a device as requireing DMA buffer bouncing. The function will allocate231263 * appropriate DMA pools for the device.232232- *233264 */234265extern int dmabounce_register_dev(struct device *, unsigned long,235235- unsigned long);266266+ unsigned long, int (*)(struct device *, dma_addr_t, size_t));236267237268/**238269 * dmabounce_unregister_dev···246277 */247278extern void dmabounce_unregister_dev(struct device *);248279249249-/**250250- * dma_needs_bounce251251- *252252- * @dev: valid struct device pointer253253- * @dma_handle: dma_handle of unbounced buffer254254- * @size: size of region being mapped255255- *256256- * Platforms that utilize the dmabounce mechanism must implement257257- * this function.258258- *259259- * The dmabounce routines call this function whenever a dma-mapping260260- * is requested to determine whether a given buffer needs to be bounced261261- * or not. The function must return 0 if the buffer is OK for262262- * DMA access and 1 if the buffer needs to be bounced.263263- *264264- */265265-extern int dma_needs_bounce(struct device*, dma_addr_t, size_t);266266-267280/*268281 * The DMA API, implemented by dmabounce.c. See below for descriptions.269282 */270270-extern dma_addr_t __dma_map_single(struct device *, void *, size_t,271271- enum dma_data_direction);272272-extern void __dma_unmap_single(struct device *, dma_addr_t, size_t,273273- enum dma_data_direction);274283extern dma_addr_t __dma_map_page(struct device *, struct page *,275284 unsigned long, size_t, enum dma_data_direction);276285extern void __dma_unmap_page(struct device *, dma_addr_t, size_t,···275328}276329277330278278-static inline dma_addr_t __dma_map_single(struct device *dev, void *cpu_addr,279279- size_t size, enum dma_data_direction dir)280280-{281281- __dma_single_cpu_to_dev(cpu_addr, size, dir);282282- return virt_to_dma(dev, cpu_addr);283283-}284284-285331static inline dma_addr_t __dma_map_page(struct device *dev, struct page *page,286332 unsigned long offset, size_t size, enum dma_data_direction dir)287333{288334 __dma_page_cpu_to_dev(page, offset, size, dir);289335 return pfn_to_dma(dev, page_to_pfn(page)) + offset;290290-}291291-292292-static inline void __dma_unmap_single(struct device *dev, dma_addr_t handle,293293- size_t size, enum dma_data_direction dir)294294-{295295- __dma_single_dev_to_cpu(dma_to_virt(dev, handle), size, dir);296336}297337298338static inline void __dma_unmap_page(struct device *dev, dma_addr_t handle,···307373static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,308374 size_t size, enum dma_data_direction dir)309375{376376+ unsigned long offset;377377+ struct page *page;310378 dma_addr_t addr;311379380380+ BUG_ON(!virt_addr_valid(cpu_addr));381381+ BUG_ON(!virt_addr_valid(cpu_addr + size - 1));312382 BUG_ON(!valid_dma_direction(dir));313383314314- addr = __dma_map_single(dev, cpu_addr, size, dir);315315- debug_dma_map_page(dev, virt_to_page(cpu_addr),316316- (unsigned long)cpu_addr & ~PAGE_MASK, size,317317- dir, addr, true);384384+ page = virt_to_page(cpu_addr);385385+ offset = (unsigned long)cpu_addr & ~PAGE_MASK;386386+ addr = __dma_map_page(dev, page, offset, size, dir);387387+ debug_dma_map_page(dev, page, offset, size, dir, addr, true);318388319389 return addr;320390}···368430 size_t size, enum dma_data_direction dir)369431{370432 debug_dma_unmap_page(dev, handle, size, dir, true);371371- __dma_unmap_single(dev, handle, size, dir);433433+ __dma_unmap_page(dev, handle, size, dir);372434}373435374436/**
+6-5
arch/arm/include/asm/dma.h
···11#ifndef __ASM_ARM_DMA_H22#define __ASM_ARM_DMA_H3344-#include <asm/memory.h>55-64/*75 * This is the maximum virtual address which can be DMA'd from.86 */99-#ifndef ARM_DMA_ZONE_SIZE1010-#define MAX_DMA_ADDRESS 0xffffffff77+#ifndef CONFIG_ZONE_DMA88+#define MAX_DMA_ADDRESS 0xffffffffUL119#else1212-#define MAX_DMA_ADDRESS (PAGE_OFFSET + ARM_DMA_ZONE_SIZE)1010+#define MAX_DMA_ADDRESS ({ \1111+ extern unsigned long arm_dma_zone_size; \1212+ arm_dma_zone_size ? \1313+ (PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; })1314#endif14151516#ifdef CONFIG_ISA_DMA_API
+4
arch/arm/include/asm/mach/arch.h
···23232424 unsigned int nr_irqs; /* number of IRQs */25252626+#ifdef CONFIG_ZONE_DMA2727+ unsigned long dma_zone_size; /* size of DMA-able area */2828+#endif2929+2630 unsigned int video_start; /* start of video RAM */2731 unsigned int video_end; /* end of video RAM */2832
-12
arch/arm/include/asm/memory.h
···204204#endif205205206206/*207207- * The DMA mask corresponding to the maximum bus address allocatable208208- * using GFP_DMA. The default here places no restriction on DMA209209- * allocations. This must be the smallest DMA mask in the system,210210- * so a successful GFP_DMA allocation will always satisfy this.211211- */212212-#ifndef ARM_DMA_ZONE_SIZE213213-#define ISA_DMA_THRESHOLD (0xffffffffULL)214214-#else215215-#define ISA_DMA_THRESHOLD (PHYS_OFFSET + ARM_DMA_ZONE_SIZE - 1)216216-#endif217217-218218-/*219207 * PFNs are used to describe any physical page; this means220208 * PFN 0 == physical address 0.221209 *
+6
arch/arm/kernel/setup.c
···918918 cpu_init();919919 tcm_init();920920921921+#ifdef CONFIG_ZONE_DMA922922+ if (mdesc->dma_zone_size) {923923+ extern unsigned long arm_dma_zone_size;924924+ arm_dma_zone_size = mdesc->dma_zone_size;925925+ }926926+#endif921927#ifdef CONFIG_MULTI_IRQ_HANDLER922928 handle_arch_irq = mdesc->handle_irq;923929#endif
···4141 */4242#define CONSISTENT_DMA_SIZE (14<<20)43434444-/*4545- * Restrict DMA-able region to workaround silicon bug. The bug4646- * restricts buffers available for DMA to video hardware to be4747- * below 128M4848- */4949-#define ARM_DMA_ZONE_SIZE SZ_128M5050-5144#endif /* __ASM_ARCH_MEMORY_H */
···88#define __ASM_ARCH_MEMORY_H991010#define PLAT_PHYS_OFFSET UL(0x40000000)1111-/*1212- * This is the maximum DMA address that can be DMAd to.1313- * There should not be more than (0xd0000000 - 0xc0000000)1414- * bytes of RAM.1515- */1616-#define ARM_DMA_ZONE_SIZE SZ_256M1717-1811#endif
···1414 */1515#define PLAT_PHYS_OFFSET UL(0xc0000000)16161717-#ifdef CONFIG_SA11111818-#define ARM_DMA_ZONE_SIZE SZ_1M1919-#endif2020-2117/*2218 * Because of the wide memory address space between physical RAM banks on the2319 * SA1100, it's much convenient to use Linux's SparseMEM support to implement
···2525#include <asm/tlbflush.h>2626#include <asm/sizes.h>27272828+#include "mm.h"2929+2830static u64 get_coherent_dma_mask(struct device *dev)2931{3030- u64 mask = ISA_DMA_THRESHOLD;3232+ u64 mask = (u64)arm_dma_limit;31333234 if (dev) {3335 mask = dev->coherent_dma_mask;···4341 return 0;4442 }45434646- if ((~mask) & ISA_DMA_THRESHOLD) {4444+ if ((~mask) & (u64)arm_dma_limit) {4745 dev_warn(dev, "coherent DMA mask %#llx is smaller "4846 "than system GFP_DMA mask %#llx\n",4949- mask, (unsigned long long)ISA_DMA_THRESHOLD);4747+ mask, (u64)arm_dma_limit);5048 return 0;5149 }5250 }···658656 debug_dma_sync_sg_for_device(dev, sg, nents, dir);659657}660658EXPORT_SYMBOL(dma_sync_sg_for_device);659659+660660+/*661661+ * Return whether the given device DMA address mask can be supported662662+ * properly. For example, if your device can only drive the low 24-bits663663+ * during bus mastering, then you would pass 0x00ffffff as the mask664664+ * to this function.665665+ */666666+int dma_supported(struct device *dev, u64 mask)667667+{668668+ if (mask < (u64)arm_dma_limit)669669+ return 0;670670+ return 1;671671+}672672+EXPORT_SYMBOL(dma_supported);673673+674674+int dma_set_mask(struct device *dev, u64 dma_mask)675675+{676676+ if (!dev->dma_mask || !dma_supported(dev, dma_mask))677677+ return -EIO;678678+679679+#ifndef CONFIG_DMABOUNCE680680+ *dev->dma_mask = dma_mask;681681+#endif682682+683683+ return 0;684684+}685685+EXPORT_SYMBOL(dma_set_mask);661686662687#define PREALLOC_DMA_DEBUG_ENTRIES 4096663688
+19-7
arch/arm/mm/init.c
···212212}213213214214#ifdef CONFIG_ZONE_DMA215215+216216+unsigned long arm_dma_zone_size __read_mostly;217217+EXPORT_SYMBOL(arm_dma_zone_size);218218+219219+/*220220+ * The DMA mask corresponding to the maximum bus address allocatable221221+ * using GFP_DMA. The default here places no restriction on DMA222222+ * allocations. This must be the smallest DMA mask in the system,223223+ * so a successful GFP_DMA allocation will always satisfy this.224224+ */225225+u32 arm_dma_limit;226226+215227static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole,216228 unsigned long dma_size)217229{···279267#endif280268 }281269282282-#ifdef ARM_DMA_ZONE_SIZE283283-#ifndef CONFIG_ZONE_DMA284284-#error ARM_DMA_ZONE_SIZE set but no DMA zone to limit allocations285285-#endif286286-270270+#ifdef CONFIG_ZONE_DMA287271 /*288272 * Adjust the sizes according to any special requirements for289273 * this machine type.290274 */291291- arm_adjust_dma_zone(zone_size, zhole_size,292292- ARM_DMA_ZONE_SIZE >> PAGE_SHIFT);275275+ if (arm_dma_zone_size) {276276+ arm_adjust_dma_zone(zone_size, zhole_size,277277+ arm_dma_zone_size >> PAGE_SHIFT);278278+ arm_dma_limit = PHYS_OFFSET + arm_dma_zone_size - 1;279279+ } else280280+ arm_dma_limit = 0xffffffff;293281#endif294282295283 free_area_init_node(0, zone_size, min, zhole_size);