/* dristat.c -- * Created: Mon Jan 15 05:05:07 2001 by faith@acm.org * * Copyright 2000 VA Linux Systems, Inc., Fremont, 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. * * Authors: Rickard E. (Rik) Faith * */ #include #include #include #include "xf86drm.h" #include "xf86drmRandom.c" #include "xf86drmHash.c" #include "xf86drm.c" #define DRM_VERSION 0x00000001 #define DRM_MEMORY 0x00000002 #define DRM_CLIENTS 0x00000004 #define DRM_STATS 0x00000008 #define DRM_BUSID 0x00000010 static void getversion(int fd) { drmVersionPtr version; version = drmGetVersion(fd); if (version) { printf(" Version information:\n"); printf(" Name: %s\n", version->name ? version->name : "?"); printf(" Version: %d.%d.%d\n", version->version_major, version->version_minor, version->version_patchlevel); printf(" Date: %s\n", version->date ? version->date : "?"); printf(" Desc: %s\n", version->desc ? version->desc : "?"); drmFreeVersion(version); } else { printf(" No version information available\n"); } } static void getbusid(int fd) { const char *busid = drmGetBusid(fd); printf(" Busid: %s\n", *busid ? busid : "(not set)"); drmFreeBusid(busid); } static void getvm(int fd) { int i; const char *typename; char flagname[33]; drm_handle_t offset; drmSize size; drmMapType type; drmMapFlags flags; drm_handle_t handle; int mtrr; printf(" VM map information:\n"); printf(" flags: (R)estricted (r)ead/(w)rite (l)ocked (k)ernel (W)rite-combine (L)ock:\n"); printf(" slot offset size type flags address mtrr\n"); for (i = 0; !drmGetMap(fd, i, &offset, &size, &type, &flags, &handle, &mtrr); i++) { switch (type) { case DRM_FRAME_BUFFER: typename = "FB"; break; case DRM_REGISTERS: typename = "REG"; break; case DRM_SHM: typename = "SHM"; break; case DRM_AGP: typename = "AGP"; break; case DRM_SCATTER_GATHER: typename = "SG"; break; default: typename = "???"; break; } flagname[0] = (flags & DRM_RESTRICTED) ? 'R' : ' '; flagname[1] = (flags & DRM_READ_ONLY) ? 'r' : 'w'; flagname[2] = (flags & DRM_LOCKED) ? 'l' : ' '; flagname[3] = (flags & DRM_KERNEL) ? 'k' : ' '; flagname[4] = (flags & DRM_WRITE_COMBINING) ? 'W' : ' '; flagname[5] = (flags & DRM_CONTAINS_LOCK) ? 'L' : ' '; flagname[6] = '\0'; printf(" %4d 0x%08lx 0x%08lx %3.3s %6.6s 0x%08lx ", i, offset, (unsigned long)size, typename, flagname, handle); if (mtrr < 0) printf("none\n"); else printf("%4d\n", mtrr); } } static void getclients(int fd) { int i; int auth; int pid; int uid; unsigned long magic; unsigned long iocs; char buf[64]; char cmd[40]; int procfd; printf(" DRI client information:\n"); printf(" a pid uid magic ioctls prog\n"); for (i = 0; !drmGetClient(fd, i, &auth, &pid, &uid, &magic, &iocs); i++) { sprintf(buf, "/proc/%d/cmdline", pid); memset(cmd, 0, sizeof(cmd)); if ((procfd = open(buf, O_RDONLY, 0)) >= 0) { read(procfd, cmd, sizeof(cmd)-1); close(procfd); } if (*cmd) { char *pt; for (pt = cmd; *pt; pt++) if (!isprint(*pt)) *pt = ' '; printf(" %c %5d %5d %10lu %10lu %s\n", auth ? 'y' : 'n', pid, uid, magic, iocs, cmd); } else { printf(" %c %5d %5d %10lu %10lu\n", auth ? 'y' : 'n', pid, uid, magic, iocs); } } } static void printhuman(unsigned long value, const char *name, int mult) { const char *p; double f; /* Print width 5 number in width 6 space */ if (value < 100000) { printf(" %5lu", value); return; } p = name; f = (double)value / (double)mult; if (f < 10.0) { printf(" %4.2f%c", f, *p); return; } p++; f = (double)value / (double)mult; if (f < 10.0) { printf(" %4.2f%c", f, *p); return; } p++; f = (double)value / (double)mult; if (f < 10.0) { printf(" %4.2f%c", f, *p); return; } } static void getstats(int fd, int i) { drmStatsT prev, curr; int j; double rate; printf(" System statistics:\n"); if (drmGetStats(fd, &prev)) return; if (!i) { for (j = 0; j < prev.count; j++) { printf(" "); printf(prev.data[j].long_format, prev.data[j].long_name); if (prev.data[j].isvalue) printf(" 0x%08lx\n", prev.data[j].value); else printf(" %10lu\n", prev.data[j].value); } return; } printf(" "); for (j = 0; j < prev.count; j++) if (!prev.data[j].verbose) { printf(" "); printf(prev.data[j].rate_format, prev.data[j].rate_name); } printf("\n"); for (;;) { sleep(i); if (drmGetStats(fd, &curr)) return; printf(" "); for (j = 0; j < curr.count; j++) { if (curr.data[j].verbose) continue; if (curr.data[j].isvalue) { printf(" %08lx", curr.data[j].value); } else { rate = (curr.data[j].value - prev.data[j].value) / (double)i; printhuman(rate, curr.data[j].mult_names, curr.data[j].mult); } } printf("\n"); memcpy(&prev, &curr, sizeof(prev)); } } int main(int argc, char **argv) { int c; int mask = 0; int minor = 0; int interval = 0; int fd; char buf[64]; int i; while ((c = getopt(argc, argv, "avmcsbM:i:")) != EOF) switch (c) { case 'a': mask = ~0; break; case 'v': mask |= DRM_VERSION; break; case 'm': mask |= DRM_MEMORY; break; case 'c': mask |= DRM_CLIENTS; break; case 's': mask |= DRM_STATS; break; case 'b': mask |= DRM_BUSID; break; case 'i': interval = strtol(optarg, NULL, 0); break; case 'M': minor = strtol(optarg, NULL, 0); break; default: fprintf( stderr, "Usage: dristat [options]\n\n" ); fprintf( stderr, "Displays DRM information. Use with no arguments to display available cards.\n\n" ); fprintf( stderr, " -a Show all available information\n" ); fprintf( stderr, " -b Show DRM bus ID's\n" ); fprintf( stderr, " -c Display information about DRM clients\n" ); fprintf( stderr, " -i [interval] Continuously display statistics every [interval] seconds\n" ); fprintf( stderr, " -v Display DRM module and card version information\n" ); fprintf( stderr, " -m Display memory use information\n" ); fprintf( stderr, " -s Display DRM statistics\n" ); fprintf( stderr, " -M [minor] Select card by minor number\n" ); return 1; } for (i = 0; i < 16; i++) if (!minor || i == minor) { sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, i); fd = drmOpenMinor(i, 1); if (fd >= 0) { printf("%s\n", buf); if (mask & DRM_BUSID) getbusid(fd); if (mask & DRM_VERSION) getversion(fd); if (mask & DRM_MEMORY) getvm(fd); if (mask & DRM_CLIENTS) getclients(fd); if (mask & DRM_STATS) getstats(fd, interval); close(fd); } } return 0; } 9' href='#n169'>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 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
/* savage_drv.h -- Private header for the savage driver */
/*
 * Copyright 2004  Felix Kuehling
 * 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 FELIX KUEHLING 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.
 */

#ifndef __SAVAGE_DRV_H__
#define __SAVAGE_DRV_H__

#define DRIVER_AUTHOR	"Felix Kuehling"

#define DRIVER_NAME	"savage"
#define DRIVER_DESC	"Savage3D/MX/IX, Savage4, SuperSavage, Twister, ProSavage[DDR]"
#define DRIVER_DATE	"20050313"

#define DRIVER_MAJOR		2
#define DRIVER_MINOR		4
#define DRIVER_PATCHLEVEL	1
/* Interface history:
 *
 * 1.x   The DRM driver from the VIA/S3 code drop, basically a dummy
 * 2.0   The first real DRM
 * 2.1   Scissors registers managed by the DRM, 3D operations clipped by
 *       cliprects of the cmdbuf ioctl
 * 2.2   Implemented SAVAGE_CMD_DMA_IDX and SAVAGE_CMD_VB_IDX
 * 2.3   Event counters used by BCI_EVENT_EMIT/WAIT ioctls are now 32 bits
 *       wide and thus very long lived (unlikely to ever wrap). The size
 *       in the struct was 32 bits before, but only 16 bits were used
 * 2.4   Implemented command DMA. Now drm_savage_init_t.cmd_dma_offset is
 *       actually used
 */

typedef struct drm_savage_age {
	uint16_t event;
	unsigned int wrap;
} drm_savage_age_t;

typedef struct drm_savage_buf_priv {
	struct drm_savage_buf_priv *next;
	struct drm_savage_buf_priv *prev;
	drm_savage_age_t age;
	struct drm_buf *buf;
} drm_savage_buf_priv_t;

typedef struct drm_savage_dma_page {
	drm_savage_age_t age;
	unsigned int used, flushed;
} drm_savage_dma_page_t;
#define SAVAGE_DMA_PAGE_SIZE 1024 /* in dwords */
/* Fake DMA buffer size in bytes. 4 pages. Allows a maximum command
 * size of 16kbytes or 4k entries. Minimum requirement would be
 * 10kbytes for 255 40-byte vertices in one drawing command. */
#define SAVAGE_FAKE_DMA_SIZE (SAVAGE_DMA_PAGE_SIZE*4*4)

/* interesting bits of hardware state that are saved in dev_priv */
typedef union {
	struct drm_savage_common_state {
		uint32_t vbaddr;
	} common;
	struct {
		unsigned char pad[sizeof(struct drm_savage_common_state)];
		uint32_t texctrl, texaddr;
		uint32_t scstart, new_scstart;
		uint32_t scend, new_scend;
	} s3d;
	struct {
		unsigned char pad[sizeof(struct drm_savage_common_state)];
		uint32_t texdescr, texaddr0, texaddr1;
		uint32_t drawctrl0, new_drawctrl0;
		uint32_t drawctrl1, new_drawctrl1;
	} s4;
} drm_savage_state_t;

/* these chip tags should match the ones in the 2D driver in savage_regs.h. */
enum savage_family {
	S3_UNKNOWN = 0,
	S3_SAVAGE3D,
	S3_SAVAGE_MX,
	S3_SAVAGE4,
	S3_PROSAVAGE,
	S3_TWISTER,
	S3_PROSAVAGEDDR,
	S3_SUPERSAVAGE,
	S3_SAVAGE2000,
	S3_LAST
};

extern struct drm_ioctl_desc savage_ioctls[];
extern int savage_max_ioctl;

#define S3_SAVAGE3D_SERIES(chip)  ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))

#define S3_SAVAGE4_SERIES(chip)  ((chip==S3_SAVAGE4)            \
                                  || (chip==S3_PROSAVAGE)       \
                                  || (chip==S3_TWISTER)         \
                                  || (chip==S3_PROSAVAGEDDR))

#define	S3_SAVAGE_MOBILE_SERIES(chip)	((chip==S3_SAVAGE_MX) || (chip==S3_SUPERSAVAGE))

#define S3_SAVAGE_SERIES(chip)    ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))

#define S3_MOBILE_TWISTER_SERIES(chip)   ((chip==S3_TWISTER)    \
                                          ||(chip==S3_PROSAVAGEDDR))

/* flags */
#define SAVAGE_IS_AGP 1

typedef struct drm_savage_private {
	drm_savage_sarea_t *sarea_priv;

	drm_savage_buf_priv_t head, tail;

	/* who am I? */
	enum savage_family chipset;

	unsigned int cob_size;
	unsigned int bci_threshold_lo, bci_threshold_hi;
	unsigned int dma_type;

	/* frame buffer layout */
	unsigned int fb_bpp;
	unsigned int front_offset, front_pitch;
	unsigned int back_offset, back_pitch;
	unsigned int depth_bpp;
	unsigned int depth_offset, depth_pitch;

	/* bitmap descriptors for swap and clear */
	unsigned int front_bd, back_bd, depth_bd;

	/* local textures */
	unsigned int texture_offset;
	unsigned int texture_size;

	/* memory regions in physical memory */
	drm_local_map_t *sarea;
	drm_local_map_t *mmio;
	drm_local_map_t *fb;
	drm_local_map_t *aperture;
	drm_local_map_t *status;
	drm_local_map_t *agp_textures;
	drm_local_map_t *cmd_dma;
	drm_local_map_t fake_dma;

	struct {
		int handle;
		unsigned long base, size;
	} mtrr[3];

	/* BCI and status-related stuff */
	volatile uint32_t *status_ptr, *bci_ptr;
	uint32_t status_used_mask;
	uint16_t event_counter;
	unsigned int event_wrap;