/* * Copyright (C) 2007 Arthur Huillet. * * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial * portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ /* * Authors: * Arthur Huillet */ #include "drmP.h" #include "drm.h" #include "nouveau_drm.h" #include "nouveau_drv.h" #include "nouveau_reg.h" /*TODO: add a "card_type" attribute*/ typedef struct{ uint32_t oclass; /* object class for this software method */ uint32_t mthd; /* method number */ void (*method_code)(struct drm_device *dev, uint32_t oclass, uint32_t mthd); /* pointer to the function that does the work */ } nouveau_software_method_t; /* This function handles the NV04 setcontext software methods. One function for all because they are very similar.*/ static void nouveau_NV04_setcontext_sw_method(struct drm_device *dev, uint32_t oclass, uint32_t mthd) { struct drm_nouveau_private *dev_priv = dev->dev_private; uint32_t inst_loc = NV_READ(NV04_PGRAPH_CTX_SWITCH4) & 0xFFFF; uint32_t value_to_set = 0, bit_to_set = 0; switch ( oclass ) { case 0x4a: switch ( mthd ) { case 0x188 : case 0x18c : bit_to_set = 0; break; case 0x198 : bit_to_set = 1 << 24; /*PATCH_STATUS_VALID*/ break; case 0x2fc : bit_to_set = NV_READ(NV04_PGRAPH_TRAPPED_DATA) << 15; /*PATCH_CONFIG = NV04_PGRAPH_TRAPPED_DATA*/ break; default : ; }; break; case 0x5c: switch ( mthd ) { case 0x184: bit_to_set = 1 << 13; /*USER_CLIP_ENABLE*/ break; case 0x188: case 0x18c: bit_to_set = 0; break; case 0x198: bit_to_set = 1 << 24; /*PATCH_STATUS_VALID*/ break; case 0x2fc : bit_to_set = NV_READ(NV04_PGRAPH_TRAPPED_DATA) << 15; /*PATCH_CONFIG = NV04_PGRAPH_TRAPPED_DATA*/ break; }; break; case 0x5f: switch ( mthd ) { case 0x184 : bit_to_set = 1 << 12; /*CHROMA_KEY_ENABLE*/ break; case 0x188 : bit_to_set = 1 << 13; /*USER_CLIP_ENABLE*/ break; case 0x18c : case 0x190 : bit_to_set = 0; break; case 0x19c : bit_to_set = 1 << 24; /*PATCH_STATUS_VALID*/ break; case 0x2fc : bit_to_set = NV_READ(NV04_PGRAPH_TRAPPED_DATA) << 15; /*PATCH_CONFIG = NV04_PGRAPH_TRAPPED_DATA*/ break; }; break; case 0x61: switch ( mthd ) { case 0x188 : bit_to_set = 1 << 13; /*USER_CLIP_ENABLE*/ break; case 0x18c : case 0x190 : bit_to_set = 0; break; case 0x19c : bit_to_set = 1 << 24; /*PATCH_STATUS_VALID*/ break; case 0x2fc : bit_to_set = NV_READ(NV04_PGRAPH_TRAPPED_DATA) << 15; /*PATCH_CONFIG = NV04_PGRAPH_TRAPPED_DATA*/ break; }; break; case 0x77: switch ( mthd ) { case 0x198 : bit_to_set = 1 << 24; /*PATCH_STATUS_VALID*/ break; case 0x304 : bit_to_set = NV_READ(NV04_PGRAPH_TRAPPED_DATA) << 15; //PATCH_CONFIG break; }; break; default :; }; value_to_set = (NV_READ(0x00700000 | inst_loc << 4))| bit_to_set; /*RAMIN*/ nouveau_wait_for_idle(dev); NV_WRITE(0x00700000 | inst_loc << 4, value_to_set); /*DRM_DEBUG("CTX_SWITCH1 value is %#x\n", NV_READ(NV04_PGRAPH_CTX_SWITCH1));*/ NV_WRITE(NV04_PGRAPH_CTX_SWITCH1, value_to_set); /*DRM_DEBUG("CTX_CACHE1 + xxx value is %#x\n", NV_READ(NV04_PGRAPH_CTX_CACHE1 + (((NV_READ(NV04_PGRAPH_TRAPPED_ADDR) >> 13) & 0x7) << 2)));*/ NV_WRITE(NV04_PGRAPH_CTX_CACHE1 + (((NV_READ(NV04_PGRAPH_TRAPPED_ADDR) >> 13) & 0x7) << 2), value_to_set); } nouveau_software_method_t nouveau_sw_methods[] = { /*NV04 context software methods*/ { 0x4a, 0x188, nouveau_NV04_setcontext_sw_method }, { 0x4a, 0x18c, nouveau_NV04_setcontext_sw_method }, { 0x4a, 0x198, nouveau_NV04_setcontext_sw_method }, { 0x4a, 0x2fc, nouveau_NV04_setcontext_sw_method }, { 0x5c, 0x184, nouveau_NV04_setcontext_sw_method }, { 0x5c, 0x188, nouveau_NV04_setcontext_sw_method }, { 0x5c, 0x18c, nouveau_NV04_setcontext_sw_method }, { 0x5c, 0x198, nouveau_NV04_setcontext_sw_method }, { 0x5c, 0x2fc, nouveau_NV04_setcontext_sw_method }, { 0x5f, 0x184, nouveau_NV04_setcontext_sw_method }, { 0x5f, 0x188, nouveau_NV04_setcontext_sw_method }, { 0x5f, 0x18c, nouveau_NV04_setcontext_sw_method }, { 0x5f, 0x190, nouveau_NV04_setcontext_sw_method }, { 0x5f, 0x19c, nouveau_NV04_setcontext_sw_method }, { 0x5f, 0x2fc, nouveau_NV04_setcontext_sw_method }, { 0x61, 0x188, nouveau_NV04_setcontext_sw_method }, { 0x61, 0x18c, nouveau_NV04_setcontext_sw_method }, { 0x61, 0x190, nouveau_NV04_setcontext_sw_method }, { 0x61, 0x19c, nouveau_NV04_setcontext_sw_method }, { 0x61, 0x2fc, nouveau_NV04_setcontext_sw_method }, { 0x77, 0x198, nouveau_NV04_setcontext_sw_method }, { 0x77, 0x304, nouveau_NV04_setcontext_sw_method }, /*terminator*/ { 0x0, 0x0, NULL, }, }; int nouveau_sw_method_execute(struct drm_device *dev, uint32_t oclass, uint32_t method) { int i = 0; while ( nouveau_sw_methods[ i ] . method_code != NULL ) { if ( nouveau_sw_methods[ i ] . oclass == oclass && nouveau_sw_methods[ i ] . mthd == method ) { nouveau_sw_methods[ i ] . method_code(dev, oclass, method); return 0; } i ++; } return 1; } a> 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
/**
 * \file ati_pcigart.c
 * ATI PCI GART support
 *
 * \author Gareth Hughes <gareth@valinux.com>
 */

/*
 * Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
 *
 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "drmP.h"

# define ATI_PCIGART_PAGE_SIZE		4096	/**< PCI GART page size */

static __inline__ void insert_page_into_table(struct drm_ati_pcigart_info *info, u32 page_base, u32 *pci_gart)
{
	switch(info->gart_reg_if) {
	case DRM_ATI_GART_IGP:
		*pci_gart = cpu_to_le32((page_base) | 0xc);
		break;
	case DRM_ATI_GART_PCIE:
		*pci_gart = cpu_to_le32((page_base >> 8) | 0xc);
		break;
	default:
	case DRM_ATI_GART_PCI:
		*pci_gart = cpu_to_le32(page_base);
		break;
	}
}

static __inline__ u32 get_page_base_from_table(struct drm_ati_pcigart_info *info, u32 *pci_gart)
{
	u32 retval;
	switch(info->gart_reg_if) {
	case DRM_ATI_GART_IGP:
		retval = *pci_gart;
		retval &= ~0xc;
		break;
	case DRM_ATI_GART_PCIE:
		retval = *pci_gart;
		retval &= ~0xc;
		retval <<= 8;
		break;
	default:
	case DRM_ATI_GART_PCI:
		retval = *pci_gart;
		break;
	}
	return retval;
}



static void *drm_ati_alloc_pcigart_table(int order)
{
	unsigned long address;
	struct page *page;
	int i;

	DRM_DEBUG("%s: alloc %d order\n", __FUNCTION__, order);

	address = __get_free_pages(GFP_KERNEL | __GFP_COMP,
				   order);
	if (address == 0UL) {
		return NULL;
	}

	page = virt_to_page(address);

	for (i = 0; i < order; i++, page++) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
		get_page(page);
#endif
		SetPageReserved(page);
	}

	DRM_DEBUG("%s: returning 0x%08lx\n", __FUNCTION__, address);
	return (void *)address;
}

static void drm_ati_free_pcigart_table(void *address, int order)
{
	struct page *page;
	int i;
	int num_pages = 1 << order;
	DRM_DEBUG("%s\n", __FUNCTION__);

	page = virt_to_page((unsigned long)address);

	for (i = 0; i < num_pages; i++, page++) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
		__put_page(page);
#endif
		ClearPageReserved(page);
	}

	free_pages((unsigned long)address, order);
}

int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
{
	struct drm_sg_mem *entry = dev->sg;
	unsigned long pages;
	int i;
	int order;
	int num_pages, max_pages;

	/* we need to support large memory configurations */
	if (!entry) {
		DRM_ERROR("no scatter/gather memory!\n");
		return 0;
	}

	order = drm_order((gart_info->table_size + (PAGE_SIZE-1)) / PAGE_SIZE);
	num_pages = 1 << order;

	if (gart_info->bus_addr) {