Lines Matching +full:upper +full:- +full:cal
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
153 gatt->ag_entries = entries; in agp_alloc_gatt()
154 gatt->ag_virtual = kmem_alloc_contig(entries * sizeof(uint32_t), in agp_alloc_gatt()
156 if (!gatt->ag_virtual) { in agp_alloc_gatt()
162 gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual); in agp_alloc_gatt()
170 kmem_free(gatt->ag_virtual, gatt->ag_entries * sizeof(uint32_t)); in agp_free_gatt()
198 sc->as_aperture_rid = rid; in agp_set_aperture_resource()
214 if (sc->as_aperture_rid != -1) { in agp_generic_attach()
215 if (sc->as_aperture_rid == 0) in agp_generic_attach()
216 sc->as_aperture_rid = AGP_APBASE; in agp_generic_attach()
218 sc->as_aperture = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in agp_generic_attach()
219 &sc->as_aperture_rid, RF_SHAREABLE); in agp_generic_attach()
220 if (!sc->as_aperture) in agp_generic_attach()
225 * Work out an upper bound for agp memory allocation. This in agp_generic_attach()
234 i = AGP_MAX_SIZE - 1; in agp_generic_attach()
235 sc->as_maxmem = agp_max[i][1] << 20U; in agp_generic_attach()
238 * The lock is used to prevent re-entry to in agp_generic_attach()
241 mtx_init(&sc->as_lock, "agp lock", NULL, MTX_DEF); in agp_generic_attach()
247 TAILQ_INIT(&sc->as_memory); in agp_generic_attach()
248 sc->as_nextid = 1; in agp_generic_attach()
250 sc->as_devalias = NULL; in agp_generic_attach()
261 error = make_dev_s(&mdargs, &sc->as_devnode, "agpgart%d", unit); in agp_generic_attach()
268 &sc->as_devalias, sc->as_devnode, "agpgart"); in agp_generic_attach()
282 destroy_dev(sc->as_devnode); in agp_free_cdev()
283 if (sc->as_devalias != NULL) in agp_free_cdev()
284 destroy_dev(sc->as_devalias); in agp_free_cdev()
292 if (sc->as_aperture != NULL) in agp_free_res()
293 bus_release_resource(dev, SYS_RES_MEMORY, sc->as_aperture_rid, in agp_free_res()
294 sc->as_aperture); in agp_free_res()
295 mtx_destroy(&sc->as_lock); in agp_free_res()
316 return rman_get_size(sc->as_aperture); in agp_generic_get_aperture()
337 * restrictions as in place for v2 -- one bus, one device on the bus.
344 int rq, sba, fw, rate, arqsz, cal; in agp_v3_enable() local
357 * ARQSZ - Set the value to the maximum one. in agp_v3_enable()
366 /* Calibration cycle - don't allow override by mode register */ in agp_v3_enable()
367 cal = AGP_MODE_GET_CAL(tstatus); in agp_v3_enable()
368 if (AGP_MODE_GET_CAL(mstatus) < cal) in agp_v3_enable()
369 cal = AGP_MODE_GET_CAL(mstatus); in agp_v3_enable()
396 command = AGP_MODE_SET_CAL(command, cal); in agp_v3_enable()
497 if ((size & (AGP_PAGE_SIZE - 1)) != 0) in agp_generic_alloc_memory()
500 if (size > sc->as_maxmem - sc->as_allocated) in agp_generic_alloc_memory()
510 mem->am_id = sc->as_nextid++; in agp_generic_alloc_memory()
511 mem->am_size = size; in agp_generic_alloc_memory()
512 mem->am_type = 0; in agp_generic_alloc_memory()
513 mem->am_obj = vm_object_allocate(OBJT_SWAP, atop(round_page(size))); in agp_generic_alloc_memory()
514 mem->am_physical = 0; in agp_generic_alloc_memory()
515 mem->am_offset = 0; in agp_generic_alloc_memory()
516 mem->am_is_bound = 0; in agp_generic_alloc_memory()
517 TAILQ_INSERT_TAIL(&sc->as_memory, mem, am_link); in agp_generic_alloc_memory()
518 sc->as_allocated += size; in agp_generic_alloc_memory()
528 if (mem->am_is_bound) in agp_generic_free_memory()
531 sc->as_allocated -= mem->am_size; in agp_generic_free_memory()
532 TAILQ_REMOVE(&sc->as_memory, mem, am_link); in agp_generic_free_memory()
533 vm_object_deallocate(mem->am_obj); in agp_generic_free_memory()
548 if ((offset & (AGP_PAGE_SIZE - 1)) != 0 || in agp_generic_bind_memory()
549 offset + mem->am_size > AGP_GET_APERTURE(dev)) { in agp_generic_bind_memory()
560 VM_OBJECT_WLOCK(mem->am_obj); in agp_generic_bind_memory()
561 for (i = 0; i < mem->am_size; i += PAGE_SIZE) { in agp_generic_bind_memory()
569 m = vm_page_grab(mem->am_obj, OFF_TO_IDX(i), in agp_generic_bind_memory()
573 VM_OBJECT_WUNLOCK(mem->am_obj); in agp_generic_bind_memory()
575 mtx_lock(&sc->as_lock); in agp_generic_bind_memory()
577 if (mem->am_is_bound) { in agp_generic_bind_memory()
580 VM_OBJECT_WLOCK(mem->am_obj); in agp_generic_bind_memory()
589 VM_OBJECT_WLOCK(mem->am_obj); in agp_generic_bind_memory()
590 for (i = 0; i < mem->am_size; i += PAGE_SIZE) { in agp_generic_bind_memory()
591 m = vm_page_lookup(mem->am_obj, OFF_TO_IDX(i)); in agp_generic_bind_memory()
595 * AGP_PAGE_SIZE < PAGE_SIZE and mem->am_size is not in agp_generic_bind_memory()
599 for (j = 0; j < PAGE_SIZE && i + j < mem->am_size; in agp_generic_bind_memory()
617 VM_OBJECT_WUNLOCK(mem->am_obj); in agp_generic_bind_memory()
624 mem->am_offset = offset; in agp_generic_bind_memory()
625 mem->am_is_bound = 1; in agp_generic_bind_memory()
627 mtx_unlock(&sc->as_lock); in agp_generic_bind_memory()
631 mtx_unlock(&sc->as_lock); in agp_generic_bind_memory()
632 VM_OBJECT_ASSERT_WLOCKED(mem->am_obj); in agp_generic_bind_memory()
633 for (k = 0; k < mem->am_size; k += PAGE_SIZE) { in agp_generic_bind_memory()
634 m = vm_page_lookup(mem->am_obj, OFF_TO_IDX(k)); in agp_generic_bind_memory()
639 VM_OBJECT_WUNLOCK(mem->am_obj); in agp_generic_bind_memory()
651 mtx_lock(&sc->as_lock); in agp_generic_unbind_memory()
653 if (!mem->am_is_bound) { in agp_generic_unbind_memory()
655 mtx_unlock(&sc->as_lock); in agp_generic_unbind_memory()
663 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) in agp_generic_unbind_memory()
664 AGP_UNBIND_PAGE(dev, mem->am_offset + i); in agp_generic_unbind_memory()
668 VM_OBJECT_WLOCK(mem->am_obj); in agp_generic_unbind_memory()
669 for (i = 0; i < mem->am_size; i += PAGE_SIZE) { in agp_generic_unbind_memory()
670 m = vm_page_lookup(mem->am_obj, atop(i)); in agp_generic_unbind_memory()
673 VM_OBJECT_WUNLOCK(mem->am_obj); in agp_generic_unbind_memory()
675 mem->am_offset = 0; in agp_generic_unbind_memory()
676 mem->am_is_bound = 0; in agp_generic_unbind_memory()
678 mtx_unlock(&sc->as_lock); in agp_generic_unbind_memory()
690 if (sc->as_state != AGP_ACQUIRE_FREE) in agp_acquire_helper()
692 sc->as_state = state; in agp_acquire_helper()
702 if (sc->as_state == AGP_ACQUIRE_FREE) in agp_release_helper()
705 if (sc->as_state != state) in agp_release_helper()
708 sc->as_state = AGP_ACQUIRE_FREE; in agp_release_helper()
719 TAILQ_FOREACH(mem, &sc->as_memory, am_link) { in agp_find_memory()
720 AGP_DPF("considering memory block %d\n", mem->am_id); in agp_find_memory()
721 if (mem->am_id == id) in agp_find_memory()
735 info->bridge_id = pci_get_devid(dev); in agp_info_user()
736 info->agp_mode = in agp_info_user()
738 if (sc->as_aperture) in agp_info_user()
739 info->aper_base = rman_get_start(sc->as_aperture); in agp_info_user()
741 info->aper_base = 0; in agp_info_user()
742 info->aper_size = AGP_GET_APERTURE(dev) >> 20; in agp_info_user()
743 info->pg_total = info->pg_system = sc->as_maxmem >> AGP_PAGE_SHIFT; in agp_info_user()
744 info->pg_used = sc->as_allocated >> AGP_PAGE_SHIFT; in agp_info_user()
752 return AGP_ENABLE(dev, setup->agp_mode); in agp_setup_user()
761 alloc->type, in agp_allocate_user()
762 alloc->pg_count << AGP_PAGE_SHIFT); in agp_allocate_user()
764 alloc->key = mem->am_id; in agp_allocate_user()
765 alloc->physical = mem->am_physical; in agp_allocate_user()
788 struct agp_memory *mem = agp_find_memory(dev, bind->key); in agp_bind_user()
793 return AGP_BIND_MEMORY(dev, mem, bind->pg_start << AGP_PAGE_SHIFT); in agp_bind_user()
799 struct agp_memory *mem = agp_find_memory(dev, unbind->key); in agp_unbind_user()
817 device_t dev = kdev->si_drv1; in agp_open()
820 if (!sc->as_isopen) { in agp_open()
821 sc->as_isopen = 1; in agp_open()
831 device_t dev = kdev->si_drv1; in agp_close()
838 while ((mem = TAILQ_FIRST(&sc->as_memory)) != NULL) { in agp_close()
839 if (mem->am_is_bound) in agp_close()
843 if (sc->as_state == AGP_ACQUIRE_USER) in agp_close()
845 sc->as_isopen = 0; in agp_close()
854 device_t dev = kdev->si_drv1; in agp_ioctl()
892 device_t dev = kdev->si_drv1; in agp_mmap()
896 return -1; in agp_mmap()
897 if (sc->as_aperture == NULL) in agp_mmap()
898 return -1; in agp_mmap()
899 *paddr = rman_get_start(sc->as_aperture) + offset; in agp_mmap()
930 return sc->as_state; in agp_state()
938 info->ai_mode = in agp_get_info()
940 if (sc->as_aperture != NULL) in agp_get_info()
941 info->ai_aperture_base = rman_get_start(sc->as_aperture); in agp_get_info()
943 info->ai_aperture_base = 0; in agp_get_info()
944 info->ai_aperture_size = AGP_GET_APERTURE(dev); in agp_get_info()
945 info->ai_memory_allowed = sc->as_maxmem; in agp_get_info()
946 info->ai_memory_used = sc->as_allocated; in agp_get_info()
995 mi->ami_size = mem->am_size; in agp_memory_info()
996 mi->ami_physical = mem->am_physical; in agp_memory_info()
997 mi->ami_offset = mem->am_offset; in agp_memory_info()
998 mi->ami_is_bound = mem->am_is_bound; in agp_memory_info()
1010 if ((size & (AGP_PAGE_SIZE - 1)) != 0 || in agp_bind_pages()
1011 (offset & (AGP_PAGE_SIZE - 1)) != 0) in agp_bind_pages()
1016 mtx_lock(&sc->as_lock); in agp_bind_pages()
1040 mtx_unlock(&sc->as_lock); in agp_bind_pages()
1048 mtx_unlock(&sc->as_lock); in agp_bind_pages()
1058 if ((size & (AGP_PAGE_SIZE - 1)) != 0 || in agp_unbind_pages()
1059 (offset & (AGP_PAGE_SIZE - 1)) != 0) in agp_unbind_pages()
1064 mtx_lock(&sc->as_lock); in agp_unbind_pages()
1070 mtx_unlock(&sc->as_lock); in agp_unbind_pages()