/************************************************************************** * * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA. * 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, sub license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDERS, AUTHORS 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. * * **************************************************************************/ /* * Simple memory MANager interface that keeps track on allocate regions on a * per "owner" basis. All regions associated with an "owner" can be released * with a simple call. Typically if the "owner" exists. The owner is any * "unsigned long" identifier. Can typically be a pointer to a file private * struct or a context identifier. * * Authors: * Thomas Hellström */ #ifndef DRM_SMAN_H #define DRM_SMAN_H #include "drmP.h" #include "drm_hashtab.h" /* * A class that is an abstration of a simple memory allocator. * The sman implementation provides a default such allocator * using the drm_mm.c implementation. But the user can replace it. * See the SiS implementation, which may use the SiS FB kernel module * for memory management. */ typedef struct drm_sman_mm { /* private info. If allocated, needs to be destroyed by the destroy function */ void *private; /* Allocate a memory block with given size and alignment. Return an opaque reference to the memory block */ void *(*allocate) (void *private, unsigned long size, unsigned alignment); /* Free a memory block. "ref" is the opaque reference that we got from the "alloc" function */ void (*free) (void *private, void *ref); /* Free all resources associated with this allocator */ void (*destroy) (void *private); /* Return a memory offset from the opaque reference returned from the "alloc" function */ unsigned long (*offset) (void *private, void *ref); } drm_sman_mm_t; typedef struct drm_memblock_item { struct list_head owner_list; drm_hash_item_t user_hash; void *mm_info; drm_sman_mm_t *mm; struct drm_sman *sman; } drm_memblock_item_t; typedef struct drm_sman { drm_sman_mm_t *mm; int num_managers; drm_open_hash_t owner_hash_tab; drm_open_hash_t user_hash_tab; struct list_head owner_items; } drm_sman_t; /* * Take down a memory manager. This function should only be called after a * successful init and after a call to drm_sman_cleanup. */ extern void drm_sman_takedown(drm_sman_t * sman); /* * Allocate structures for a manager. * num_managers are the number of memory pools to manage. (VRAM, AGP, ....) * user_order is the log2 of the number of buckets in the user hash table. * set this to approximately log2 of the max number of memory regions * that will be allocated for _all_ pools together. * owner_order is the log2 of the number of buckets in the owner hash table. * set this to approximately log2 of * the number of client file connections that will * be using the manager. * */ extern int drm_sman_init(drm_sman_t * sman, unsigned int num_managers, unsigned int user_order, unsigned int owner_order); /* * Initialize a drm_mm.c allocator. Should be called only once for each * manager unless a customized allogator is used. */ extern int drm_sman_set_range(drm_sman_t * sman, unsigned int manager, unsigned long start, unsigned long size); /* * Initialize a customized allocator for one of the managers. * (See the SiS module). The object pointed to by "allocator" is copied, * so it can be destroyed after this call. */ extern int drm_sman_set_manager(drm_sman_t * sman, unsigned int mananger, drm_sman_mm_t * allocator); /* * Allocate a memory block. Aligment is not implemented yet. */ extern drm_memblock_item_t *drm_sman_alloc(drm_sman_t * sman, unsigned int manager, unsigned long size, unsigned alignment, unsigned long owner); /* * Free a memory block identified by its user hash key. */ extern int drm_sman_free_key(drm_sman_t * sman, unsigned int key); /* * returns 1 iff there are no stale memory blocks associated with this owner. * Typically called to determine if we need to idle the hardware and call * drm_sman_owner_cleanup. If there are no stale memory blocks, it removes all * resources associated with owner. */ extern int drm_sman_owner_clean(drm_sman_t * sman, unsigned long owner); /* * Frees all stale memory blocks associated with this owner. Note that this * requires that the hardware is finished with all blocks, so the graphics engine * should be idled before this call is made. This function also frees * any resources associated with "owner" and should be called when owner * is not going to be referenced anymore. */ extern void drm_sman_owner_cleanup(drm_sman_t * sman, unsigned long owner); /* * Frees all stale memory blocks associated with the memory manager. * See idling above. */ extern void drm_sman_cleanup(drm_sman_t * sman); #endif #n97'>97 98 99 100 101 102 103 104 105 106 107 108 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 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
/**
 * \file drm_stub.c
 * Stub support
 *
 * \author Rickard E. (Rik) Faith <faith@valinux.com>
 */

/*
 * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org
 *
 * Copyright 2001 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 <linux/module.h>
#include <linux/moduleparam.h>

#include "drmP.h"
#include "drm_core.h"

unsigned int drm_debug = 0;		/* 1 to enable debug output */
EXPORT_SYMBOL(drm_debug);

MODULE_AUTHOR(CORE_AUTHOR);
MODULE_DESCRIPTION(CORE_DESC);
MODULE_LICENSE("GPL and additional rights");
MODULE_PARM_DESC(debug, "Enable debug output");

module_param_named(debug, drm_debug, int, 0600);

struct idr drm_minors_idr;

struct class *drm_class;
struct proc_dir_entry *drm_proc_root;

static int drm_minor_get_id(struct drm_device *dev, int type)
{
	int new_id;
	int ret;
	int base = 0, limit = 63;

	if (type == DRM_MINOR_CONTROL) {
		base += 64;
		limit = base + 127;
	} else if (type == DRM_MINOR_RENDER) {
		base += 128;
		limit = base + 255;
	}	

again:
	if (idr_pre_get(&drm_minors_idr, GFP_KERNEL) == 0) {
		DRM_ERROR("Out of memory expanding drawable idr\n");
		return -ENOMEM;
	}
	mutex_lock(&dev->struct_mutex);