rename the top-level Makefile.cfgparam to cfgparam.mk
[unleashed.git] / share / man / man7i / agpgart_io.7i
blobf0d372b7d33136fc50a843c2c8f10d4015ff77c3
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
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
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(8) 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
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
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
95 .sp
96 .ne 2
97 .na
98 \fB EPERM\fR
99 .ad
100 .sp .6
101 .RS 4n
102 Without enough privilege.
105 .SH IOCTLS
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).
113 Common ioctl error codes are shown below. (Additional error codes may be
114 displayed by individual ioctls.)
116 .ne 2
118 \fBENXIO\fR
120 .sp .6
121 .RS 4n
122 Ioctl command not supported or getting device soft state error.
126 .ne 2
128 \fBEPERM\fR
130 .sp .6
131 .RS 4n
132 Process not privileged.
136 .ne 2
138 \fB\fBAGPIOC_INFO\fR\fR
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.
145 .in +2
147 The argument is a pointer to agp_info_t structure.
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;
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.
164               typedef struct _agp_version {
165                       uint16_t   agpv_major;
166                       uint16_t   agpv_minor;
167               } agp_version_t;
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 */
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
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)):
204                   project.max-device-locked-memory
206                 This value can be modified through system
207                 utilities like prctl(1).
209 agpi_pgsystem  Same as pg_total.
210 agpi_pgused    System pages already allocated by the driver.
212 Return Values:
214            EFAULT  Argument copy out error
215            EINVAL  Command invalid
216            0       Success
218 .in -2
223 .ne 2
225 \fB\fBAGPIOC_ACQUIRE\fR\fR
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.
236 The argument should be NULL.
238 Return values:
240 .ne 2
242 \fBEBUSY\fR
244 .RS 9n
245 GART has been acquired
249 .ne 2
251 \fB0\fR
253 .RS 9n
254 Success.
260 .ne 2
262 \fB\fBAGPIOC_RELEASE\fR\fR
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.
273 The argument should be NULL.
275 Return values:
277 .ne 2
279 \fBEPERM\fR
281 .RS 9n
282 Not owner of GART.
286 .ne 2
288 \fB0\fR
290 .RS 9n
291 Success.
297 .ne 2
299 \fB\fBAGPIOC_SETUP\fR\fR
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.
308 .in +2
310 The argument is a pointer to agp_setup_t structure:
312      typedef struct _agp_setup {
313            uint32_t agps_mode; /* IN: value to be set for AGPCMD */
314      } agp_setup_t;
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.
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)
332 .in -2
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.
337 Return Values:
339 .ne 2
341 \fBEPERM\fR
343 .RS 10n
344 Not owner of GART.
348 .ne 2
350 \fBEFAULT\fR
352 .RS 10n
353 Argument copy in error.
357 .ne 2
359 \fBEINVAL\fR
361 .RS 10n
362 Command invalid for non-AGP system.
366 .ne 2
368 \fBEIO\fR
370 .RS 10n
371 Hardware setup error.
375 .ne 2
377 \fB0\fR
379 .RS 10n
380 Success.
386 .ne 2
388 \fB\fBAGPIOC_ALLOCATE\fR\fR
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.
401 .in +2
403 The argument is a pointer to agp_allocate_t structure.
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;
412 .in -2
415 .ne 2
417 \fBagpa_key\fR
419 .RS 21n
420 Unique ID of the allocated memory.
424 .ne 2
426 \fBagpa_pgcount\fR
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.
438 .ne 2
440 \fBagpa_type\fR
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:
446 .in +2
448          #define AGP_NORMAL      0
450 .in -2
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.
458 .ne 2
460 \fBagpa_physical\fR
462 .RS 21n
463 Reserved for special uses. In normal operations, the value is undefined.
465 Return Values:
467 .ne 2
469 \fBEPERM\fR
471 .RS 10n
472 Not owner of GART.
476 .ne 2
478 \fBEINVAL\fR
480 .RS 10n
481 Argument not valid.
485 .ne 2
487 \fBEFAULT\fR
489 .RS 10n
490 Argument copy in/out error.
494 .ne 2
496 \fBENOMEM\fR
498 .RS 10n
499 Memory allocation error.
503 .ne 2
505 \fB0\fR
507 .RS 10n
508 Success.
514 .ne 2
516 \fBAGPIOC_DEALLOCATE\fR
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.
527 The input argument is a key of type int32_t, no output argument.
529 Return Values:
531 .ne 2
533 \fBEPERM\fR
535 .RS 10n
536 Not owner of GART.
540 .ne 2
542 \fBEINVAL\fR
544 .RS 10n
545 Key not valid or memory in use.
549 .ne 2
551 \fB0\fR
553 .RS 10n
554 Success.
560 .ne 2
562 \fBAGPIOC_BIND\fR
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.
574 .in +2
576 The argument is a pointer to agp_bind_t structure:
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;
583 .in -2
586 .ne 2
588 \fBagpb_key\fR
590 .RS 20n
591 The unique ID of the memory to be bound, which is previously allocated by
592 calling AGPIOC_ALLOCATE.
596 .ne 2
598 \fBagpb_pgstart\fR
600 .RS 20n
601 The starting page offset to be bound in aperture space.
604 Return Values:
606 .ne 2
608 \fBEPERM\fR
610 .RS 20n
611 Not owner of GART.
615 .ne 2
617 \fBEFAULT\fR
619 .RS 20n
620 Argument copy in error.
624 .ne 2
626 \fBEINVAL\fR
628 .RS 20n
629 Argument not valid.
633 .ne 2
635 \fBEIO\fR
637 .RS 20n
638 Binding to the GTT table of IGD devices failed.
642 .ne 2
644 \fB0\fR
646 .RS 20n
647 Success.
653 .ne 2
655 \fBAGPIOC_UNBIND\fR
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.
662 This ioctl command can be called from user or kernel context.
664 .in +2
666 The argument is a pointer to agp_unbind_t structure.
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;
673 .in -2
676 .ne 2
678 \fBagpu_key\fR
680 .RS 20n
681 Unique ID of the memory to be unbound which was previously bound by calling
682 AGPIOC_BIND.
686 .ne 2
688 \fBagpu_pri\fR
690 .RS 20n
691 Reserved for compatibility with X.org/XFree86, not used.
694 Return Values:
696 .ne 2
698 \fBEPERM\fR
700 .RS 20n
701 Not owner of GART.
705 .ne 2
707 \fBEFAULT\fR
709 .RS 20n
710 Argument copy in error.
714 .ne 2
716 \fBEINVAL\fR
718 .RS 20n
719 Argument not valid or memory in use.
723 .ne 2
725 \fBEIO\fR
727 .RS 20n
728 Unbinding from the GTT table of IGD devices failed.
732 .ne 2
734 \fB0\fR
736 .RS 20n
737 Success
744 .SH EXAMPLE
747 Below is an sample program showing how agpgart ioctls can be used:
749 .in +2
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>
761 #define AGP_PAGE_SIZE   4096
763 int main(int argc, char *argv[])
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;
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");
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);
790         ret = ioctl(fd, AGPIOC_ACQUIRE);
791         if(ret == -1) {
792                 printf(" Acquire GART error %d\en", errno);
793                 exit(-1);
794         }
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         }
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         }
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");
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         ...
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 = mmap(NULL, 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         ...
844         /*
845          * When user processes finish access to the aperture space,
846          * unmap the memory range
847          */
848         munmap((void *)p, maplen);
849         ...
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         }
861         ret = ioctl(fd, AGPIOC_RELEASE);
862         if(ret == -1) {
863                 printf(" Release GART error %d\en", errno);
864                 exit(-1);
865         }
867         close(fd);
870 .in -2
872 .SH FILES
874 .ne 2
876 \fB\fB/dev/agpgart\fR\fR
878 .sp .6
879 .RS 4n
880 Symbolic link to the pseudo agpgart device.
884 .ne 2
886 \fB\fB/platform/i86pc/kernel/drv/agpgart\fR\fR
888 .sp .6
889 .RS 4n
890 agpgart pseudo driver.
894 .ne 2
896 \fB\fB/platform/i86pc/kernel/drv/agpgart.conf\fR\fR
898 .sp .6
899 .RS 4n
900 Driver configuration file.
903 .SH ATTRIBUTES
906 See \fBattributes\fR(5) for descriptions of the following attributes:
911 box;
912 c | c
913 l | l .
914 ATTRIBUTE TYPE  ATTRIBUTE VALUE
916 Architecture    X86
918 Stability level Unstable
921 .SH SEE ALSO
924 \fBprctl\fR(1), \fBkstat\fR(8), \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)