/* * This file is subject to the terms of the GFX License. If a copy of * the license was not distributed with this file, you can obtain one at: * * http://ugfx.io/license.html */ // Set this to your frame buffer pixel format. Note Linux frame buffer only supports RGB modes (no BGR modes). #ifndef GDISP_LLD_PIXELFORMAT #define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 #endif #ifdef GDISP_DRIVER_VMT #define FBDEV_PATH1 "/dev/fb0" #define FBDEV_PATH2 "/dev/fb/0" // Optional - comment this out to only try the one device #define USE_SET_MODE // Optional - comment this out to not to try to set the color mode we want //#define VTDEV_PATH "/dev/tty0" // Optional - if defined use this tty to switch from text to graphics mode #define _GNU_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if VTDEV_PATH static void board_revert2textmode(void) { int tty; // Go back to text mode if ((tty = open(VTDEV_PATH, O_RDWR)) >= 0) { ioctl(tty, KDSETMODE, KD_TEXT); close(tty); } } static void board_switch2graphicsmode(void) { int tty; // Open the tty if ((tty = open (VTDEV_PATH, O_RDWR)) < 0) { fprintf(stderr, "GDISP Framebuffer: Cannot open tty %s\n", VTDEV_PATH); exit(-1); } if (ioctl (tty, KDSETMODE, KD_GRAPHICS) == -1) { fprintf(stderr, "GDISP Framebuffer: Cannot set to graphics mode\n"); exit(-1); } close(tty); // Make sure we clean up properly atexit(board_revert2textmode) } #endif static void board_init(GDisplay *g, fbInfo *fbi) { int fb; char * env; size_t fblen; struct fb_fix_screeninfo fb_fix; struct fb_var_screeninfo fb_var; // Open the frame buffer device if((env = getenv("FRAMEBUFFER")) != 0) fb = open(env, O_RDWR); else { fb = open(FBDEV_PATH1, O_RDWR); #ifdef FBDEV_PATH2 if (fb < 0) fb = open(FBDEV_PATH2, O_RDWR); #endif } if(fb < 0) { fprintf(stderr, "GDISP Framebuffer: Error opening the framebuffer device\n"); exit(-1); } // Get screen info if (ioctl(fb, FBIOGET_FSCREENINFO, &fb_fix) == -1 || ioctl(fb, FBIOGET_VSCREENINFO, &fb_var) == -1) { fprintf(stderr, "GDISP Framebuffer: Error getting screen info\n"); exit(-1); } #ifdef USE_SET_MODE fb_var.reserved[0] = 0; fb_var.reserved[1] = 0; fb_var.reserved[2] = 0; fb_var.xoffset = 0; fb_var.yoffset = 0; #if LLDCOLOR_BITS == 15 fb_var.bits_per_pixel = LLDCOLOR_BITS; // Handle RGB555 & BGR555 #else fb_var.bits_per_pixel = sizeof(LLDCOLOR_TYPE)*8; #endif fb_var.grayscale = 0; fb_var.activate = FB_ACTIVATE_NOW; if (ioctl(fb, FBIOPUT_VSCREENINFO, &fb_var) == -1 || ioctl (fb, FBIOGET_VSCREENINFO, &fb_var) == -1) { fprintf(stderr, "GDISP Framebuffer: Failed to set video mode\n"); exit(-1); } #endif // Check things are as they should be if (fb_fix.type != FB_TYPE_PACKED_PIXELS) { fprintf(stderr, "GDISP Framebuffer: The display is not in a single plane graphics mode\n"); exit(-1); } if (fb_fix.visual != FB_VISUAL_TRUECOLOR) { fprintf(stderr, "GDISP Framebuffer: The display is not in TRUECOLOR mode\n"); exit(-1); } if (fb_var.bits_per_pixel != sizeof(LLDCOLOR_TYPE)*8) { fprintf(stderr, "GDISP Framebuffer: The display is %u not %u bits per pixel\n", fb_var.bits_per_pixel, LLDCOLOR_TYPE_BITS); exit(-1); } if (fb_var.red.length != LLDCOLOR_BITS_R || fb_var.green.length != LLDCOLOR_BITS_G || fb_var.blue.length != LLDCOLOR_BITS_B) { fprintf(stderr, "GDISP Framebuffer: The display pixel format is not %d%d%d\n", LLDCOLOR_BITS_R, LLDCOLOR_BITS_G, LLDCOLOR_BITS_B); exit(-1); } if (fb_var.red.offset != LLDCOLOR_SHIFT_R || fb_var.green.offset != LLDCOLOR_SHIFT_G || fb_var.blue.offset != LLDCOLOR_SHIFT_B) { #if LLDCOLOR_SHIFT_B == 0 fprintf(stderr, "GDISP Framebuffer: The display pixel format is not RGB\n"); #else fprintf(stderr, "GDISP Framebuffer: The display pixel format is not BGR\n"); #endif exit(-1); } // Ensure we are at the origin of the virtual display area if (fb_var.xoffset || fb_var.yoffset) { fb_var.xoffset = 0; fb_var.yoffset = 0; ioctl(fb, FBIOPAN_DISPLAY, &fb_var); } // Switch to graphics mode (if required) #ifdef VTDEV_PATH board_switch2graphicsmode(); #endif // Calculate the frame buffer length fblen = fb_var.yres * fb_fix.line_length; // Different systems need mapping in slightly different ways - Yuck! #ifdef ARCH_LINUX_SPARC #define CG3_MMAP_OFFSET 0x4000000 #define CG6_RAM 0x70016000 #define TCX_RAM8BIT 0x00000000 #define TCX_RAM24BIT 0x01000000 switch (fb_fix.accel) { case FB_ACCEL_SUN_CGTHREE: fbi->pixels = mmap(0, fblen, PROT_READ|PROT_WRITE, MAP_SHARED, fb, CG3_MMAP_OFFSET); break; case FB_ACCEL_SUN_CGSIX: fbi->pixels = mmap(0, fblen, PROT_READ|PROT_WRITE, MAP_SHARED, fb, CG6_RAM); break; case FB_ACCEL_SUN_TCX: fbi->pixels = mmap(0, fblen, PROT_READ|PROT_WRITE, MAP_SHARED, fb, TCX_RAM24BIT); break; default: fprintf(stderr, "GDISP Framebuffer: Don't know how to mmap with accel %d\n", fb_fix.accel); exit(-1); } #elif defined(BLACKFIN) fbi->pixels = mmap(0, fblen, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FILE, fb, 0); #elif defined(__uClinux__) fbi->pixels = mmap(0, fblen, PROT_READ|PROT_WRITE, 0, fb, 0); #else fbi->pixels = mmap(0, fblen, PROT_READ|PROT_WRITE, MAP_SHARED, fb, 0); #endif if(!fbi->pixels || fbi->pixels == (void *)-1) { fprintf(stderr, "GDISP Framebuffer: mmap of display buffer failed\n"); exit(-1); } // If this program gets children they should not inherit this file descriptor fcntl(fb, F_SETFD, FD_CLOEXEC); // We are finished with the file descriptor close(fb); // Set the rest of the details of the frame buffer g->g.Width = fb_var.xres; g->g.Height = fb_var.yres; g->g.Backlight = 100; g->g.Contrast = 50; fbi->linelen = fb_fix.line_length; } #if GDISP_HARDWARE_FLUSH static void board_flush(GDisplay *g) { (void) g; } #endif #if GDISP_NEED_CONTROL static void board_backlight(GDisplay *g, gU8 percent) { (void) g; (void) percent; } static void board_contrast(GDisplay *g, gU8 percent) { (void) g; (void) percent; } static void board_power(GDisplay *g, gPowermode pwr) { (void) g; (void) pwr; } #endif #endif /* GDISP_LLD_BOARD_IMPLEMENTATION */ ground-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/******************************************************************************
 * pci.c
 * 
 * Architecture-dependent PCI access functions.
 */

#include <xen/spinlock.h>
#include <xen/pci.h>
#include <asm/io.h>

static DEFINE_SPINLOCK(pci_config_lock);

uint32_t pci_conf_read(uint32_t cf8, uint8_t offset, uint8_t bytes)
{
    unsigned long flags;
    uint32_t value;

    BUG_ON((offset + bytes) > 4);

    spin_lock_irqsave(&pci_config_lock, flags);

    outl(cf8, 0xcf8);

    switch ( bytes )
    {
    case 1:
        value = inb(0xcfc + offset);
        break;
    case 2:
        value = inw(0xcfc + offset);
        break;
    case 4:
        value = inl(0xcfc + offset);