Contained Within
Find More Documentation
Featured Support Resources
| Download this book in PDF
Example Hardware Initialization Code
A
- This appendix shows hardware initialization code for a GX frame buffer. The file consists of include files and the constructor for the XglDpMgr object for the GX frame buffer.
-
Note - If you are running on a GX frame buffer, and you built the GX reference pipeline xglSUNWcg6.so.4 , and you want to build your pipeline using the GX intialization code listed below, you need to rename the cg6 binary xglSUNWcg6.so.4 and link your pipeline to the cg6 name using the command ln -s xglYourpipe.so.4 xglSUNWcg6.so.4.
Hardware Initialization Code for the GX Frame Buffer
-
-
// **********************************************************
// *
// * Filename:DpMgrGXexample.cc
// *
// * Purpose:This is a C++ source file that contains a routine
// * used to initialize a physical hardware device managed by
// * the Dp manager and a routine that creates a Dp device object.
// *
// **********************************************************
#include "xgli/Drawable.h"
#include "xgli/SysState.h"// for XGLI_ERROR()
#include "DpMgrGXexample.h"
-
-
#include "DpDevGXexample.h"
// vvvvvvvvvvvvvvvvvv GX example vvvvvvvvvvvvvvvvvv
//
// Required package: SUNWDrvs
//
// for ioctl()
#include "/opt/SUNWddk/driver_dev/cgsix/sparc/cg6io.h"
#include <sysent.h>
#include <sys/mman.h>
#include <sys/cg6reg.h>
const int MegaByte = 0x100000;
// ^^^^^^^^^^^^^^^^^^ GX example ^^^^^^^^^^^^^^^^^^
class XglDpDev;
class XglRasterWin;
// *------------------------------------------------------
// *
// * XglDpMgrGXexample::XglDpMgrGXexample
// *
// * The constructor for the Dp manager object is called when
// * a new DpMgr object is created by the DpLib. This is done
// * once per physical device that is accessed.
// * Use this routine to initialize your hardware and to store
// * device-specific information.
// *
// *-------------------------------------------------------
XglDpMgrGXexample::XglDpMgrGXexample(XglDrawable* drawable)
{
creationOk = TRUE; // flag indicating successful hardware
// initialization. Default value is TRUE
//
// File descriptor or device name for opening your device.
//
int fd = drawable->getDevFd();
const char* name = drawable->getDeviceName();
-
-
//=====================================================
//=====================================================
// EDIT HERE:
// vvvvvvvvvvvvvvvvvv GX example vvvvvvvvvvvvvvvvvv
// Requires independent address space
memoryMappedImageBuffer = TRUE;
// ^^^^^^^^^^^^^^^^^^ GX example ^^^^^^^^^^^^^^^^^^
// Requires independent address space
memoryMappedZBuffer = FALSE;
// The value of the variables hwZBuffer and hwAccumBuffer
// are tested in DpDevGXexample. They determine which type
// of PixRect gets instantiated for your hardware. FALSE
// indicates that your hardware does not support Z buffering.
hwZBuffer = FALSE;
// Note: It is strongly recommended that if you have
// hardware accumulation, you implement li1Accumulate
// and li1ClearAccumulation. Otherwise, set
// hwAccumBuffer to FALSE. When this variable is
// FALSE, accumulation is done in software.See DpDevGXexample
// for allocation of the software accumulation buffer.
hwAccumBuffer = FALSE;
// Insert hardware initialization here.
// vvvvvvvvvvvvvvvvvv GX example vvvvvvvvvvvvvvvvvv
struct cg6_informgx_info;
Xgl_sgn32 gx_pageoffset; // Offset of gx_physaddr from page bdry
Xgl_sgn32 gx_physaddr; // Adjusted gx_physaddr
Xgl_usgn32gx_alloc_bytes;
Xgl_usgn8*gx_base_addr;
if(ioctl(fd, CG6IOGXINFO, &gx_info) == -1) {
XGLI_DI_ERROR( (XglSysState*)NULL, "di-6", XGL_OBJ,
NULL, NULL);
creationOk = FALSE;
return;
}
gx_alloc_bytes = gx_info.vmsize * MegaByte;
if(gx_info.hdb_capable)
gx_alloc_bytes *= 2;
-
-
gx_pageoffset = CG6_VADDR_COLOR & ( sysconf( _SC_PAGESIZE) - 1 );
gx_alloc_bytes += gx_pageoffset;
gx_physaddr = CG6_VADDR_COLOR - gx_pageoffset;
gx_base_addr = (Xgl_usgn8* ) mmap( (caddr_t)NULL,
(size_t)gx_alloc_bytes,
PROT_READ | PROT_WRITE, MAP_SHARED,
fd, gx_physaddr );
if(gx_base_addr == (Xgl_usgn8*)-1) {
XGLI_DI_ERROR( (XglSysState*)NULL, "di-6", XGL_OBJ,
NULL, NULL);
creationOk = FALSE;
return;
}
// ^^^^^^^^^^^^^^^^^^ GX example ^^^^^^^^^^^^^^^^^^
//
// End hardware initialization here
//=======================================================
//=======================================================
// Set this environment variable to test the error mechanism.
// This example will abort this device pipeline if any
// hardware initialization problems occur, output a device
// specific error message, set creationOk to FALSE, and then
// return immediately. In this case, the xpex pipeline
// will be used.
// Note: When this variable is set, your pipeline
// will always abort.
//
char *hw_error = getenv("XGL_GXEXAMPLE_ERROR_TEST");
if (hw_error) {
XGLI_ERROR((XglSysState*)NULL,
XGL_ERROR_NONRECOVERABLE,
XGL_ERROR_RESOURCE,
"SYMBOLgxexample-1",
XGL_SYS_STATE,
NULL, NULL);
// Example of predefined error message (out of memory).
// Notice _DI_
XGLI_DI_ERROR((XglSysState*)NULL, "di-1",
XGL_SYS_STATE, NULL, NULL);
creationOk = FALSE;
return;
-
-
}
//
// FOR MEMORY-MAPPED FRAME BUFFERS:
// This section begins the initialization of the RefDpCtx
// tilitisy for memory-mapped frame buffers. If your frame
// buffer is not memory-mapped, you can ignore or delete
// this section.
//
Xgl_usgn32linebytes; // # bytes from one scan line to next
Xgl_usgn32fb_width; // Frame buffer width
Xgl_usgn32fb_height; // Frame buffer height
//=========================================================
//=========================================================
// EDIT HERE:
// If image buffer is memory mapped, set fb_address to
// the base address of the image buffer; otherwise,
// leave as NULL.
// If z buffer is memory mapped, set z_buffer_address to
// the base address of the z buffer; otherwise, leave as NULL.
//
// vvvvvvvvvvvvvvvvvv GX example vvvvvvvvvvvvvvvvvv
Xgl_usgn8*fb_address = gx_base_addr;
// ^^^^^^^^^^^^^^^^^^ GX example ^^^^^^^^^^^^^^^^^^
Xgl_usgn8*z_buffer_address = NULL;
//========================================================
//========================================================
// X11 attributes
Xgl_X_window user_win;
XWindowAttributes wattrs;
Window window;
Display* dpy;
intscreen;
// Get the width and height of the frame buffer
// and the depth of the window from the X server.
//
drawable->getDescriptor((void*)&user_win);
dpy = (Display*)user_win.X_display;
window = (Window)user_win.X_window;
screen = (int)user_win.X_screen;
-
-
// Identify properties of root window--our "frame buffer".
// Note that this example uses Xlib calls to retrieve information
// about the hardware. You could also use an ioctl() for this.
//
XGetWindowAttributes(dpy, window, &wattrs);
fb_width = wattrs.screen->width; // root window width
fb_height = wattrs.screen->height; // root window height
linebytes = fb_width;
//
// If image and/or Z buffer is memory mapped, this initializes the
// XglPixRectMemAssigned class. The PixRect object is
// instantiated by the DpDevGXexample class.
//
if (memoryMappedImageBuffer)
fbPixRect.reassign(fb_address, fb_width, fb_height,
wattrs.depth, linebytes);
if (memoryMappedZBuffer)
zPixRect.reassign(z_buffer_address, fb_width, fb_height,
wattrs.depth, linebytes);
// End of section on initializing RefDpCtx for memory-
// mapped frame buffers.
// RefDpCtx initialization is continued in the DpDev object.
} // End of XglDpMgrGXexample::XglDpMgrGXexample
|
|