<commit_before>#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/errno.h>
#include<linux/string.h>
#include<linux/mm.h>
#include<linux/slab.h>
#include<linux/delay.h>
#include<linux/fb.h>
#include<linux/ioport.h>
#include<linux/init.h>
#include<linux/pci.h>
#include<linux/mm_types.h>
#include<linux/vmalloc.h>
#include<linux/pagemap.h>
#include<linux/screen_info.h>
#include<linux/vmalloc.h>
#include<linux/pagemap.h>
#include <linux/console.h>
#ifdef CONFIG_MTRR
#include <asm/mtrr.h>
#endif
#include <asm/fb.h>
#include "sm750.h"
#include "sm750_hw.h"
#include "sm750_accel.h"
#include "sm750_cursor.h"

#include "modedb.h"

int smi_indent = 0;


/*
#ifdef __BIG_ENDIAN
ssize_t lynxfb_ops_write(struct fb_info *info, const char __user *buf,
 	    size_t count, loff_t *ppos);
ssize_t lynxfb_ops_read(struct fb_info *info, char __user *buf,
			   size_t count, loff_t *ppos);
#endif
 */

typedef void (*PROC_SPEC_SETUP)(struct lynx_share*,char *);
typedef int (*PROC_SPEC_MAP)(struct lynx_share*,struct pci_dev*);
typedef int (*PROC_SPEC_INITHW)(struct lynx_share*,struct pci_dev*);


/* common var for all device */
static int g_hwcursor = 1;
static int g_noaccel;
#ifdef CONFIG_MTRR
static int g_nomtrr;
#endif
static const char * g_fbmode[] = {NULL,NULL};
static const char * g_def_fbmode = "800x600-16@60";
static char * g_settings = NULL;
static int g_dualview;
static char * g_option = NULL;

/* if not use spin_lock,system will die if user load driver
 * and immediatly unload driver frequently (dual)*/
static inline void myspin_lock(spinlock_t * sl){
	struct lynx_share * share;
	share = container_of(sl,struct lynx_share,slock);
	if(share->dual){
		spin_lock(sl);
	}
}

static inline void myspin_unlock(spinlock_t * sl){
	struct lynx_share * share;
	share = container_of(sl,struct lynx_share,slock);
	if(share->dual){
		spin_unlock(sl);
	}
}
static const struct fb_videomode lynx750_ext[] = {
	/*  	1024x600-60 VESA 	[1.71:1]	*/
	{NULL,  60, 1024, 600, 20423, 144,  40, 18, 1, 104, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/* 	1024x600-70 VESA */
	{NULL,  70, 1024, 600, 17211, 152,  48, 21, 1, 104, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*  	1024x600-75 VESA */
	{NULL,  75, 1024, 600, 15822, 160,  56, 23, 1, 104, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*  	1024x600-85 VESA */
	{NULL,  85, 1024, 600, 13730, 168,  56, 26, 1, 112, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*	720x480	*/
	{NULL, 60,  720,  480,  37427, 88,   16, 13, 1,   72,  3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*	1280x720		[1.78:1]	*/
	{NULL, 60,  1280,  720,  13426, 162, 86, 22, 1,  136, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},

	/* 1280x768@60 */
	{NULL,60,1280,768,12579,192,64,20,3,128,7,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},

	{NULL,60,1360,768,11804,208,64,23,1,144,3,
	FB_SYNC_HOR_HIGH_ACT|FB_VMODE_NONINTERLACED},

	/*	1360 x 768	[1.77083:1]	*/
	{NULL,  60, 1360, 768, 11804, 208,  64, 23, 1, 144, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*	1368 x 768      [1.78:1]	*/
	{NULL, 60,  1368,  768,  11647, 216, 72, 23, 1,  144, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/* 	1440 x 900		[16:10]	*/
	{NULL, 60, 1440, 900, 9392, 232, 80, 28, 1, 152, 3,
	FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},

	/*	1440x960		[15:10]	*/
	{NULL, 60, 1440, 960, 8733, 240, 88, 30, 1, 152, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*	1920x1080	[16:9]	*/
	{NULL, 60, 1920, 1080, 6734, 148, 88, 41, 1, 44, 3,
	FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},
};




/* no hardware cursor supported under version 2.6.10, kernel bug */
static int lynxfb_ops_cursor(struct fb_info* info,struct fb_cursor* fbcursor)
{
	struct lynxfb_par * par;
	struct lynxfb_crtc * crtc;
	struct lynx_cursor * cursor;

	par = info->par;
	crtc = &par->crtc;
	cursor = &crtc->cursor;

	if(fbcursor->image.width > cursor->maxW ||
		fbcursor->image.height > cursor->maxH ||
		 fbcursor->image.depth > 1){
		return -ENXIO;
	}

	cursor->disable(cursor);
	if(fbcursor->set & FB_CUR_SETSIZE){
		cursor->setSize(cursor,fbcursor->image.width,fbcursor->image.height);
	}

	if(fbcursor->set & FB_CUR_SETPOS){
		cursor->setPos(cursor,fbcursor->image.dx - info->var.xoffset,
								fbcursor->image.dy - info->var.yoffset);
	}

	if(fbcursor->set & FB_CUR_SETCMAP){
		/* get the 16bit color of kernel means */
		u16 fg,bg;
		fg = ((info->cmap.red[fbcursor->image.fg_color] & 0xf800))|
				((info->cmap.green[fbcursor->image.fg_color] & 0xfc00) >> 5)|
				((info->cmap.blue[fbcursor->image.fg_color] & 0xf800) >> 11);

		bg = ((info->cmap.red[fbcursor->image.bg_color] & 0xf800))|
				((info->cmap.green[fbcursor->image.bg_color] & 0xfc00) >> 5)|
				((info->cmap.blue[fbcursor->image.bg_color] & 0xf800) >> 11);

		cursor->setColor(cursor,fg,bg);
	}


	if(fbcursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE))
	{
		cursor->setData(cursor,
						fbcursor->rop,
						fbcursor->image.data,
						fbcursor->mask);
	}

	if(fbcursor->enable){
		cursor->enable(cursor);
	}

	return 0;
}

static void lynxfb_ops_fillrect(struct fb_info* info,const struct fb_fillrect* region)
{
	struct lynxfb_par * par;
	struct lynx_share * share;
	unsigned int base,pitch,Bpp,rop;
	u32 color;

	if(info->state != FBINFO_STATE_RUNNING){
		return;
	}

	par = info->par;
	share = par->share;

	/* each time 2d function begin to work,below three variable always need
	 * be set, seems we can put them together in some place  */
	base = par->crtc.oScreen;
	pitch = info->fix.line_length;
	Bpp = info->var.bits_per_pixel >> 3;

	color = (Bpp == 1)?region->color:((u32*)info->pseudo_palette)[region->color];
	rop = ( region->rop != ROP_COPY ) ? HW_ROP2_XOR:HW_ROP2_COPY;

	myspin_lock(&share->slock);
	share->accel.de_fillrect(&share->accel,
							base,pitch,Bpp,
							region->dx,region->dy,
							region->width,region->height,
							color,rop);
	myspin_unlock(&share->slock);
}

static void lynxfb_ops_copyarea(struct fb_info * info,const struct fb_copyarea * region)
{
	struct lynxfb_par * par;
	struct lynx_share * share;
	unsigned int base,pitch,Bpp;

	par = info->par;
	share = par->share;

	/* each time 2d function begin to work,below three variable always need
	 * be set, seems we can put them together in some place  */
	base = par->crtc.oScreen;
	pitch = info->fix.line_length;
	Bpp = info->var.bits_per_pixel >> 3;

	myspin_lock(&share->slock);
	share->accel.de_copyarea(&share->accel,
							base,pitch,region->sx,region->sy,
							base,pitch,Bpp,region->dx,region->dy,
							region->width,region->height,HW_ROP2_COPY);
	myspin_unlock(&share->slock);
}

static void lynxfb_ops_imageblit(struct fb_info*info,const struct fb_image* image)
{
	unsigned int base,pitch,Bpp;
	unsigned int fgcol,bgcol;
	struct lynxfb_par * par;
	struct lynx_share * share;

	par = info->par;
	share = par->share;
	/* each time 2d function begin to work,below three variable always need
	 * be set, seems we can put them together in some place  */
	base = par->crtc.oScreen;
	pitch = info->fix.line_length;
	Bpp = info->var.bits_per_pixel >> 3;

	if(image->depth == 1){
		if(info->fix.visual == FB_VISUAL_TRUECOLOR ||
			info->fix.visual == FB_VISUAL_DIRECTCOLOR)
		{
			fgcol = ((u32*)info->pseudo_palette)[image->fg_color];
			bgcol = ((u32*)info->pseudo_palette)[image->bg_color];
		}
		else
		{
			fgcol = image->fg_color;
			bgcol = image->bg_color;
		}
		goto _do_work;
	}
	return;
_do_work:
	myspin_lock(&share->slock);
	share->accel.de_imageblit(&share->accel,
					image->data,image->width>>3,0,
					base,pitch,Bpp,
					image->dx,image->dy,
					image->width,image->height,
					fgcol,bgcol,HW_ROP2_COPY);
	myspin_unlock(&share->slock);
}

static int lynxfb_ops_pan_display(struct fb_var_screeninfo *var,
        struct fb_info *info)
{
    struct lynxfb_par * par;
    struct lynxfb_crtc * crtc;<commit_msg>staging: sm750fb: Remove spinlock helper function<commit_after>#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/errno.h>
#include<linux/string.h>
#include<linux/mm.h>
#include<linux/slab.h>
#include<linux/delay.h>
#include<linux/fb.h>
#include<linux/ioport.h>
#include<linux/init.h>
#include<linux/pci.h>
#include<linux/mm_types.h>
#include<linux/vmalloc.h>
#include<linux/pagemap.h>
#include<linux/screen_info.h>
#include<linux/vmalloc.h>
#include<linux/pagemap.h>
#include <linux/console.h>
#ifdef CONFIG_MTRR
#include <asm/mtrr.h>
#endif
#include <asm/fb.h>
#include "sm750.h"
#include "sm750_hw.h"
#include "sm750_accel.h"
#include "sm750_cursor.h"

#include "modedb.h"

int smi_indent = 0;


/*
#ifdef __BIG_ENDIAN
ssize_t lynxfb_ops_write(struct fb_info *info, const char __user *buf,
 	    size_t count, loff_t *ppos);
ssize_t lynxfb_ops_read(struct fb_info *info, char __user *buf,
			   size_t count, loff_t *ppos);
#endif
 */

typedef void (*PROC_SPEC_SETUP)(struct lynx_share*,char *);
typedef int (*PROC_SPEC_MAP)(struct lynx_share*,struct pci_dev*);
typedef int (*PROC_SPEC_INITHW)(struct lynx_share*,struct pci_dev*);


/* common var for all device */
static int g_hwcursor = 1;
static int g_noaccel;
#ifdef CONFIG_MTRR
static int g_nomtrr;
#endif
static const char * g_fbmode[] = {NULL,NULL};
static const char * g_def_fbmode = "800x600-16@60";
static char * g_settings = NULL;
static int g_dualview;
static char * g_option = NULL;

static const struct fb_videomode lynx750_ext[] = {
	/*  	1024x600-60 VESA 	[1.71:1]	*/
	{NULL,  60, 1024, 600, 20423, 144,  40, 18, 1, 104, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/* 	1024x600-70 VESA */
	{NULL,  70, 1024, 600, 17211, 152,  48, 21, 1, 104, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*  	1024x600-75 VESA */
	{NULL,  75, 1024, 600, 15822, 160,  56, 23, 1, 104, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*  	1024x600-85 VESA */
	{NULL,  85, 1024, 600, 13730, 168,  56, 26, 1, 112, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*	720x480	*/
	{NULL, 60,  720,  480,  37427, 88,   16, 13, 1,   72,  3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*	1280x720		[1.78:1]	*/
	{NULL, 60,  1280,  720,  13426, 162, 86, 22, 1,  136, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},

	/* 1280x768@60 */
	{NULL,60,1280,768,12579,192,64,20,3,128,7,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},

	{NULL,60,1360,768,11804,208,64,23,1,144,3,
	FB_SYNC_HOR_HIGH_ACT|FB_VMODE_NONINTERLACED},

	/*	1360 x 768	[1.77083:1]	*/
	{NULL,  60, 1360, 768, 11804, 208,  64, 23, 1, 144, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*	1368 x 768      [1.78:1]	*/
	{NULL, 60,  1368,  768,  11647, 216, 72, 23, 1,  144, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/* 	1440 x 900		[16:10]	*/
	{NULL, 60, 1440, 900, 9392, 232, 80, 28, 1, 152, 3,
	FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},

	/*	1440x960		[15:10]	*/
	{NULL, 60, 1440, 960, 8733, 240, 88, 30, 1, 152, 3,
	FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},

	/*	1920x1080	[16:9]	*/
	{NULL, 60, 1920, 1080, 6734, 148, 88, 41, 1, 44, 3,
	FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},
};




/* no hardware cursor supported under version 2.6.10, kernel bug */
static int lynxfb_ops_cursor(struct fb_info* info,struct fb_cursor* fbcursor)
{
	struct lynxfb_par * par;
	struct lynxfb_crtc * crtc;
	struct lynx_cursor * cursor;

	par = info->par;
	crtc = &par->crtc;
	cursor = &crtc->cursor;

	if(fbcursor->image.width > cursor->maxW ||
		fbcursor->image.height > cursor->maxH ||
		 fbcursor->image.depth > 1){
		return -ENXIO;
	}

	cursor->disable(cursor);
	if(fbcursor->set & FB_CUR_SETSIZE){
		cursor->setSize(cursor,fbcursor->image.width,fbcursor->image.height);
	}

	if(fbcursor->set & FB_CUR_SETPOS){
		cursor->setPos(cursor,fbcursor->image.dx - info->var.xoffset,
								fbcursor->image.dy - info->var.yoffset);
	}

	if(fbcursor->set & FB_CUR_SETCMAP){
		/* get the 16bit color of kernel means */
		u16 fg,bg;
		fg = ((info->cmap.red[fbcursor->image.fg_color] & 0xf800))|
				((info->cmap.green[fbcursor->image.fg_color] & 0xfc00) >> 5)|
				((info->cmap.blue[fbcursor->image.fg_color] & 0xf800) >> 11);

		bg = ((info->cmap.red[fbcursor->image.bg_color] & 0xf800))|
				((info->cmap.green[fbcursor->image.bg_color] & 0xfc00) >> 5)|
				((info->cmap.blue[fbcursor->image.bg_color] & 0xf800) >> 11);

		cursor->setColor(cursor,fg,bg);
	}


	if(fbcursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE))
	{
		cursor->setData(cursor,
						fbcursor->rop,
						fbcursor->image.data,
						fbcursor->mask);
	}

	if(fbcursor->enable){
		cursor->enable(cursor);
	}

	return 0;
}

static void lynxfb_ops_fillrect(struct fb_info* info,const struct fb_fillrect* region)
{
	struct lynxfb_par * par;
	struct lynx_share * share;
	unsigned int base,pitch,Bpp,rop;
	u32 color;

	if(info->state != FBINFO_STATE_RUNNING){
		return;
	}

	par = info->par;
	share = par->share;

	/* each time 2d function begin to work,below three variable always need
	 * be set, seems we can put them together in some place  */
	base = par->crtc.oScreen;
	pitch = info->fix.line_length;
	Bpp = info->var.bits_per_pixel >> 3;

	color = (Bpp == 1)?region->color:((u32*)info->pseudo_palette)[region->color];
	rop = ( region->rop != ROP_COPY ) ? HW_ROP2_XOR:HW_ROP2_COPY;

	/*
	 * If not use spin_lock,system will die if user load driver
	 * and immediatly unload driver frequently (dual)
	 */
	if (share->dual)
		spin_lock(&share->slock);

	share->accel.de_fillrect(&share->accel,
							base,pitch,Bpp,
							region->dx,region->dy,
							region->width,region->height,
							color,rop);

	if (share->dual)
		spin_unlock(&share->slock);
}

static void lynxfb_ops_copyarea(struct fb_info * info,const struct fb_copyarea * region)
{
	struct lynxfb_par * par;
	struct lynx_share * share;
	unsigned int base,pitch,Bpp;

	par = info->par;
	share = par->share;

	/* each time 2d function begin to work,below three variable always need
	 * be set, seems we can put them together in some place  */
	base = par->crtc.oScreen;
	pitch = info->fix.line_length;
	Bpp = info->var.bits_per_pixel >> 3;

	/*
	 * If not use spin_lock, system will die if user load driver
	 * and immediatly unload driver frequently (dual)
	 */
	if (share->dual)
		spin_lock(&share->slock);

	share->accel.de_copyarea(&share->accel,
							base,pitch,region->sx,region->sy,
							base,pitch,Bpp,region->dx,region->dy,
							region->width,region->height,HW_ROP2_COPY);

	if (share->dual)
		spin_unlock(&share->slock);
}

static void lynxfb_ops_imageblit(struct fb_info*info,const struct fb_image* image)
{
	unsigned int base,pitch,Bpp;
	unsigned int fgcol,bgcol;
	struct lynxfb_par * par;
	struct lynx_share * share;

	par = info->par;
	share = par->share;
	/* each time 2d function begin to work,below three variable always need
	 * be set, seems we can put them together in some place  */
	base = par->crtc.oScreen;
	pitch = info->fix.line_length;
	Bpp = info->var.bits_per_pixel >> 3;

	if(image->depth == 1){
		if(info->fix.visual == FB_VISUAL_TRUECOLOR ||
			info->fix.visual == FB_VISUAL_DIRECTCOLOR)
		{
			fgcol = ((u32*)info->pseudo_palette)[image->fg_color];
			bgcol = ((u32*)info->pseudo_palette)[image->bg_color];
		}
		else
		{
			fgcol = image->fg_color;
			bgcol = image->bg_color;
		}
		goto _do_work;
	}
	return;
_do_work:
	/*
	 * If not use spin_lock, system will die if user load driver
	 * and immediatly unload driver frequently (dual)
	 */
	if (share->dual)
		spin_lock(&share->slock);

	share->accel.de_imageblit(&share->accel,
					image->data,image->width>>3,0,
					base,pitch,Bpp,
					image->dx,image->dy,
					image->width,image->height,
					fgcol,bgcol,HW_ROP2_COPY);

	if (share->dual)
		spin_unlock(&share->slock);
}

static int lynxfb_ops_pan_display(struct fb_var_screeninfo *var,
        struct fb_info *info)
{
    struct lynxfb_par * par;
    struct lynxfb_crtc * crtc;
{'fraction_non_alphanumeric': 0.14785872507999015, 'fraction_numerical': 0.0670071375830667, 'mean_word_length': 4.376447237843202, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 283, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4715591', 'n_tokens_mistral': 8044, 'n_tokens_neox': 6797, 'n_words': 1336}