Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "staging: tidspbridge - rename bridge_brd_mem_map/unmap to a proper name"

This reverts commit 4dd1944ab7242d76534c97d5fef0ce541a2f1040.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Omar Ramirez Luna <omar.ramirez@ti.com>

authored by

Felipe Contreras and committed by
Omar Ramirez Luna
d0b345f3 ac8a139a

+141 -116
-24
drivers/staging/tidspbridge/core/_tiomap.h
··· 383 383 */ 384 384 int sm_interrupt_dsp(struct bridge_dev_context *dev_context, u16 mb_val); 385 385 386 - /** 387 - * user_to_dsp_map() - maps user to dsp virtual address 388 - * @mmu: Pointer to iommu handle. 389 - * @uva: Virtual user space address. 390 - * @da DSP address 391 - * @size Buffer size to map. 392 - * @usr_pgs struct page array pointer where the user pages will be stored 393 - * 394 - * This function maps a user space buffer into DSP virtual address. 395 - * 396 - */ 397 - u32 user_to_dsp_map(struct iommu *mmu, u32 uva, u32 da, u32 size, 398 - struct page **usr_pgs); 399 - 400 - /** 401 - * user_to_dsp_unmap() - unmaps DSP virtual buffer. 402 - * @mmu: Pointer to iommu handle. 403 - * @da DSP address 404 - * 405 - * This function unmaps a user space buffer into DSP virtual address. 406 - * 407 - */ 408 - int user_to_dsp_unmap(struct iommu *mmu, u32 da); 409 - 410 386 #endif /* _TIOMAP_ */
+79 -74
drivers/staging/tidspbridge/core/tiomap3430.c
··· 109 109 static int bridge_brd_mem_write(struct bridge_dev_context *dev_ctxt, 110 110 u8 *host_buff, u32 dsp_addr, 111 111 u32 ul_num_bytes, u32 mem_type); 112 + static int bridge_brd_mem_map(struct bridge_dev_context *dev_ctxt, 113 + u32 ul_mpu_addr, u32 virt_addr, 114 + u32 ul_num_bytes, u32 ul_map_attr, 115 + struct page **mapped_pages); 116 + static int bridge_brd_mem_un_map(struct bridge_dev_context *dev_ctxt, 117 + u32 da); 112 118 static int bridge_dev_create(struct bridge_dev_context 113 119 **dev_cntxt, 114 120 struct dev_object *hdev_obj, ··· 122 116 static int bridge_dev_ctrl(struct bridge_dev_context *dev_context, 123 117 u32 dw_cmd, void *pargs); 124 118 static int bridge_dev_destroy(struct bridge_dev_context *dev_ctxt); 119 + static int get_io_pages(struct mm_struct *mm, u32 uva, unsigned pages, 120 + struct page **usr_pgs); 121 + static u32 user_va2_pa(struct mm_struct *mm, u32 address); 125 122 static int pte_update(struct bridge_dev_context *dev_ctxt, u32 pa, 126 123 u32 va, u32 size, 127 124 struct hw_mmu_map_attrs_t *map_attrs); ··· 194 185 bridge_brd_set_state, 195 186 bridge_brd_mem_copy, 196 187 bridge_brd_mem_write, 188 + bridge_brd_mem_map, 189 + bridge_brd_mem_un_map, 197 190 /* The following CHNL functions are provided by chnl_io.lib: */ 198 191 bridge_chnl_create, 199 192 bridge_chnl_destroy, ··· 1166 1155 } 1167 1156 1168 1157 /* 1169 - * ======== user_va2_pa ======== 1170 - * Purpose: 1171 - * This function walks through the page tables to convert a userland 1172 - * virtual address to physical address 1173 - */ 1174 - static u32 user_va2_pa(struct mm_struct *mm, u32 address) 1175 - { 1176 - pgd_t *pgd; 1177 - pmd_t *pmd; 1178 - pte_t *ptep, pte; 1179 - 1180 - pgd = pgd_offset(mm, address); 1181 - if (!(pgd_none(*pgd) || pgd_bad(*pgd))) { 1182 - pmd = pmd_offset(pgd, address); 1183 - if (!(pmd_none(*pmd) || pmd_bad(*pmd))) { 1184 - ptep = pte_offset_map(pmd, address); 1185 - if (ptep) { 1186 - pte = *ptep; 1187 - if (pte_present(pte)) 1188 - return pte & PAGE_MASK; 1189 - } 1190 - } 1191 - } 1192 - 1193 - return 0; 1194 - } 1195 - 1196 - /** 1197 - * get_io_pages() - pin and get pages of io user's buffer. 1198 - * @mm: mm_struct Pointer of the process. 1199 - * @uva: Virtual user space address. 1200 - * @pages Pages to be pined. 1201 - * @usr_pgs struct page array pointer where the user pages will be stored 1158 + * ======== bridge_brd_mem_map ======== 1159 + * This function maps MPU buffer to the DSP address space. It performs 1160 + * linear to physical address translation if required. It translates each 1161 + * page since linear addresses can be physically non-contiguous 1162 + * All address & size arguments are assumed to be page aligned (in proc.c) 1202 1163 * 1164 + * TODO: Disable MMU while updating the page tables (but that'll stall DSP) 1203 1165 */ 1204 - static int get_io_pages(struct mm_struct *mm, u32 uva, unsigned pages, 1205 - struct page **usr_pgs) 1206 - { 1207 - u32 pa; 1208 - int i; 1209 - struct page *pg; 1166 + static int bridge_brd_mem_map(struct bridge_dev_context *dev_ctx, 1167 + u32 uva, u32 da, u32 size, u32 attr, 1168 + struct page **usr_pgs) 1210 1169 1211 - for (i = 0; i < pages; i++) { 1212 - pa = user_va2_pa(mm, uva); 1213 - 1214 - if (!pfn_valid(__phys_to_pfn(pa))) 1215 - break; 1216 - 1217 - pg = PHYS_TO_PAGE(pa); 1218 - usr_pgs[i] = pg; 1219 - get_page(pg); 1220 - } 1221 - return i; 1222 - } 1223 - 1224 - /** 1225 - * user_to_dsp_map() - maps user to dsp virtual address 1226 - * @mmu: Pointer to iommu handle. 1227 - * @uva: Virtual user space address. 1228 - * @da DSP address 1229 - * @size Buffer size to map. 1230 - * @usr_pgs struct page array pointer where the user pages will be stored 1231 - * 1232 - * This function maps a user space buffer into DSP virtual address. 1233 - * 1234 - */ 1235 - u32 user_to_dsp_map(struct iommu *mmu, u32 uva, u32 da, u32 size, 1236 - struct page **usr_pgs) 1237 1170 { 1238 1171 int res, w; 1239 1172 unsigned pages, i; 1173 + struct iommu *mmu = dev_ctx->dsp_mmu; 1240 1174 struct vm_area_struct *vma; 1241 1175 struct mm_struct *mm = current->mm; 1242 1176 struct sg_table *sgt; ··· 1238 1282 da = iommu_vmap(mmu, da, sgt, IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_32); 1239 1283 1240 1284 if (!IS_ERR_VALUE(da)) 1241 - return da; 1285 + return 0; 1242 1286 res = (int)da; 1243 1287 1244 1288 sg_free_table(sgt); ··· 1251 1295 return res; 1252 1296 } 1253 1297 1254 - /** 1255 - * user_to_dsp_unmap() - unmaps DSP virtual buffer. 1256 - * @mmu: Pointer to iommu handle. 1257 - * @da DSP address 1298 + /* 1299 + * ======== bridge_brd_mem_un_map ======== 1300 + * Invalidate the PTEs for the DSP VA block to be unmapped. 1258 1301 * 1259 - * This function unmaps a user space buffer into DSP virtual address. 1260 - * 1302 + * PTEs of a mapped memory block are contiguous in any page table 1303 + * So, instead of looking up the PTE address for every 4K block, 1304 + * we clear consecutive PTEs until we unmap all the bytes 1261 1305 */ 1262 - int user_to_dsp_unmap(struct iommu *mmu, u32 da) 1306 + static int bridge_brd_mem_un_map(struct bridge_dev_context *dev_ctx, u32 da) 1263 1307 { 1264 1308 unsigned i; 1265 1309 struct sg_table *sgt; 1266 1310 struct scatterlist *sg; 1267 1311 1268 - sgt = iommu_vunmap(mmu, da); 1312 + sgt = iommu_vunmap(dev_ctx->dsp_mmu, da); 1269 1313 if (!sgt) 1270 1314 return -EFAULT; 1271 1315 ··· 1273 1317 put_page(sg_page(sg)); 1274 1318 sg_free_table(sgt); 1275 1319 kfree(sgt); 1320 + 1321 + return 0; 1322 + } 1323 + 1324 + 1325 + static int get_io_pages(struct mm_struct *mm, u32 uva, unsigned pages, 1326 + struct page **usr_pgs) 1327 + { 1328 + u32 pa; 1329 + int i; 1330 + struct page *pg; 1331 + 1332 + for (i = 0; i < pages; i++) { 1333 + pa = user_va2_pa(mm, uva); 1334 + 1335 + if (!pfn_valid(__phys_to_pfn(pa))) 1336 + break; 1337 + 1338 + pg = PHYS_TO_PAGE(pa); 1339 + usr_pgs[i] = pg; 1340 + get_page(pg); 1341 + } 1342 + return i; 1343 + } 1344 + 1345 + /* 1346 + * ======== user_va2_pa ======== 1347 + * Purpose: 1348 + * This function walks through the page tables to convert a userland 1349 + * virtual address to physical address 1350 + */ 1351 + static u32 user_va2_pa(struct mm_struct *mm, u32 address) 1352 + { 1353 + pgd_t *pgd; 1354 + pmd_t *pmd; 1355 + pte_t *ptep, pte; 1356 + 1357 + pgd = pgd_offset(mm, address); 1358 + if (!(pgd_none(*pgd) || pgd_bad(*pgd))) { 1359 + pmd = pmd_offset(pgd, address); 1360 + if (!(pmd_none(*pmd) || pmd_bad(*pmd))) { 1361 + ptep = pte_offset_map(pmd, address); 1362 + if (ptep) { 1363 + pte = *ptep; 1364 + if (pte_present(pte)) 1365 + return pte & PAGE_MASK; 1366 + } 1367 + } 1368 + } 1276 1369 1277 1370 return 0; 1278 1371 }
+44
drivers/staging/tidspbridge/include/dspbridge/dspdefs.h
··· 162 162 u32 mem_type); 163 163 164 164 /* 165 + * ======== bridge_brd_mem_map ======== 166 + * Purpose: 167 + * Map a MPU memory region to a DSP/IVA memory space 168 + * Parameters: 169 + * dev_ctxt: Handle to Bridge driver defined device info. 170 + * ul_mpu_addr: MPU memory region start address. 171 + * virt_addr: DSP/IVA memory region u8 address. 172 + * ul_num_bytes: Number of bytes to map. 173 + * map_attrs: Mapping attributes (e.g. endianness). 174 + * Returns: 175 + * 0: Success. 176 + * -EPERM: Other, unspecified error. 177 + * Requires: 178 + * dev_ctxt != NULL; 179 + * Ensures: 180 + */ 181 + typedef int(*fxn_brd_memmap) (struct bridge_dev_context 182 + * dev_ctxt, u32 ul_mpu_addr, 183 + u32 virt_addr, u32 ul_num_bytes, 184 + u32 map_attr, 185 + struct page **mapped_pages); 186 + 187 + /* 188 + * ======== bridge_brd_mem_un_map ======== 189 + * Purpose: 190 + * UnMap an MPU memory region from DSP/IVA memory space 191 + * Parameters: 192 + * dev_ctxt: Handle to Bridge driver defined device info. 193 + * virt_addr: DSP/IVA memory region u8 address. 194 + * ul_num_bytes: Number of bytes to unmap. 195 + * Returns: 196 + * 0: Success. 197 + * -EPERM: Other, unspecified error. 198 + * Requires: 199 + * dev_ctxt != NULL; 200 + * Ensures: 201 + */ 202 + typedef int(*fxn_brd_memunmap) (struct bridge_dev_context 203 + * dev_ctxt, 204 + u32 da); 205 + 206 + /* 165 207 * ======== bridge_brd_stop ======== 166 208 * Purpose: 167 209 * Bring board to the BRD_STOPPED state. ··· 993 951 fxn_brd_setstate pfn_brd_set_state; /* Sets the Board State */ 994 952 fxn_brd_memcopy pfn_brd_mem_copy; /* Copies DSP Memory */ 995 953 fxn_brd_memwrite pfn_brd_mem_write; /* Write DSP Memory w/o halt */ 954 + fxn_brd_memmap pfn_brd_mem_map; /* Maps MPU mem to DSP mem */ 955 + fxn_brd_memunmap pfn_brd_mem_un_map; /* Unmaps MPU mem to DSP mem */ 996 956 fxn_chnl_create pfn_chnl_create; /* Create channel manager. */ 997 957 fxn_chnl_destroy pfn_chnl_destroy; /* Destroy channel manager. */ 998 958 fxn_chnl_open pfn_chnl_open; /* Create a new channel. */
+2
drivers/staging/tidspbridge/pmgr/dev.c
··· 1118 1118 STORE_FXN(fxn_brd_setstate, pfn_brd_set_state); 1119 1119 STORE_FXN(fxn_brd_memcopy, pfn_brd_mem_copy); 1120 1120 STORE_FXN(fxn_brd_memwrite, pfn_brd_mem_write); 1121 + STORE_FXN(fxn_brd_memmap, pfn_brd_mem_map); 1122 + STORE_FXN(fxn_brd_memunmap, pfn_brd_mem_un_map); 1121 1123 STORE_FXN(fxn_chnl_create, pfn_chnl_create); 1122 1124 STORE_FXN(fxn_chnl_destroy, pfn_chnl_destroy); 1123 1125 STORE_FXN(fxn_chnl_open, pfn_chnl_open);
+16 -18
drivers/staging/tidspbridge/rmgr/proc.c
··· 52 52 #include <dspbridge/msg.h> 53 53 #include <dspbridge/dspioctl.h> 54 54 #include <dspbridge/drv.h> 55 - #include <_tiomap.h> 56 55 57 56 /* ----------------------------------- This */ 58 57 #include <dspbridge/proc.h> ··· 1357 1358 int status = 0; 1358 1359 struct proc_object *p_proc_object = (struct proc_object *)hprocessor; 1359 1360 struct dmm_map_object *map_obj; 1361 + u32 tmp_addr = 0; 1360 1362 1361 1363 #ifdef CONFIG_TIDSPBRIDGE_CACHE_LINE_CHECK 1362 1364 if ((ul_map_attr & BUFMODE_MASK) != RBUF) { ··· 1390 1390 1391 1391 /* Add mapping to the page tables. */ 1392 1392 if (!status) { 1393 + 1394 + /* Mapped address = MSB of VA | LSB of PA */ 1395 + tmp_addr = (va_align | ((u32) pmpu_addr & (PG_SIZE4K - 1))); 1393 1396 /* mapped memory resource tracking */ 1394 - map_obj = add_mapping_info(pr_ctxt, pa_align, va_align, 1397 + map_obj = add_mapping_info(pr_ctxt, pa_align, tmp_addr, 1395 1398 size_align); 1396 - if (!map_obj) { 1399 + if (!map_obj) 1397 1400 status = -ENOMEM; 1398 - } else { 1399 - va_align = user_to_dsp_map( 1400 - p_proc_object->hbridge_context->dsp_mmu, 1401 - pa_align, va_align, size_align, 1402 - map_obj->pages); 1403 - if (IS_ERR_VALUE(va_align)) 1404 - status = (int)va_align; 1405 - } 1401 + else 1402 + status = (*p_proc_object->intf_fxns->pfn_brd_mem_map) 1403 + (p_proc_object->hbridge_context, pa_align, va_align, 1404 + size_align, ul_map_attr, map_obj->pages); 1406 1405 } 1407 1406 if (!status) { 1408 1407 /* Mapped address = MSB of VA | LSB of PA */ 1409 - map_obj->dsp_addr = (va_align | 1410 - ((u32)pmpu_addr & (PG_SIZE4K - 1))); 1411 - *pp_map_addr = (void *)map_obj->dsp_addr; 1408 + *pp_map_addr = (void *) tmp_addr; 1412 1409 } else { 1413 - remove_mapping_information(pr_ctxt, va_align, size_align); 1410 + remove_mapping_information(pr_ctxt, tmp_addr, size_align); 1414 1411 dmm_un_map_memory(dmm_mgr, va_align, &size_align); 1415 1412 } 1416 1413 mutex_unlock(&proc_lock); ··· 1721 1724 */ 1722 1725 status = dmm_un_map_memory(dmm_mgr, (u32) va_align, &size_align); 1723 1726 /* Remove mapping from the page tables. */ 1724 - if (!status) 1725 - status = user_to_dsp_unmap( 1726 - p_proc_object->hbridge_context->dsp_mmu, va_align); 1727 + if (!status) { 1728 + status = (*p_proc_object->intf_fxns->pfn_brd_mem_un_map) 1729 + (p_proc_object->hbridge_context, va_align); 1730 + } 1727 1731 1728 1732 mutex_unlock(&proc_lock); 1729 1733 if (status)