Lines Matching refs:md

57 	struct proto_md *md;  member
145 struct proto_md *md) in proto_busdma_md_destroy_internal() argument
148 LIST_REMOVE(md, mds); in proto_busdma_md_destroy_internal()
149 LIST_REMOVE(md, peers); in proto_busdma_md_destroy_internal()
150 if (md->physaddr) in proto_busdma_md_destroy_internal()
151 bus_dmamap_unload(md->bd_tag, md->bd_map); in proto_busdma_md_destroy_internal()
152 if (md->virtaddr != NULL) in proto_busdma_md_destroy_internal()
153 bus_dmamem_free(md->bd_tag, md->virtaddr, md->bd_map); in proto_busdma_md_destroy_internal()
155 bus_dmamap_destroy(md->bd_tag, md->bd_map); in proto_busdma_md_destroy_internal()
156 bus_dma_tag_destroy(md->bd_tag); in proto_busdma_md_destroy_internal()
157 free(md, M_PROTO_BUSDMA); in proto_busdma_md_destroy_internal()
167 pcb->ioc->u.md.bus_nsegs = nseg; in proto_busdma_mem_alloc_callback()
168 pcb->ioc->u.md.bus_addr = segs[0].ds_addr; in proto_busdma_mem_alloc_callback()
176 struct proto_md *md; in proto_busdma_mem_alloc() local
179 md = malloc(sizeof(*md), M_PROTO_BUSDMA, M_WAITOK | M_ZERO); in proto_busdma_mem_alloc()
180 md->tag = tag; in proto_busdma_mem_alloc()
184 tag->nsegs, tag->maxsegsz, 0, NULL, NULL, &md->bd_tag); in proto_busdma_mem_alloc()
186 free(md, M_PROTO_BUSDMA); in proto_busdma_mem_alloc()
189 error = bus_dmamem_alloc(md->bd_tag, &md->virtaddr, 0, &md->bd_map); in proto_busdma_mem_alloc()
191 bus_dma_tag_destroy(md->bd_tag); in proto_busdma_mem_alloc()
192 free(md, M_PROTO_BUSDMA); in proto_busdma_mem_alloc()
195 md->physaddr = pmap_kextract((uintptr_t)(md->virtaddr)); in proto_busdma_mem_alloc()
197 pcb.md = md; in proto_busdma_mem_alloc()
199 error = bus_dmamap_load(md->bd_tag, md->bd_map, md->virtaddr, in proto_busdma_mem_alloc()
202 bus_dmamem_free(md->bd_tag, md->virtaddr, md->bd_map); in proto_busdma_mem_alloc()
203 bus_dma_tag_destroy(md->bd_tag); in proto_busdma_mem_alloc()
204 free(md, M_PROTO_BUSDMA); in proto_busdma_mem_alloc()
207 LIST_INSERT_HEAD(&tag->mds, md, peers); in proto_busdma_mem_alloc()
208 LIST_INSERT_HEAD(&busdma->mds, md, mds); in proto_busdma_mem_alloc()
209 ioc->u.md.virt_addr = (uintptr_t)md->virtaddr; in proto_busdma_mem_alloc()
210 ioc->u.md.virt_size = tag->maxsz; in proto_busdma_mem_alloc()
211 ioc->u.md.phys_nsegs = 1; in proto_busdma_mem_alloc()
212 ioc->u.md.phys_addr = md->physaddr; in proto_busdma_mem_alloc()
213 ioc->result = (uintptr_t)(void *)md; in proto_busdma_mem_alloc()
218 proto_busdma_mem_free(struct proto_busdma *busdma, struct proto_md *md) in proto_busdma_mem_free() argument
221 if (md->virtaddr == NULL) in proto_busdma_mem_free()
223 return (proto_busdma_md_destroy_internal(busdma, md)); in proto_busdma_mem_free()
230 struct proto_md *md; in proto_busdma_md_create() local
233 md = malloc(sizeof(*md), M_PROTO_BUSDMA, M_WAITOK | M_ZERO); in proto_busdma_md_create()
234 md->tag = tag; in proto_busdma_md_create()
238 tag->nsegs, tag->maxsegsz, 0, NULL, NULL, &md->bd_tag); in proto_busdma_md_create()
240 free(md, M_PROTO_BUSDMA); in proto_busdma_md_create()
243 error = bus_dmamap_create(md->bd_tag, 0, &md->bd_map); in proto_busdma_md_create()
245 bus_dma_tag_destroy(md->bd_tag); in proto_busdma_md_create()
246 free(md, M_PROTO_BUSDMA); in proto_busdma_md_create()
250 LIST_INSERT_HEAD(&tag->mds, md, peers); in proto_busdma_md_create()
251 LIST_INSERT_HEAD(&busdma->mds, md, mds); in proto_busdma_md_create()
252 ioc->result = (uintptr_t)(void *)md; in proto_busdma_md_create()
257 proto_busdma_md_destroy(struct proto_busdma *busdma, struct proto_md *md) in proto_busdma_md_destroy() argument
260 if (md->virtaddr != NULL) in proto_busdma_md_destroy()
262 return (proto_busdma_md_destroy_internal(busdma, md)); in proto_busdma_md_destroy()
271 pcb->ioc->u.md.bus_nsegs = nseg; in proto_busdma_md_load_callback()
272 pcb->ioc->u.md.bus_addr = segs[0].ds_addr; in proto_busdma_md_load_callback()
276 proto_busdma_md_load(struct proto_busdma *busdma, struct proto_md *md, in proto_busdma_md_load() argument
285 iov.iov_base = (void *)(uintptr_t)ioc->u.md.virt_addr; in proto_busdma_md_load()
286 iov.iov_len = ioc->u.md.virt_size; in proto_busdma_md_load()
296 pcb.md = md; in proto_busdma_md_load()
298 error = bus_dmamap_load_uio(md->bd_tag, md->bd_map, &uio, in proto_busdma_md_load()
305 md->physaddr = pmap_extract(pmap, ioc->u.md.virt_addr); in proto_busdma_md_load()
306 ioc->u.md.phys_nsegs = 1; /* XXX */ in proto_busdma_md_load()
307 ioc->u.md.phys_addr = md->physaddr; in proto_busdma_md_load()
312 proto_busdma_md_unload(struct proto_busdma *busdma, struct proto_md *md) in proto_busdma_md_unload() argument
315 if (!md->physaddr) in proto_busdma_md_unload()
317 bus_dmamap_unload(md->bd_tag, md->bd_map); in proto_busdma_md_unload()
318 md->physaddr = 0; in proto_busdma_md_unload()
323 proto_busdma_sync(struct proto_busdma *busdma, struct proto_md *md, in proto_busdma_sync() argument
332 if (!md->physaddr) in proto_busdma_sync()
334 bus_dmamap_sync(md->bd_tag, md->bd_map, ioc->u.sync.op); in proto_busdma_sync()
341 struct proto_md *md; in proto_busdma_md_lookup() local
343 LIST_FOREACH(md, &busdma->mds, mds) { in proto_busdma_md_lookup()
344 if ((void *)md == (void *)key) in proto_busdma_md_lookup()
345 return (md); in proto_busdma_md_lookup()
373 struct proto_md *md, *md1; in proto_busdma_cleanup() local
377 LIST_FOREACH_SAFE(md, &busdma->mds, mds, md1) in proto_busdma_cleanup()
378 proto_busdma_md_destroy_internal(busdma, md); in proto_busdma_cleanup()
390 struct proto_md *md; in proto_busdma_ioctl() local
418 tag = proto_busdma_tag_lookup(busdma, ioc->u.md.tag); in proto_busdma_ioctl()
426 md = proto_busdma_md_lookup(busdma, ioc->key); in proto_busdma_ioctl()
427 if (md == NULL) { in proto_busdma_ioctl()
431 error = proto_busdma_mem_free(busdma, md); in proto_busdma_ioctl()
434 tag = proto_busdma_tag_lookup(busdma, ioc->u.md.tag); in proto_busdma_ioctl()
442 md = proto_busdma_md_lookup(busdma, ioc->key); in proto_busdma_ioctl()
443 if (md == NULL) { in proto_busdma_ioctl()
447 error = proto_busdma_md_destroy(busdma, md); in proto_busdma_ioctl()
450 md = proto_busdma_md_lookup(busdma, ioc->key); in proto_busdma_ioctl()
451 if (md == NULL) { in proto_busdma_ioctl()
455 error = proto_busdma_md_load(busdma, md, ioc, td); in proto_busdma_ioctl()
458 md = proto_busdma_md_lookup(busdma, ioc->key); in proto_busdma_ioctl()
459 if (md == NULL) { in proto_busdma_ioctl()
463 error = proto_busdma_md_unload(busdma, md); in proto_busdma_ioctl()
466 md = proto_busdma_md_lookup(busdma, ioc->key); in proto_busdma_ioctl()
467 if (md == NULL) { in proto_busdma_ioctl()
471 error = proto_busdma_sync(busdma, md, ioc); in proto_busdma_ioctl()
486 struct proto_md *md; in proto_busdma_mmap_allowed() local
492 LIST_FOREACH(md, &busdma->mds, mds) { in proto_busdma_mmap_allowed()
493 if (physaddr >= trunc_page(md->physaddr) && in proto_busdma_mmap_allowed()
494 physaddr <= trunc_page(md->physaddr + md->tag->maxsz)) { in proto_busdma_mmap_allowed()