1 '\" te
   2 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved
   3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
   6 .TH AGPGART_IO 7I "Sep 10, 2013"
   7 .SH NAME
   8 agpgart_io \- Solaris agpgart driver I/O control operations
   9 .SH SYNOPSIS
  10 .LP
  11 .nf
  12 #include <sys/agpgart.h>
  13 .fi
  14 
  15 .SH DESCRIPTION
  16 .sp
  17 .LP
  18 The Accelerated Graphics Port (AGP) is a PCI bus technology enhancement that
  19 improves 3D graphics performance by using low-cost system memory. AGP chipsets
  20 use the Graphics Address Remapping Table (GART) to map discontiguous system
  21 memory into a contiguous PCI memory range (known as the AGP Aperture), enabling
  22 the graphics card to utilize the mapped aperture range as video memory.
  23 .sp
  24 .LP
  25 The \fBagpgart\fR driver creates a pseudo device node at \fB/dev/agpgart\fR and
  26 provides a set of ioctls for managing  allocation/deallocation of system
  27 memory, setting mappings between system memory and aperture range, and setting
  28 up AGP devices. The \fBagpgart\fR driver manages both pseudo and real device
  29 nodes, but to initiate AGP-related operations you operate only on the
  30 \fB/dev/agpgart\fR pseudo device node. To do this, open \fB/dev/agpgart\fR. The
  31 macro defined for the pseudo device node name is:
  32 .sp
  33 .in +2
  34 .nf
  35 #define  AGP_DEVICE      "/dev/agpgart"
  36 .fi
  37 .in -2
  38 
  39 .sp
  40 .LP
  41 The \fBagpgart_io\fR driver implementation is AGP architecture-dependent and
  42 cannot be made generic. Currently, the \fBagpgart_io\fR driver only supports
  43 specific AGP  systems. To determine if a system is supported, run an
  44 \fBopen\fR(2) system  call on the AGP_DEVICE node. (Note that  \fBopen\fR(2)
  45 fails if a system is not supported). After the AGP_DEVICE is opened, you can
  46 use \fBkstat\fR(1M) to  read the system architecture  type.
  47 .sp
  48 .LP
  49 In addition to AGP system support, the \fBagpgart\fR ioctls can also be used on
  50 Intel integrated graphics devices (IGD). IGD devices usually have no dedicated
  51 video memory and must  use system memory as video memory. IGD devices contain
  52 translation tables (referred to as \fBGTT\fR tables) that are similar to the
  53 GART translation table for address mapping purposes.
  54 .sp
  55 .LP
  56 Processes must open the \fBagpgart_io\fR driver utilizing a GRAPHICS_ACCESS
  57 privilege. Then all the ioctls  can be called  by this processes with the saved
  58 file descriptor. With the exception of AGPIOC_INFO, the AGPIOC_ACQUIRE ioctl
  59 must be called before any other ioctl. Once a process has acquired GART, it
  60 cannot be acquired by another process until the former process calls
  61 AGPIOC_RELEASE.
  62 .sp
  63 .LP
  64 If the AGP_DEVICE fails to open, it may be due to one of the following reasons:
  65 .sp
  66 .ne 2
  67 .na
  68 \fBEAGAIN\fR
  69 .ad
  70 .sp .6
  71 .RS 4n
  72 GART table allocation failed.
  73 .RE
  74 
  75 .sp
  76 .ne 2
  77 .na
  78 \fBEIO\fR
  79 .ad
  80 .sp .6
  81 .RS 4n
  82 Internal hardware initialization failed.
  83 .RE
  84 
  85 .sp
  86 .ne 2
  87 .na
  88 \fBENXIO\fR
  89 .ad
  90 .sp .6
  91 .RS 4n
  92 Getting device soft state error. (This is unlikely to happen.)
  93 .RE
  94 
  95 .sp
  96 .ne 2
  97 .na
  98 \fB EPERM\fR
  99 .ad
 100 .sp .6
 101 .RS 4n
 102 Without enough privilege.
 103 .RE
 104 
 105 .SH IOCTLS
 106 .sp
 107 .LP
 108 With the exception of GPIOC_INFO, all ioctls shown in this section are
 109 protected by GRAPHICS_ACCESS privilege. (Only processes with GRAPHICS_ACCESS
 110 privilege in its effective set can access the privileged ioctls).
 111 .sp
 112 .LP
 113 Common ioctl error codes are shown below. (Additional error codes may be
 114 displayed by individual ioctls.)
 115 .sp
 116 .ne 2
 117 .na
 118 \fBENXIO\fR
 119 .ad
 120 .sp .6
 121 .RS 4n
 122 Ioctl command not supported or getting device soft state error.
 123 .RE
 124 
 125 .sp
 126 .ne 2
 127 .na
 128 \fBEPERM\fR
 129 .ad
 130 .sp .6
 131 .RS 4n
 132 Process not privileged.
 133 .RE
 134 
 135 .sp
 136 .ne 2
 137 .na
 138 \fB\fBAGPIOC_INFO\fR\fR
 139 .ad
 140 .sp .6
 141 .RS 4n
 142 Get system wide AGP or IGD hardware information. This command can be called by
 143 any process from user or kernel context.
 144 .sp
 145 .in +2
 146 .nf
 147 The argument is a pointer to agp_info_t structure.
 148 
 149  typedef struct  _agp_info {
 150        agp_version_t agpi_version; /* OUT: AGP version supported */
 151        uint32_t agpi_devid;    /* OUT: bridge vendor + device */
 152        uint32_t agpi_mode;     /* OUT: mode of bridge */
 153        ulong_t  agpi_aperbase; /* OUT: base of aperture */
 154        size_t   agpi_apersize; /* OUT: aperture size in MB */
 155        uint32_t agpi_pgtotal;  /* OUT: max aperture pages avail. */
 156        uint32_t agpi_pgsystem; /* OUT: same as pg_total */
 157        uint32_t agpi_pgused; /* OUT: no. of currently used pages */
 158  } agp_info_t;
 159 
 160 agpi_version  The version of AGP protocol the bridge device is
 161               compatible with, for example, major 3 and minor 0
 162               means AGP version 3.0.
 163 
 164               typedef struct _agp_version {
 165                       uint16_t   agpv_major;
 166                       uint16_t   agpv_minor;
 167               } agp_version_t;
 168 
 169 agpi_devid    AGP bridge vendor and device ID.
 170 agpi_mode     Current AGP mode, read from AGP status register of
 171               target device. The main bits are defined as below.
 172               /* AGP status register bits definition */
 173 
 174                 #define AGPSTAT_RQ_MASK         0xff000000
 175                 #define AGPSTAT_SBA             (0x1 << 9)
 176                 #define AGPSTAT_OVER4G          (0x1 << 5)
 177                 #define AGPSTAT_FW              (0x1 << 4)
 178                 #define AGPSTAT_RATE_MASK       0x7
 179                 /* AGP 3.0 only bits */
 180                 #define AGPSTAT_ARQSZ_MASK      (0x7 << 13)
 181                 #define AGPSTAT_CAL_MASK        (0x7 << 10)
 182                 #define AGPSTAT_GART64B         (0x1 << 7)
 183                 #define AGPSTAT_MODE3           (0x1 << 3)
 184                 /* rate for 2.0 mode */
 185                 #define AGP2_RATE_1X                    0x1
 186                 #define AGP2_RATE_2X                    0x2
 187                 #define AGP2_RATE_4X                    0x4
 188                 /* rate for 3.0 mode */
 189                 #define AGP3_RATE_4X                    0x1
 190                 #define AGP3_RATE_8X                    0x2
 191 
 192 agpi_aperbase   The base address of aperture in PCI memory space.
 193 agpi_apersize   The size of the aperture in megabytes.
 194 agpi_pgtotal    Represents the maximum memory
 195                 pages the system can allocate
 196                 according to aperture size and
 197                 system memory size (which may differ
 198                 from the maximum locked memory a process
 199                 can have. The latter  is subject
 200                 to the memory resource limit imposed
 201                 by the  resource_controls(5) for each
 202                 project(4)):
 203 
 204                   project.max-device-locked-memory
 205 
 206                 This value can be modified through system
 207                 utilities like prctl(1).
 208 
 209 agpi_pgsystem  Same as pg_total.
 210 agpi_pgused    System pages already allocated by the driver.
 211 
 212 Return Values:
 213 
 214            EFAULT  Argument copy out error
 215            EINVAL  Command invalid
 216            0       Success
 217 .fi
 218 .in -2
 219 
 220 .RE
 221 
 222 .sp
 223 .ne 2
 224 .na
 225 \fB\fBAGPIOC_ACQUIRE\fR\fR
 226 .ad
 227 .sp .6
 228 .RS 4n
 229 Acquire control of GART. With the exception of AGPIOC_INFO, a process must
 230 acquire GART before can it call other agpgart ioctl commands. Additionally,
 231 only processes with GRAPHICS_ACCESS privilege may access this ioctl. In the
 232 current agpgart implementation, GART access is exclusive, meaning that only one
 233 process can perform GART operations at a time. To release control over GART,
 234 call AGPIOC_RELEASE. This command can be called from user or kernel context.
 235 .sp
 236 The argument should be NULL.
 237 .sp
 238 Return values:
 239 .sp
 240 .ne 2
 241 .na
 242 \fBEBUSY\fR
 243 .ad
 244 .RS 9n
 245 GART has been acquired
 246 .RE
 247 
 248 .sp
 249 .ne 2
 250 .na
 251 \fB0\fR
 252 .ad
 253 .RS 9n
 254 Success.
 255 .RE
 256 
 257 .RE
 258 
 259 .sp
 260 .ne 2
 261 .na
 262 \fB\fBAGPIOC_RELEASE\fR\fR
 263 .ad
 264 .sp .6
 265 .RS 4n
 266 Release GART control. If a process releases GART control, it cannot perform
 267 additional GART operations until GART is reacquired. Note that this command
 268 does not free allocated memory or clear GART entries. (All clear jobs are done
 269 by direct calls or by closing the device). When a process exits without making
 270 this ioctl, the final \fBclose\fR(2) performs this automatically. This command
 271 can be called from user or kernel context.
 272 .sp
 273 The argument should be NULL.
 274 .sp
 275 Return values:
 276 .sp
 277 .ne 2
 278 .na
 279 \fBEPERM\fR
 280 .ad
 281 .RS 9n
 282 Not owner of GART.
 283 .RE
 284 
 285 .sp
 286 .ne 2
 287 .na
 288 \fB0\fR
 289 .ad
 290 .RS 9n
 291 Success.
 292 .RE
 293 
 294 .RE
 295 
 296 .sp
 297 .ne 2
 298 .na
 299 \fB\fBAGPIOC_SETUP\fR\fR
 300 .ad
 301 .sp .6
 302 .RS 4n
 303 Setup AGPCMD register. An AGPCMD register resides in both  the  AGP master and
 304 target devices. The AGPCMD register controls the working mode of the AGP master
 305 and target devices. Each device must be  configured  using the same mode. This
 306 command can be called from user or kernel context.
 307 .sp
 308 .in +2
 309 .nf
 310 The argument is a pointer to agp_setup_t structure:
 311 
 312      typedef struct _agp_setup {
 313            uint32_t agps_mode; /* IN: value to be set for AGPCMD */
 314      } agp_setup_t;
 315 
 316 agps_mode  Specifying the mode to be set. Each bit of the value may have
 317            a specific meaning, please refer to AGP 2.0/3.0 specification
 318            or hardware datasheets for details.
 319 
 320                /* AGP command register bits definition */
 321                #define     AGPCMD_RQ_MASK          0xff000000
 322                #define     AGPCMD_SBAEN            (0x1 << 9)
 323                #define     AGPCMD_AGPEN            (0x1 << 8)
 324                #define     AGPCMD_OVER4GEN         (0x1 << 5)
 325                #define     AGPCMD_FWEN             (0x1 << 4)
 326                #define     AGPCMD_RATE_MASK        0x7
 327                /* AGP 3.0 only bits */
 328                #define     AGP3_CMD_ARQSZ_MASK     (0x7 << 13)
 329                #define     AGP3_CMD_CAL_MASK       (0x7 << 10)
 330                #define     AGP3_CMD_GART64BEN      (0x1 << 7)
 331 .fi
 332 .in -2
 333 
 334 The final values set to the AGPCMD register of the master/target devices are
 335 decided by the agps_mode value and AGPSTAT of the master and target devices.
 336 .sp
 337 Return Values:
 338 .sp
 339 .ne 2
 340 .na
 341 \fBEPERM\fR
 342 .ad
 343 .RS 10n
 344 Not owner of GART.
 345 .RE
 346 
 347 .sp
 348 .ne 2
 349 .na
 350 \fBEFAULT\fR
 351 .ad
 352 .RS 10n
 353 Argument copy in error.
 354 .RE
 355 
 356 .sp
 357 .ne 2
 358 .na
 359 \fBEINVAL\fR
 360 .ad
 361 .RS 10n
 362 Command invalid for non-AGP system.
 363 .RE
 364 
 365 .sp
 366 .ne 2
 367 .na
 368 \fBEIO\fR
 369 .ad
 370 .RS 10n
 371 Hardware setup error.
 372 .RE
 373 
 374 .sp
 375 .ne 2
 376 .na
 377 \fB0\fR
 378 .ad
 379 .RS 10n
 380 Success.
 381 .RE
 382 
 383 .RE
 384 
 385 .sp
 386 .ne 2
 387 .na
 388 \fB\fBAGPIOC_ALLOCATE\fR\fR
 389 .ad
 390 .sp .6
 391 .RS 4n
 392 Allocate system memory for graphics device. This command returns a unique ID
 393 which can be used in subsequent operations to represent the allocated memory.
 394 The memory is made up of discontiguous physical pages. In rare cases, special
 395 memory types may be required. The allocated memory must be bound to the GART
 396 table before it can be used by graphics device. Graphics applications can also
 397 \fBmmap\fR(2) the memory to userland for data storing. Memory should be freed
 398 when it is no longer used by calling AGPIOC_DEALLOCATE or simply by closing the
 399 device. This command can be called from user or kernel context.
 400 .sp
 401 .in +2
 402 .nf
 403 The argument is a pointer to agp_allocate_t structure.
 404 
 405      typedef struct _agp_allocate {
 406            int32_t  agpa_key;     /* OUT:ID of allocated memory */
 407            uint32_t agpa_pgcount;/* IN: no. of pages to be allocated */
 408            uint32_t agpa_type;/* IN: type of memory to be allocated */
 409            uint32_t agpa_physical; /* OUT: reserved */
 410      } agp_allocate_t;
 411 .fi
 412 .in -2
 413 
 414 .sp
 415 .ne 2
 416 .na
 417 \fBagpa_key\fR
 418 .ad
 419 .RS 21n
 420 Unique ID of the allocated memory.
 421 .RE
 422 
 423 .sp
 424 .ne 2
 425 .na
 426 \fBagpa_pgcount\fR
 427 .ad
 428 .RS 21n
 429 Number of pages to be allocated. The driver currently supports only 4K pages.
 430 The value cannot exceed the agpi_pgtotal value returned by AGPIOC_INFO ioct and
 431 is subject to the limit of project.max-device-locked-memory. If the memory
 432 needed is larger than the resource limit but not larger than agpi_pgtotal, use
 433 \fBprctl\fR(1) or other system utilities to change the default value of memory
 434 resource limit beforehand.
 435 .RE
 436 
 437 .sp
 438 .ne 2
 439 .na
 440 \fBagpa_type\fR
 441 .ad
 442 .RS 21n
 443 Type of memory to be allocated. The valid value of agpa_type should be
 444 AGP_NORMAL. It is defined as:
 445 .sp
 446 .in +2
 447 .nf
 448          #define AGP_NORMAL      0
 449 .fi
 450 .in -2
 451 
 452 Above, AGP_NORMAL represents the discontiguous non-cachable physical memory
 453 which doesn't consume kernel virtual space but can be mapped to user space by
 454 \fBmmap\fR(2). This command may support more type values in the future.
 455 .RE
 456 
 457 .sp
 458 .ne 2
 459 .na
 460 \fBagpa_physical\fR
 461 .ad
 462 .RS 21n
 463 Reserved for special uses. In normal operations, the value is undefined.
 464 .sp
 465 Return Values:
 466 .sp
 467 .ne 2
 468 .na
 469 \fBEPERM\fR
 470 .ad
 471 .RS 10n
 472 Not owner of GART.
 473 .RE
 474 
 475 .sp
 476 .ne 2
 477 .na
 478 \fBEINVAL\fR
 479 .ad
 480 .RS 10n
 481 Argument not valid.
 482 .RE
 483 
 484 .sp
 485 .ne 2
 486 .na
 487 \fBEFAULT\fR
 488 .ad
 489 .RS 10n
 490 Argument copy in/out error.
 491 .RE
 492 
 493 .sp
 494 .ne 2
 495 .na
 496 \fBENOMEM\fR
 497 .ad
 498 .RS 10n
 499 Memory allocation error.
 500 .RE
 501 
 502 .sp
 503 .ne 2
 504 .na
 505 \fB0\fR
 506 .ad
 507 .RS 10n
 508 Success.
 509 .RE
 510 
 511 .RE
 512 
 513 .sp
 514 .ne 2
 515 .na
 516 \fBAGPIOC_DEALLOCATE\fR
 517 .ad
 518 .RS 21n
 519 Deallocate the memory identified by a key assigned in a previous allocation. If
 520 the memory isn't unbound from GART, this command unbinds it automatically. The
 521 memory should no longer be used and those still in mapping to userland cannot
 522 be deallocated. Always call AGPIOC_DEALLOCATE explicitly (instead of
 523 deallocating  implicitly by closing the device), as the system won't carry out
 524 the job until the last reference to the device file is dropped. This command
 525 from user or kernel context.
 526 .sp
 527 The input argument is a key of type int32_t, no output argument.
 528 .sp
 529 Return Values:
 530 .sp
 531 .ne 2
 532 .na
 533 \fBEPERM\fR
 534 .ad
 535 .RS 10n
 536 Not owner of GART.
 537 .RE
 538 
 539 .sp
 540 .ne 2
 541 .na
 542 \fBEINVAL\fR
 543 .ad
 544 .RS 10n
 545 Key not valid or memory in use.
 546 .RE
 547 
 548 .sp
 549 .ne 2
 550 .na
 551 \fB0\fR
 552 .ad
 553 .RS 10n
 554 Success.
 555 .RE
 556 
 557 .RE
 558 
 559 .sp
 560 .ne 2
 561 .na
 562 \fBAGPIOC_BIND\fR
 563 .ad
 564 .RS 21n
 565 Bind allocated memory.  This  command binds the allocated   memory  identified
 566 by a key to  a specific offset of the GART table, which enables GART   to
 567 translate the aperture  range at the offset to system memory. Each GART entry
 568 represents one physical page. If the GART range is previously bound to other
 569 system memory, it returns an error. Once the memory is bound, it cannot be
 570 bound to other offsets unless it is unbound. To unbind the memory, call
 571 AGPIOC_UNBIND or deallocate the memory. This command can be called from user or
 572 kernel context.
 573 .sp
 574 .in +2
 575 .nf
 576 The argument is a pointer to agp_bind_t structure:
 577 
 578      typedef struct _agp_bind {
 579            int32_t  agpb_key;      /* IN: ID of memory to be bound */
 580            uint32_t agpb_pgstart;  /* IN: offset in aperture */
 581      } agp_bind_t;
 582 .fi
 583 .in -2
 584 
 585 .sp
 586 .ne 2
 587 .na
 588 \fBagpb_key\fR
 589 .ad
 590 .RS 20n
 591 The unique ID of the memory to be bound, which is previously allocated by
 592 calling AGPIOC_ALLOCATE.
 593 .RE
 594 
 595 .sp
 596 .ne 2
 597 .na
 598 \fBagpb_pgstart\fR
 599 .ad
 600 .RS 20n
 601 The starting page offset to be bound in aperture space.
 602 .RE
 603 
 604 Return Values:
 605 .sp
 606 .ne 2
 607 .na
 608 \fBEPERM\fR
 609 .ad
 610 .RS 20n
 611 Not owner of GART.
 612 .RE
 613 
 614 .sp
 615 .ne 2
 616 .na
 617 \fBEFAULT\fR
 618 .ad
 619 .RS 20n
 620 Argument copy in error.
 621 .RE
 622 
 623 .sp
 624 .ne 2
 625 .na
 626 \fBEINVAL\fR
 627 .ad
 628 .RS 20n
 629 Argument not valid.
 630 .RE
 631 
 632 .sp
 633 .ne 2
 634 .na
 635 \fBEIO\fR
 636 .ad
 637 .RS 20n
 638 Binding to the GTT table of IGD devices failed.
 639 .RE
 640 
 641 .sp
 642 .ne 2
 643 .na
 644 \fB0\fR
 645 .ad
 646 .RS 20n
 647 Success.
 648 .RE
 649 
 650 .RE
 651 
 652 .sp
 653 .ne 2
 654 .na
 655 \fBAGPIOC_UNBIND\fR
 656 .ad
 657 .RS 21n
 658 Unbind memory identified by a key from the GART. This command clears the
 659 corresponding entries in the GART table. Only the memory not in mapping to
 660 userland is allowed to be unbound.
 661 .sp
 662 This ioctl command can be called from user or kernel context.
 663 .sp
 664 .in +2
 665 .nf
 666 The argument is a pointer to agp_unbind_t structure.
 667 
 668      typedef struct _agp_unbind {
 669            int32_t  agpu_key; /* IN: key of memory to be unbound*/
 670            uint32_t agpu_pri; /* Not used: for compat. with Xorg */
 671      } agp_unbind_t;
 672 .fi
 673 .in -2
 674 
 675 .sp
 676 .ne 2
 677 .na
 678 \fBagpu_key\fR
 679 .ad
 680 .RS 20n
 681 Unique ID of the memory to be unbound which was previously bound by calling
 682 AGPIOC_BIND.
 683 .RE
 684 
 685 .sp
 686 .ne 2
 687 .na
 688 \fBagpu_pri\fR
 689 .ad
 690 .RS 20n
 691 Reserved for compatibility with X.org/XFree86, not used.
 692 .RE
 693 
 694 Return Values:
 695 .sp
 696 .ne 2
 697 .na
 698 \fBEPERM\fR
 699 .ad
 700 .RS 20n
 701 Not owner of GART.
 702 .RE
 703 
 704 .sp
 705 .ne 2
 706 .na
 707 \fBEFAULT\fR
 708 .ad
 709 .RS 20n
 710 Argument copy in error.
 711 .RE
 712 
 713 .sp
 714 .ne 2
 715 .na
 716 \fBEINVAL\fR
 717 .ad
 718 .RS 20n
 719 Argument not valid or memory in use.
 720 .RE
 721 
 722 .sp
 723 .ne 2
 724 .na
 725 \fBEIO\fR
 726 .ad
 727 .RS 20n
 728 Unbinding from the GTT table of IGD devices failed.
 729 .RE
 730 
 731 .sp
 732 .ne 2
 733 .na
 734 \fB0\fR
 735 .ad
 736 .RS 20n
 737 Success
 738 .RE
 739 
 740 .RE
 741 
 742 .RE
 743 
 744 .SH EXAMPLE
 745 .sp
 746 .LP
 747 Below is an sample program showing how agpgart ioctls can be used:
 748 .sp
 749 .in +2
 750 .nf
 751 #include <stdio.h>
 752 #include <stdlib.h>
 753 #include <unistd.h
 754 #include <sys/ioccom.h>
 755 #include <sys/types.h>
 756 #include <fcntl.h>
 757 #include <errno.h>
 758 #include <sys/mman.h>
 759 #include <sys/agpgart.h>
 760 
 761 #define AGP_PAGE_SIZE   4096
 762 
 763 int main(int argc, char *argv[])
 764 {
 765         int fd, ret;
 766         agp_allocate_t alloc;
 767         agp_bind_t bindinfo;
 768         agp_info_t agpinfo;
 769         agp_setup_t modesetup;
 770         int *p = NULL;
 771         off_t mapoff;
 772         size_t maplen;
 773 
 774         if((fd = open(AGP_DEVICE, O_RDWR))== -1) {
 775                 printf("open AGP_DEVICE error with %d\en", errno);\e
 776                 exit(-1);
 777         }
 778         printf("device opened\en");
 779 
 780         ret = ioctl(fd, AGPIOC_INFO, &agpinfo);
 781         if(ret == -1) {
 782                 printf("Get info error %d\en", errno);
 783                 exit(-1);
 784         }
 785         printf("AGPSTAT is %x\en", agpinfo.agpi_mode);
 786         printf("APBASE is %x\en", agpinfo.agpi_aperbase);
 787         printf("APSIZE is %dMB\en", agpinfo.agpi_apersize);
 788         printf("pg_total is %d\en", agpinfo.agpi_pgtotal);
 789 
 790         ret = ioctl(fd, AGPIOC_ACQUIRE);
 791         if(ret == -1) {
 792                 printf(" Acquire GART error %d\en", errno);
 793                 exit(-1);
 794         }
 795 
 796         modesetup.agps_mode = agpinfo.agpi_mode;
 797         ret = ioctl(fd, AGPIOC_SETUP, &modesetup);
 798         if(ret == -1) {
 799                 printf("set up AGP mode error\en", errno);
 800                 exit(-1);
 801         }
 802 
 803         printf("Please input the number of pages you want to allocate\en");
 804         scanf("%d", &alloc.agpa_pgcount);
 805         alloc.agpa_type = AGP_NORMAL;
 806         ret = ioctl(fd, AGPIOC_ALLOCATE, &alloc);
 807         if(ret == -1) {
 808                 printf("Allocate memory error %d\en", errno);
 809                 exit(-1);
 810         }
 811 
 812         printf("Please input the aperture page offset to bind\en");
 813         scanf("%d", &bindinfo.agpb_pgstart);
 814         bindinfo.agpb_key = alloc.agpa_key;
 815         ret = ioctl(fd, AGPIOC_BIND, &bindinfo);
 816         if(ret == -1) {
 817                 printf("Bind error %d\en", errno);
 818                 exit(-1);
 819         }
 820         printf("Bind successful\en");
 821 
 822         /*
 823          * Now gart aperture space from (bindinfo.agpb_pgstart) to
 824          * (bindinfo.agpb_pgstart + alloc.agpa_pgcount) can be used for
 825          * AGP graphics transactions
 826          */
 827         ...
 828 
 829         /*
 830          * mmap can allow user processes to store graphics data
 831          * to the aperture space
 832          */
 833         maplen = alloc.agpa_pgcount * AGP_PAGE_SIZE;
 834         mapoff = bindinfo.agpb_pgstart * AGP_PAGE_SIZE;
 835         p = (int *)mmap((caddr_t)0, maplen, (PROT_READ | PROT_WRITE),
 836                         MAP_SHARED, fd, mapoff);
 837         if (p == MAP_FAILED) {
 838                 printf("Mmap error %d\en", errno);
 839                 exit(-1);
 840         }
 841         printf("Mmap successful\en");
 842         ...
 843 
 844         /*
 845          * When user processes finish access to the aperture space,
 846          * unmap the memory range
 847          */
 848         munmap((void *)p, maplen);
 849         ...
 850 
 851         /*
 852          * After finishing AGP transactions, the resources can be freed
 853          * step by step or simply by close device.
 854          */
 855         ret = ioctl(fd, AGPIOC_DEALLOCATE, alloc.agpa_key);
 856         if(ret == -1) {
 857                 printf(" Deallocate memory error %d\en", errno);
 858                 exit(-1);
 859         }
 860 
 861         ret = ioctl(fd, AGPIOC_RELEASE);
 862         if(ret == -1) {
 863                 printf(" Release GART error %d\en", errno);
 864                 exit(-1);
 865         }
 866 
 867         close(fd);
 868 }
 869 .fi
 870 .in -2
 871 
 872 .SH FILES
 873 .sp
 874 .ne 2
 875 .na
 876 \fB\fB/dev/agpgart\fR\fR
 877 .ad
 878 .sp .6
 879 .RS 4n
 880 Symbolic link to the pseudo agpgart device.
 881 .RE
 882 
 883 .sp
 884 .ne 2
 885 .na
 886 \fB\fB/platform/i86pc/kernel/drv/agpgart\fR\fR
 887 .ad
 888 .sp .6
 889 .RS 4n
 890 agpgart pseudo driver.
 891 .RE
 892 
 893 .sp
 894 .ne 2
 895 .na
 896 \fB\fB/platform/i86pc/kernel/drv/agpgart.conf\fR\fR
 897 .ad
 898 .sp .6
 899 .RS 4n
 900 Driver configuration file.
 901 .RE
 902 
 903 .SH ATTRIBUTES
 904 .sp
 905 .LP
 906 See \fBattributes\fR(5) for descriptions of the following attributes:
 907 .sp
 908 
 909 .sp
 910 .TS
 911 box;
 912 c | c
 913 l | l .
 914 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 915 _
 916 Architecture    X86
 917 _
 918 Stability level Unstable
 919 .TE
 920 
 921 .SH SEE ALSO
 922 .sp
 923 .LP
 924 \fBprctl\fR(1), \fBkstat\fR(1M), \fBclose\fR(2), \fBioctl\fR(2), \fBopen\fR(2),
 925 \fBmmap\fR(2), \fBproject\fR(4), \fBprivileges\fR(5), \fBattributes\fR(5),
 926 \fBresource_controls\fR(5)