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"
8 agpgart_io \- Solaris agpgart driver I/O control operations
12 #include <sys/agpgart.h>
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.
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:
35 #define AGP_DEVICE "/dev/agpgart"
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.
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.
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
64 If the AGP_DEVICE fails to open, it may be due to one of the following reasons:
72 GART table allocation failed.
82 Internal hardware initialization failed.
92 Getting device soft state error. (This is unlikely to happen.)
102 Without enough privilege.
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.)
122 Ioctl command not supported or getting device soft state error.
132 Process not privileged.
138 \fB\fBAGPIOC_INFO\fR\fR
142 Get system wide AGP or IGD hardware information. This command can be called by
143 any process from user or kernel context.
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 */
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 {
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
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.
214 EFAULT Argument copy out error
215 EINVAL Command invalid
225 \fB\fBAGPIOC_ACQUIRE\fR\fR
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.
245 GART has been acquired
262 \fB\fBAGPIOC_RELEASE\fR\fR
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.
299 \fB\fBAGPIOC_SETUP\fR\fR
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.
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 */
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)
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.
353 Argument copy in error.
362 Command invalid for non-AGP system.
371 Hardware setup error.
388 \fB\fBAGPIOC_ALLOCATE\fR\fR
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.
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 */
420 Unique ID of the allocated memory.
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.
443 Type of memory to be allocated. The valid value of agpa_type should be
444 AGP_NORMAL. It is defined as:
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.
463 Reserved for special uses. In normal operations, the value is undefined.
490 Argument copy in/out error.
499 Memory allocation error.
516 \fBAGPIOC_DEALLOCATE\fR
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.
545 Key not valid or memory in use.
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
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 */
591 The unique ID of the memory to be bound, which is previously allocated by
592 calling AGPIOC_ALLOCATE.
601 The starting page offset to be bound in aperture space.
620 Argument copy in error.
638 Binding to the GTT table of IGD devices failed.
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.
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 */
681 Unique ID of the memory to be unbound which was previously bound by calling
691 Reserved for compatibility with X.org/XFree86, not used.
710 Argument copy in error.
719 Argument not valid or memory in use.
728 Unbinding from the GTT table of IGD devices failed.
747 Below is an sample program showing how agpgart ioctls can be used:
754 #include <sys/ioccom.h>
755 #include <sys/types.h>
758 #include <sys/mman.h>
759 #include <sys/agpgart.h>
761 #define AGP_PAGE_SIZE 4096
763 int main(int argc, char *argv[])
766 agp_allocate_t alloc;
769 agp_setup_t modesetup;
774 if((fd = open(AGP_DEVICE, O_RDWR))== -1) {
775 printf("open AGP_DEVICE error with %d\en", errno);\e
778 printf("device opened\en");
780 ret = ioctl(fd, AGPIOC_INFO, &agpinfo);
782 printf("Get info error %d\en", errno);
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);
792 printf(" Acquire GART error %d\en", errno);
796 modesetup.agps_mode = agpinfo.agpi_mode;
797 ret = ioctl(fd, AGPIOC_SETUP, &modesetup);
799 printf("set up AGP mode error\en", errno);
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);
808 printf("Allocate memory error %d\en", errno);
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);
817 printf("Bind error %d\en", errno);
820 printf("Bind successful\en");
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
830 * mmap can allow user processes to store graphics data
831 * to the aperture space
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);
841 printf("Mmap successful\en");
845 * When user processes finish access to the aperture space,
846 * unmap the memory range
848 munmap((void *)p, maplen);
852 * After finishing AGP transactions, the resources can be freed
853 * step by step or simply by close device.
855 ret = ioctl(fd, AGPIOC_DEALLOCATE, alloc.agpa_key);
857 printf(" Deallocate memory error %d\en", errno);
861 ret = ioctl(fd, AGPIOC_RELEASE);
863 printf(" Release GART error %d\en", errno);
876 \fB\fB/dev/agpgart\fR\fR
880 Symbolic link to the pseudo agpgart device.
886 \fB\fB/platform/i86pc/kernel/drv/agpgart\fR\fR
890 agpgart pseudo driver.
896 \fB\fB/platform/i86pc/kernel/drv/agpgart.conf\fR\fR
900 Driver configuration file.
906 See \fBattributes\fR(5) for descriptions of the following attributes:
914 ATTRIBUTE TYPE ATTRIBUTE VALUE
918 Stability level Unstable
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)