1 /**************************************************************************
3 * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <dev/drm2/drmP.h>
36 #include <dev/drm2/ttm/ttm_module.h>
37 #include <dev/drm2/ttm/ttm_bo_driver.h>
38 #include <dev/drm2/ttm/ttm_page_alloc.h>
40 #include <dev/drm2/ttm/ttm_placement.h>
42 struct ttm_agp_backend {
49 MALLOC_DEFINE(M_TTM_AGP, "ttm_agp", "TTM AGP Backend");
51 static int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
53 struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
54 struct drm_mm_node *node = bo_mem->mm_node;
58 for (i = 0; i < ttm->num_pages; i++) {
59 vm_page_t page = ttm->pages[i];
62 page = ttm->dummy_read_page;
64 agp_be->pages[i] = page;
67 agp_be->offset = node->start * PAGE_SIZE;
68 ret = -agp_bind_pages(agp_be->bridge, agp_be->pages,
69 ttm->num_pages << PAGE_SHIFT, agp_be->offset);
71 printf("[TTM] AGP Bind memory failed\n");
76 static int ttm_agp_unbind(struct ttm_tt *ttm)
78 struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
80 return -agp_unbind_pages(agp_be->bridge, ttm->num_pages << PAGE_SHIFT,
84 static void ttm_agp_destroy(struct ttm_tt *ttm)
86 struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
89 free(agp_be->pages, M_TTM_AGP);
90 free(agp_be, M_TTM_AGP);
93 static struct ttm_backend_func ttm_agp_func = {
95 .unbind = ttm_agp_unbind,
96 .destroy = ttm_agp_destroy,
99 struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,
101 unsigned long size, uint32_t page_flags,
102 vm_page_t dummy_read_page)
104 struct ttm_agp_backend *agp_be;
106 agp_be = malloc(sizeof(*agp_be), M_TTM_AGP, M_WAITOK | M_ZERO);
108 agp_be->bridge = bridge;
109 agp_be->ttm.func = &ttm_agp_func;
111 if (ttm_tt_init(&agp_be->ttm, bdev, size, page_flags, dummy_read_page)) {
112 free(agp_be, M_TTM_AGP);
117 agp_be->pages = malloc(agp_be->ttm.num_pages * sizeof(*agp_be->pages),
118 M_TTM_AGP, M_WAITOK);
123 int ttm_agp_tt_populate(struct ttm_tt *ttm)
125 if (ttm->state != tt_unpopulated)
128 return ttm_pool_populate(ttm);
131 void ttm_agp_tt_unpopulate(struct ttm_tt *ttm)
133 ttm_pool_unpopulate(ttm);