Merge branch 'vm_ioremap_memory-examples'

I'm going to do an -rc8, so I'm just going to do this rather than delay
it any further. They are arguably stable material anyway.

* vm_ioremap_memory-examples:
mtdchar: remove no-longer-used vma helpers
vm: convert snd_pcm_lib_mmap_iomem() to vm_iomap_memory() helper
vm: convert fb_mmap to vm_iomap_memory() helper
vm: convert mtdchar mmap to vm_iomap_memory() helper
vm: convert HPET mmap to vm_iomap_memory() helper

Changed files
+19 -105
drivers
char
mtd
video
sound
+1 -13
drivers/char/hpet.c
··· 373 373 struct hpet_dev *devp; 374 374 unsigned long addr; 375 375 376 - if (((vma->vm_end - vma->vm_start) != PAGE_SIZE) || vma->vm_pgoff) 377 - return -EINVAL; 378 - 379 376 devp = file->private_data; 380 377 addr = devp->hd_hpets->hp_hpet_phys; 381 378 382 379 if (addr & (PAGE_SIZE - 1)) 383 380 return -ENOSYS; 384 381 385 - vma->vm_flags |= VM_IO; 386 382 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 387 - 388 - if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT, 389 - PAGE_SIZE, vma->vm_page_prot)) { 390 - printk(KERN_ERR "%s: io_remap_pfn_range failed\n", 391 - __func__); 392 - return -EAGAIN; 393 - } 394 - 395 - return 0; 383 + return vm_iomap_memory(vma, addr, PAGE_SIZE); 396 384 #else 397 385 return -ENOSYS; 398 386 #endif
+2 -57
drivers/mtd/mtdchar.c
··· 1123 1123 } 1124 1124 #endif 1125 1125 1126 - static inline unsigned long get_vm_size(struct vm_area_struct *vma) 1127 - { 1128 - return vma->vm_end - vma->vm_start; 1129 - } 1130 - 1131 - static inline resource_size_t get_vm_offset(struct vm_area_struct *vma) 1132 - { 1133 - return (resource_size_t) vma->vm_pgoff << PAGE_SHIFT; 1134 - } 1135 - 1136 - /* 1137 - * Set a new vm offset. 1138 - * 1139 - * Verify that the incoming offset really works as a page offset, 1140 - * and that the offset and size fit in a resource_size_t. 1141 - */ 1142 - static inline int set_vm_offset(struct vm_area_struct *vma, resource_size_t off) 1143 - { 1144 - pgoff_t pgoff = off >> PAGE_SHIFT; 1145 - if (off != (resource_size_t) pgoff << PAGE_SHIFT) 1146 - return -EINVAL; 1147 - if (off + get_vm_size(vma) - 1 < off) 1148 - return -EINVAL; 1149 - vma->vm_pgoff = pgoff; 1150 - return 0; 1151 - } 1152 - 1153 1126 /* 1154 1127 * set up a mapping for shared memory segments 1155 1128 */ ··· 1132 1159 struct mtd_file_info *mfi = file->private_data; 1133 1160 struct mtd_info *mtd = mfi->mtd; 1134 1161 struct map_info *map = mtd->priv; 1135 - resource_size_t start, off; 1136 - unsigned long len, vma_len; 1137 1162 1138 1163 /* This is broken because it assumes the MTD device is map-based 1139 1164 and that mtd->priv is a valid struct map_info. It should be 1140 1165 replaced with something that uses the mtd_get_unmapped_area() 1141 1166 operation properly. */ 1142 1167 if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) { 1143 - off = get_vm_offset(vma); 1144 - start = map->phys; 1145 - len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size); 1146 - start &= PAGE_MASK; 1147 - vma_len = get_vm_size(vma); 1148 - 1149 - /* Overflow in off+len? */ 1150 - if (vma_len + off < off) 1151 - return -EINVAL; 1152 - /* Does it fit in the mapping? */ 1153 - if (vma_len + off > len) 1154 - return -EINVAL; 1155 - 1156 - off += start; 1157 - /* Did that overflow? */ 1158 - if (off < start) 1159 - return -EINVAL; 1160 - if (set_vm_offset(vma, off) < 0) 1161 - return -EINVAL; 1162 - vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP; 1163 - 1164 1168 #ifdef pgprot_noncached 1165 - if (file->f_flags & O_DSYNC || off >= __pa(high_memory)) 1169 + if (file->f_flags & O_DSYNC || map->phys >= __pa(high_memory)) 1166 1170 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 1167 1171 #endif 1168 - if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, 1169 - vma->vm_end - vma->vm_start, 1170 - vma->vm_page_prot)) 1171 - return -EAGAIN; 1172 - 1173 - return 0; 1172 + return vm_iomap_memory(vma, map->phys, map->size); 1174 1173 } 1175 1174 return -ENOSYS; 1176 1175 #else
+14 -25
drivers/video/fbmem.c
··· 1373 1373 { 1374 1374 struct fb_info *info = file_fb_info(file); 1375 1375 struct fb_ops *fb; 1376 - unsigned long off; 1376 + unsigned long mmio_pgoff; 1377 1377 unsigned long start; 1378 1378 u32 len; 1379 1379 1380 1380 if (!info) 1381 1381 return -ENODEV; 1382 - if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) 1383 - return -EINVAL; 1384 - off = vma->vm_pgoff << PAGE_SHIFT; 1385 1382 fb = info->fbops; 1386 1383 if (!fb) 1387 1384 return -ENODEV; ··· 1390 1393 return res; 1391 1394 } 1392 1395 1393 - /* frame buffer memory */ 1396 + /* 1397 + * Ugh. This can be either the frame buffer mapping, or 1398 + * if pgoff points past it, the mmio mapping. 1399 + */ 1394 1400 start = info->fix.smem_start; 1395 - len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len); 1396 - if (off >= len) { 1397 - /* memory mapped io */ 1398 - off -= len; 1399 - if (info->var.accel_flags) { 1400 - mutex_unlock(&info->mm_lock); 1401 - return -EINVAL; 1402 - } 1401 + len = info->fix.smem_len; 1402 + mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT; 1403 + if (vma->vm_pgoff >= mmio_pgoff) { 1404 + vma->vm_pgoff -= mmio_pgoff; 1403 1405 start = info->fix.mmio_start; 1404 - len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len); 1406 + len = info->fix.mmio_len; 1405 1407 } 1406 1408 mutex_unlock(&info->mm_lock); 1407 - start &= PAGE_MASK; 1408 - if ((vma->vm_end - vma->vm_start + off) > len) 1409 - return -EINVAL; 1410 - off += start; 1411 - vma->vm_pgoff = off >> PAGE_SHIFT; 1412 - /* VM_IO | VM_DONTEXPAND | VM_DONTDUMP are set by io_remap_pfn_range()*/ 1409 + 1413 1410 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); 1414 - fb_pgprotect(file, vma, off); 1415 - if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, 1416 - vma->vm_end - vma->vm_start, vma->vm_page_prot)) 1417 - return -EAGAIN; 1418 - return 0; 1411 + fb_pgprotect(file, vma, start); 1412 + 1413 + return vm_iomap_memory(vma, start, len); 1419 1414 } 1420 1415 1421 1416 static int
+2 -10
sound/core/pcm_native.c
··· 3222 3222 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, 3223 3223 struct vm_area_struct *area) 3224 3224 { 3225 - long size; 3226 - unsigned long offset; 3225 + struct snd_pcm_runtime *runtime = substream->runtime;; 3227 3226 3228 3227 area->vm_page_prot = pgprot_noncached(area->vm_page_prot); 3229 - area->vm_flags |= VM_IO; 3230 - size = area->vm_end - area->vm_start; 3231 - offset = area->vm_pgoff << PAGE_SHIFT; 3232 - if (io_remap_pfn_range(area, area->vm_start, 3233 - (substream->runtime->dma_addr + offset) >> PAGE_SHIFT, 3234 - size, area->vm_page_prot)) 3235 - return -EAGAIN; 3236 - return 0; 3228 + return vm_iomap_memory(area, runtime->dma_addr, runtime->dma_bytes); 3237 3229 } 3238 3230 3239 3231 EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem);