xref: /openbsd/sys/dev/pci/drm/ttm/ttm_agp_backend.c (revision 1bb76ff1)
17f4dd379Sjsg /* SPDX-License-Identifier: GPL-2.0 OR MIT */
21099013bSjsg /**************************************************************************
31099013bSjsg  *
41099013bSjsg  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
51099013bSjsg  * All Rights Reserved.
61099013bSjsg  *
71099013bSjsg  * Permission is hereby granted, free of charge, to any person obtaining a
81099013bSjsg  * copy of this software and associated documentation files (the
91099013bSjsg  * "Software"), to deal in the Software without restriction, including
101099013bSjsg  * without limitation the rights to use, copy, modify, merge, publish,
111099013bSjsg  * distribute, sub license, and/or sell copies of the Software, and to
121099013bSjsg  * permit persons to whom the Software is furnished to do so, subject to
131099013bSjsg  * the following conditions:
141099013bSjsg  *
151099013bSjsg  * The above copyright notice and this permission notice (including the
161099013bSjsg  * next paragraph) shall be included in all copies or substantial portions
171099013bSjsg  * of the Software.
181099013bSjsg  *
191099013bSjsg  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
201099013bSjsg  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
211099013bSjsg  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
221099013bSjsg  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
231099013bSjsg  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
241099013bSjsg  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
251099013bSjsg  * USE OR OTHER DEALINGS IN THE SOFTWARE.
261099013bSjsg  *
271099013bSjsg  **************************************************************************/
281099013bSjsg /*
291099013bSjsg  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
301099013bSjsg  *          Keith Packard.
311099013bSjsg  */
321099013bSjsg 
331099013bSjsg #define pr_fmt(fmt) "[TTM] " fmt
341099013bSjsg 
355ca02815Sjsg #include <drm/ttm/ttm_device.h>
365ca02815Sjsg #include <drm/ttm/ttm_tt.h>
375ca02815Sjsg #include <drm/ttm/ttm_resource.h>
387f4dd379Sjsg #include <linux/agp_backend.h>
397f4dd379Sjsg #include <linux/module.h>
407f4dd379Sjsg #include <linux/slab.h>
417f4dd379Sjsg #include <linux/io.h>
427f4dd379Sjsg #include <asm/agp.h>
431099013bSjsg 
441099013bSjsg struct ttm_agp_backend {
451099013bSjsg 	struct ttm_tt ttm;
465ca02815Sjsg 	struct agp_memory *mem;
475ca02815Sjsg 	struct agp_bridge_data *bridge;
481099013bSjsg };
491099013bSjsg 
ttm_agp_bind(struct ttm_tt * ttm,struct ttm_resource * bo_mem)50ad8b1aafSjsg int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem)
511099013bSjsg {
525ca02815Sjsg 	STUB();
535ca02815Sjsg 	return -ENOSYS;
545ca02815Sjsg #ifdef notyet
551099013bSjsg 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
565ca02815Sjsg 	struct vm_page *dummy_read_page = ttm_glob.dummy_read_page;
575ca02815Sjsg 	struct agp_memory *mem;
585ca02815Sjsg 	int ret, cached = ttm->caching == ttm_cached;
591099013bSjsg 	unsigned i;
601099013bSjsg 
61ad8b1aafSjsg 	if (agp_be->mem)
62ad8b1aafSjsg 		return 0;
63ad8b1aafSjsg 
645ca02815Sjsg 	mem = agp_allocate_memory(agp_be->bridge, ttm->num_pages, AGP_USER_MEMORY);
655ca02815Sjsg 	if (unlikely(mem == NULL))
665ca02815Sjsg 		return -ENOMEM;
675ca02815Sjsg 
685ca02815Sjsg 	mem->page_count = 0;
691099013bSjsg 	for (i = 0; i < ttm->num_pages; i++) {
701099013bSjsg 		struct vm_page *page = ttm->pages[i];
711099013bSjsg 
721099013bSjsg 		if (!page)
737f4dd379Sjsg 			page = dummy_read_page;
741099013bSjsg 
755ca02815Sjsg 		mem->pages[mem->page_count++] = page;
761099013bSjsg 	}
775ca02815Sjsg 	agp_be->mem = mem;
781099013bSjsg 
795ca02815Sjsg 	mem->is_flushed = 1;
805ca02815Sjsg 	mem->type = (cached) ? AGP_USER_CACHED_MEMORY : AGP_USER_MEMORY;
815ca02815Sjsg 
825ca02815Sjsg 	ret = agp_bind_memory(mem, bo_mem->start);
835ca02815Sjsg 	if (ret)
845ca02815Sjsg 		pr_err("AGP Bind memory failed\n");
855ca02815Sjsg 
865ca02815Sjsg 	return ret;
875ca02815Sjsg #endif
881099013bSjsg }
89ad8b1aafSjsg EXPORT_SYMBOL(ttm_agp_bind);
901099013bSjsg 
ttm_agp_unbind(struct ttm_tt * ttm)91ad8b1aafSjsg void ttm_agp_unbind(struct ttm_tt *ttm)
921099013bSjsg {
935ca02815Sjsg 	STUB();
945ca02815Sjsg #ifdef notyet
951099013bSjsg 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
961099013bSjsg 
975ca02815Sjsg 	if (agp_be->mem) {
985ca02815Sjsg 		if (agp_be->mem->is_bound) {
995ca02815Sjsg 			agp_unbind_memory(agp_be->mem);
1005ca02815Sjsg 			return;
1011099013bSjsg 		}
1025ca02815Sjsg 		agp_free_memory(agp_be->mem);
1035ca02815Sjsg 		agp_be->mem = NULL;
1041099013bSjsg 	}
1055ca02815Sjsg #endif
1061099013bSjsg }
107ad8b1aafSjsg EXPORT_SYMBOL(ttm_agp_unbind);
1081099013bSjsg 
ttm_agp_is_bound(struct ttm_tt * ttm)109ad8b1aafSjsg bool ttm_agp_is_bound(struct ttm_tt *ttm)
110ad8b1aafSjsg {
1115ca02815Sjsg 	STUB();
1125ca02815Sjsg 	return false;
1135ca02815Sjsg #ifdef notyet
114ad8b1aafSjsg 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
115ad8b1aafSjsg 
116ad8b1aafSjsg 	if (!ttm)
117ad8b1aafSjsg 		return false;
118ad8b1aafSjsg 
119ad8b1aafSjsg 	return (agp_be->bound == 1);
1205ca02815Sjsg #endif
121ad8b1aafSjsg }
122ad8b1aafSjsg EXPORT_SYMBOL(ttm_agp_is_bound);
123ad8b1aafSjsg 
ttm_agp_destroy(struct ttm_tt * ttm)124ad8b1aafSjsg void ttm_agp_destroy(struct ttm_tt *ttm)
1251099013bSjsg {
1265ca02815Sjsg 	STUB();
1275ca02815Sjsg #ifdef notyet
1281099013bSjsg 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
1291099013bSjsg 
1301099013bSjsg 	if (agp_be->bound)
1311099013bSjsg 		ttm_agp_unbind(ttm);
1321099013bSjsg 	ttm_tt_fini(ttm);
133c547faa2Sjsg 	kfree(agp_be);
1345ca02815Sjsg #endif
1351099013bSjsg }
136ad8b1aafSjsg EXPORT_SYMBOL(ttm_agp_destroy);
1371099013bSjsg 
ttm_agp_tt_create(struct ttm_buffer_object * bo,struct agp_bridge_data * bridge,uint32_t page_flags)1387f4dd379Sjsg struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
1395ca02815Sjsg 				 struct agp_bridge_data *bridge,
1407f4dd379Sjsg 				 uint32_t page_flags)
1411099013bSjsg {
1421099013bSjsg 	struct ttm_agp_backend *agp_be;
1431099013bSjsg 
144c547faa2Sjsg 	agp_be = kmalloc(sizeof(*agp_be), GFP_KERNEL);
1451099013bSjsg 	if (!agp_be)
1461099013bSjsg 		return NULL;
1471099013bSjsg 
1485ca02815Sjsg 	agp_be->mem = NULL;
1495ca02815Sjsg 	agp_be->bridge = bridge;
1501099013bSjsg 
151*1bb76ff1Sjsg 	if (ttm_tt_init(&agp_be->ttm, bo, page_flags, ttm_write_combined, 0)) {
1525ca02815Sjsg 		kfree(agp_be);
1531099013bSjsg 		return NULL;
1541099013bSjsg 	}
1551099013bSjsg 
1561099013bSjsg 	return &agp_be->ttm;
1571099013bSjsg }
1581099013bSjsg EXPORT_SYMBOL(ttm_agp_tt_create);
159