From 0297c08b8e24615591decd1ea3a2f25c8a4c2c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Sun, 29 Dec 2013 08:58:58 +0000 Subject: [PATCH] more dependencies resolved --- bas.lk.in | 2 + include/bas_string.h | 1 + include/fb.h | 2 +- include/radeonfb.h | 3 +- include/wait.h | 8 +++ include/x86regs.h | 11 +-- radeon/radeon_base.c | 13 ++-- radeon/radeon_monitor.c | 145 ++++++++++++++++++++-------------------- util/bas_string.c | 13 ++++ video/fbmem.c | 134 ++++++++++++------------------------- x86emu/biosemu.c | 108 ++++++++++-------------------- 11 files changed, 191 insertions(+), 249 deletions(-) diff --git a/bas.lk.in b/bas.lk.in index 2d5e2d4..a0dc1b7 100644 --- a/bas.lk.in +++ b/bas.lk.in @@ -83,6 +83,8 @@ SECTIONS OBJDIR/videl.o OBJDIR/fbmem.o + OBJDIR/biosemu.o + OBJDIR/radeon_base.o OBJDIR/radeon_accel.o OBJDIR/radeon_cursor.o diff --git a/include/bas_string.h b/include/bas_string.h index a0c3433..67491f2 100644 --- a/include/bas_string.h +++ b/include/bas_string.h @@ -28,6 +28,7 @@ extern int strncmp(const char *s1, const char *s2, size_t max); extern char *strcpy(char *dst, const char *src); char *strncpy(char *dst, const char *src, size_t max); +extern int strcmp(const char *s1, const char *s2); extern size_t strlen(const char *str); extern char *strcat(char *dst, const char *src); extern char *strncat(char *dst, const char *src, size_t max); diff --git a/include/fb.h b/include/fb.h index 7728186..c82449c 100644 --- a/include/fb.h +++ b/include/fb.h @@ -468,7 +468,7 @@ struct fb_info { extern int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var); extern int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var); extern int fb_blank(struct fb_info *info, int blank); -extern int fb_ioctl(unsigned int cmd, unsigned long arg); +extern int fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg); extern struct fb_info *framebuffer_alloc(unsigned long size); extern void framebuffer_release(struct fb_info *info); diff --git a/include/radeonfb.h b/include/radeonfb.h index 4b69ee5..8a2494e 100644 --- a/include/radeonfb.h +++ b/include/radeonfb.h @@ -9,6 +9,7 @@ #include "i2c.h" #include "i2c-algo-bit.h" #include "util.h" /* for swpX() */ +#include "wait.h" //#include "radeon_theatre.h" #include "radeon_reg.h" @@ -470,7 +471,7 @@ struct radeonfb_info */ static inline void _radeon_msleep(struct radeonfb_info *rinfo, uint32_t ms) { - mdelay(ms); + wait_ms(ms); } #define radeon_msleep(ms) _radeon_msleep(rinfo,ms) diff --git a/include/wait.h b/include/wait.h index 26a2e19..347fadf 100644 --- a/include/wait.h +++ b/include/wait.h @@ -41,6 +41,7 @@ typedef bool (*checker_func)(void); extern __inline__ void wait(uint32_t) __attribute__((always_inline)); extern __inline__ bool waitfor(uint32_t us, checker_func condition) __attribute__((always_inline)); + /* * wait for the specified number of us on slice timer 0. Replaces the original routines that had * the number of useconds to wait for hardcoded in their name. @@ -52,6 +53,13 @@ extern __inline__ void wait(uint32_t us) while (MCF_SLT_SCNT(0) - target > 0); } +/* + * same as above, but with milliseconds wait time + */ +extern __inline__ void wait_ms(uint32_t ms) +{ + wait(ms * 1000); +} /* * the same as above, with a checker function which gets called while * busy waiting and allows for an early return if it returns true diff --git a/include/x86regs.h b/include/x86regs.h index a5a73bc..b8f2dcc 100644 --- a/include/x86regs.h +++ b/include/x86regs.h @@ -315,12 +315,13 @@ typedef struct { extern "C" { /* Use "C" linkage when in C++ mode */ #endif - /* Global emulator machine state. - * - * We keep it global to avoid pointer dereferences in the code for speed. - */ +/* Global emulator machine state. + * + * We keep it global to avoid pointer dereferences in the code for speed. + */ + +extern X86EMU_sysEnv _X86EMU_env; - extern X86EMU_sysEnv _X86EMU_env; #define M _X86EMU_env #define X86_EAX M.x86.R_EAX diff --git a/radeon/radeon_base.c b/radeon/radeon_base.c index 312451e..50a625c 100644 --- a/radeon/radeon_base.c +++ b/radeon/radeon_base.c @@ -57,6 +57,7 @@ #include "radeonfb.h" #include "edid.h" #include "ati_ids.h" +#include "driver_mem.h" #include "bas_printf.h" #include "exceptions.h" /* for set_ipl() */ @@ -68,8 +69,6 @@ #endif /* DBG_RADEON */ extern void run_bios(struct radeonfb_info *rinfo); -extern void mdelay(int32_t msec); -extern void udelay(int32_t usec); #define MAX_MAPPED_VRAM (2048*2048*4) #define MIN_MAPPED_VRAM (1024*768*4) @@ -1011,7 +1010,7 @@ int32_t radeon_screen_blank(struct radeonfb_info *rinfo, int32_t blank, int32_t OUTPLLP(PIXCLKS_CNTL, 0, ~PIXCLK_LVDS_ALWAYS_ONb); val &= ~(LVDS_BL_MOD_EN); OUTREG(LVDS_GEN_CNTL, val); - udelay(100); + wait(100); val &= ~(LVDS_ON | LVDS_EN); OUTREG(LVDS_GEN_CNTL, val); val &= ~LVDS_DIGON; @@ -1525,7 +1524,7 @@ int radeonfb_set_par(struct fb_info *info) int depth = var_to_depth(mode); int use_rmx = 0; - newmode = (struct radeon_regs *)Funcs_malloc(sizeof(struct radeon_regs),3); + newmode = (struct radeon_regs *) driver_mem_alloc(sizeof(struct radeon_regs)); if (!newmode) return -1; //-ENOMEM; /* We always want engine to be idle on a mode switch, even @@ -1774,7 +1773,7 @@ int radeonfb_set_par(struct fb_info *info) /* Update fix */ info->fix.line_length = rinfo->pitch*64; info->fix.visual = rinfo->depth == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; - Funcs_free(newmode); + driver_mem_free(newmode); return 0; } @@ -2186,9 +2185,9 @@ void radeonfb_pci_unregister(void) // radeonfb_pm_exit(rinfo); uninstall_vbl_timer(radeon_timer_func); if (rinfo->mon1_EDID!=NULL) - Funcs_free(rinfo->mon1_EDID); + driver_mem_free(rinfo->mon1_EDID); if (rinfo->mon2_EDID!=NULL) - Funcs_free(rinfo->mon2_EDID); + driver_mem_free(rinfo->mon2_EDID); if (rinfo->mon1_modedb) fb_destroy_modedb(rinfo->mon1_modedb); #ifdef CONFIG_FB_RADEON_I2C diff --git a/radeon/radeon_monitor.c b/radeon/radeon_monitor.c index 34ba83d..9a82543 100644 --- a/radeon/radeon_monitor.c +++ b/radeon/radeon_monitor.c @@ -1,5 +1,8 @@ #include "radeonfb.h" +#include "wait.h" #include "edid.h" +#include "driver_mem.h" +#include "bas_string.h" #define DBG_MONITOR #ifdef DBG_MONITOR @@ -72,7 +75,7 @@ static int radeon_crt_is_connected(struct radeonfb_info *rinfo, int is_crt_dac) /* the monitor either wasn't connected or it is a non-DDC CRT. * try to probe it */ - if(is_crt_dac) + if (is_crt_dac) { unsigned long ulOrigVCLK_ECP_CNTL; unsigned long ulOrigDAC_CNTL; @@ -93,7 +96,7 @@ static int radeon_crt_is_connected(struct radeonfb_info *rinfo, int is_crt_dac) ulData = ulOrigDAC_EXT_CNTL; ulData &= ~DAC_FORCE_DATA_MASK; ulData |= (DAC_FORCE_BLANK_OFF_EN | DAC_FORCE_DATA_EN | DAC_FORCE_DATA_SEL_MASK); - if((rinfo->family == CHIP_FAMILY_RV250) || (rinfo->family == CHIP_FAMILY_RV280)) + if ((rinfo->family == CHIP_FAMILY_RV250) || (rinfo->family == CHIP_FAMILY_RV280)) ulData |= (0x01b6 << DAC_FORCE_DATA_SHIFT); else ulData |= (0x01ac << DAC_FORCE_DATA_SHIFT); @@ -104,7 +107,7 @@ static int radeon_crt_is_connected(struct radeonfb_info *rinfo, int is_crt_dac) ulData &= ~(DAC_RANGE_CNTL_MASK | DAC_PDWN); ulData |= 0x2; OUTREG(DAC_CNTL, ulData); - mdelay(1); + wait_ms(1); ulData = INREG(DAC_CNTL); connected = (DAC_CMP_OUTPUT & ulData) ? 1 : 0; ulData = ulOrigVCLK_ECP_CNTL; @@ -126,7 +129,7 @@ static int radeon_parse_monitor_layout(struct radeonfb_info *rinfo, const char * char s1[5], s2[5]; int i = 0, second = 0; const char *s; - if((monitor_layout == NULL) || (*monitor_layout == '\0')) + if ((monitor_layout == NULL) || (*monitor_layout == '\0')) return 0; s = monitor_layout; do @@ -142,9 +145,9 @@ static int radeon_parse_monitor_layout(struct radeonfb_info *rinfo, const char * case '\0': break; default: - if(i >= 4) + if (i >= 4) break; - if(second) + if (second) s2[i] = *s; else s1[i] = *s; @@ -153,24 +156,24 @@ static int radeon_parse_monitor_layout(struct radeonfb_info *rinfo, const char * } } while(*s++); - if(second) + if (second) s2[i] = '\0'; else { s1[i] = '\0'; s2[0] = '\0'; } - if(Funcs_equal(s1, "CRT")) + if (strcmp(s1, "CRT")) rinfo->mon1_type = MT_CRT; - else if(Funcs_equal(s1, "TMDS")) + else if (strcmp(s1, "TMDS")) rinfo->mon1_type = MT_DFP; - else if(Funcs_equal(s1, "LVDS")) + else if (strcmp(s1, "LVDS")) rinfo->mon1_type = MT_LCD; - if(Funcs_equal(s2, "CRT")) + if (strcmp(s2, "CRT")) rinfo->mon2_type = MT_CRT; - else if(Funcs_equal(s2, "TMDS")) + else if (strcmp(s2, "TMDS")) rinfo->mon2_type = MT_DFP; - else if(Funcs_equal(s2, "LVDS")) + else if (strcmp(s2, "LVDS")) rinfo->mon2_type = MT_LCD; return 1; } @@ -186,7 +189,7 @@ void radeon_probe_screens(struct radeonfb_info *rinfo, #ifdef CONFIG_FB_RADEON_I2C int ddc_crt2_used = 0; #endif - if(radeon_parse_monitor_layout(rinfo, monitor_layout)) + if (radeon_parse_monitor_layout(rinfo, monitor_layout)) { /* * If user specified a monitor_layout option, use it instead @@ -196,22 +199,22 @@ void radeon_probe_screens(struct radeonfb_info *rinfo, */ #ifdef CONFIG_FB_RADEON_I2C dbg("radeonfb: radeon_probe_screens: use monitor layout\r\n"); - if(!ignore_edid) + if (!ignore_edid) { - if(rinfo->mon1_type != MT_NONE) + if (rinfo->mon1_type != MT_NONE) { dbg("radeonfb: radeon_probe_screens: probe ddc_dvi on MON1\r\n"); - if(!radeon_probe_i2c_connector(rinfo, ddc_dvi, &rinfo->mon1_EDID)) + if (!radeon_probe_i2c_connector(rinfo, ddc_dvi, &rinfo->mon1_EDID)) { dbg("radeonfb: radeon_probe_screens: probe ddc_crt2 on MON1\r\n"); radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon1_EDID); ddc_crt2_used = 1; } } - if(rinfo->mon2_type != MT_NONE) + if (rinfo->mon2_type != MT_NONE) { dbg("radeonfb: radeon_probe_screens: probe ddc_vga on MON2\r\n"); - if(!radeon_probe_i2c_connector(rinfo, ddc_vga, &rinfo->mon2_EDID) && !ddc_crt2_used) + if (!radeon_probe_i2c_connector(rinfo, ddc_vga, &rinfo->mon2_EDID) && !ddc_crt2_used) { dbg("radeonfb: radeon_probe_screens: probe ddc_crt2 on MON2\r\n"); radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon2_EDID); @@ -219,9 +222,9 @@ void radeon_probe_screens(struct radeonfb_info *rinfo, } } #endif /* CONFIG_FB_RADEON_I2C */ - if(rinfo->mon1_type == MT_NONE) + if (rinfo->mon1_type == MT_NONE) { - if(rinfo->mon2_type != MT_NONE) + if (rinfo->mon2_type != MT_NONE) { rinfo->mon1_type = rinfo->mon2_type; rinfo->mon1_EDID = rinfo->mon2_EDID; @@ -255,26 +258,26 @@ void radeon_probe_screens(struct radeonfb_info *rinfo, /* * Old single head cards */ - if(!rinfo->has_CRTC2) + if (!rinfo->has_CRTC2) { #ifdef CONFIG_FB_RADEON_I2C - if(rinfo->mon1_type == MT_NONE) + if (rinfo->mon1_type == MT_NONE) { dbg("radeonfb: radeon_probe_screens: probe ddc_dvi on MON1\r\n"); rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_dvi, &rinfo->mon1_EDID); } - if(rinfo->mon1_type == MT_NONE) + if (rinfo->mon1_type == MT_NONE) { dbg("radeonfb: radeon_probe_screens: probe ddc_vga on MON1\r\n"); rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_vga, &rinfo->mon1_EDID); } - if(rinfo->mon1_type == MT_NONE) + if (rinfo->mon1_type == MT_NONE) { dbg("radeonfb: radeon_probe_screens: probe ddc_crt2 on MON1\r\n"); rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon1_EDID); } #endif /* CONFIG_FB_RADEON_I2C */ - if(rinfo->mon1_type == MT_NONE) + if (rinfo->mon1_type == MT_NONE) rinfo->mon1_type = MT_CRT; goto bail; } @@ -282,52 +285,52 @@ void radeon_probe_screens(struct radeonfb_info *rinfo, * Probe primary head (DVI or laptop internal panel) */ #ifdef CONFIG_FB_RADEON_I2C - if(rinfo->mon1_type == MT_NONE) + if (rinfo->mon1_type == MT_NONE) { dbg("radeonfb: radeon_probe_screens: probe ddc_dvi on MON1\r\n"); rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_dvi, &rinfo->mon1_EDID); } - if(rinfo->mon1_type == MT_NONE) + if (rinfo->mon1_type == MT_NONE) { dbg("radeonfb: radeon_probe_screens: probe ddc_crt2 on MON1\r\n"); rinfo->mon1_type = radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon1_EDID); - if(rinfo->mon1_type != MT_NONE) + if (rinfo->mon1_type != MT_NONE) ddc_crt2_used = 1; } #endif /* CONFIG_FB_RADEON_I2C */ - if(rinfo->mon1_type == MT_NONE && rinfo->is_mobility + if (rinfo->mon1_type == MT_NONE && rinfo->is_mobility && (INREG(LVDS_GEN_CNTL) & LVDS_ON)) { rinfo->mon1_type = MT_LCD; dbg("Non-DDC laptop panel detected\r\n"); } - if(rinfo->mon1_type == MT_NONE) + if (rinfo->mon1_type == MT_NONE) rinfo->mon1_type = radeon_crt_is_connected(rinfo, rinfo->reversed_DAC); /* * Probe secondary head (mostly VGA, can be DVI) */ #ifdef CONFIG_FB_RADEON_I2C - if(rinfo->mon2_type == MT_NONE) + if (rinfo->mon2_type == MT_NONE) { dbg("radeonfb: radeon_probe_screens: probe ddc_vga on MON2\r\n"); rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_vga, &rinfo->mon2_EDID); } - if(rinfo->mon2_type == MT_NONE && !ddc_crt2_used) + if (rinfo->mon2_type == MT_NONE && !ddc_crt2_used) { dbg("radeonfb: radeon_probe_screens: probe ddc_crt2 on MON2\r\n"); rinfo->mon2_type = radeon_probe_i2c_connector(rinfo, ddc_crt2, &rinfo->mon2_EDID); } #endif /* CONFIG_FB_RADEON_I2C */ - if(rinfo->mon2_type == MT_NONE) + if (rinfo->mon2_type == MT_NONE) rinfo->mon2_type = radeon_crt_is_connected(rinfo, !rinfo->reversed_DAC); /* * If we only detected port 2, we swap them, if none detected, * assume CRT (maybe fallback to old BIOS_SCRATCH stuff ? or look * at FP registers ?) */ - if(rinfo->mon1_type == MT_NONE) + if (rinfo->mon1_type == MT_NONE) { - if(rinfo->mon2_type != MT_NONE) + if (rinfo->mon2_type != MT_NONE) { rinfo->mon1_type = rinfo->mon2_type; rinfo->mon1_EDID = rinfo->mon2_EDID; @@ -340,10 +343,10 @@ void radeon_probe_screens(struct radeonfb_info *rinfo, /* * Deal with reversed TMDS */ - if(rinfo->reversed_TMDS) + if (rinfo->reversed_TMDS) { /* Always keep internal TMDS as primary head */ - if(rinfo->mon1_type == MT_DFP || rinfo->mon2_type == MT_DFP) + if (rinfo->mon1_type == MT_DFP || rinfo->mon2_type == MT_DFP) { int tmp_type = rinfo->mon1_type; unsigned char *tmp_EDID = rinfo->mon1_EDID; @@ -351,28 +354,28 @@ void radeon_probe_screens(struct radeonfb_info *rinfo, rinfo->mon1_EDID = rinfo->mon2_EDID; rinfo->mon2_type = tmp_type; rinfo->mon2_EDID = tmp_EDID; - if(rinfo->mon1_type == MT_CRT || rinfo->mon2_type == MT_CRT) + if (rinfo->mon1_type == MT_CRT || rinfo->mon2_type == MT_CRT) rinfo->reversed_DAC ^= 1; } } } - if(ignore_edid) + if (ignore_edid) { - Funcs_free(rinfo->mon1_EDID); + driver_mem_free(rinfo->mon1_EDID); rinfo->mon1_EDID = NULL; - Funcs_free(rinfo->mon2_EDID); + driver_mem_free(rinfo->mon2_EDID); rinfo->mon2_EDID = NULL; } bail: dbg("radeonfb: Monitor 1 type %s found\r\n", radeon_get_mon_name(rinfo->mon1_type)); - if(rinfo->mon1_EDID) + if (rinfo->mon1_EDID) { dbg("radeonfb: EDID probed\r\n"); } - if(!rinfo->has_CRTC2) + if (!rinfo->has_CRTC2) return; dbg("radeonfb: Monitor 2 type %s\r\n", radeon_get_mon_name(rinfo->mon2_type)); - if(rinfo->mon2_EDID) + if (rinfo->mon2_EDID) { dbg("radeonfb: EDID probed\r\n"); } @@ -443,14 +446,14 @@ void radeon_check_modes(struct radeonfb_info *rinfo, struct mode_option *resolut * we only deal with first entry returned by parse_EDID, we may do better * some day... */ - if(!rinfo->panel_info.use_bios_dividers + if (!rinfo->panel_info.use_bios_dividers && rinfo->mon1_type != MT_CRT && rinfo->mon1_EDID) { struct fb_var_screeninfo var; dbg("radeonfb: radeon_check_modes: fb_parse_edid\r\n"); - if(fb_parse_edid(rinfo->mon1_EDID, &var) == 0) + if (fb_parse_edid(rinfo->mon1_EDID, &var) == 0) { - if((var.xres >= rinfo->panel_info.xres) && (var.yres >= rinfo->panel_info.yres)) + if ((var.xres >= rinfo->panel_info.xres) && (var.yres >= rinfo->panel_info.yres)) radeon_var_to_panel_info(rinfo, &var); } else @@ -462,7 +465,7 @@ void radeon_check_modes(struct radeonfb_info *rinfo, struct mode_option *resolut * If we have some valid panel infos, we setup the default mode based on * those */ - if(rinfo->mon1_type != MT_CRT && rinfo->panel_info.valid) + if (rinfo->mon1_type != MT_CRT && rinfo->panel_info.valid) { struct fb_var_screeninfo *var = &info->var; dbg("radeonfb: radeon_check_modes: setup the default mode based on panel info\r\n"); @@ -480,9 +483,9 @@ void radeon_check_modes(struct radeonfb_info *rinfo, struct mode_option *resolut var->hsync_len = rinfo->panel_info.hSync_width; var->vsync_len = rinfo->panel_info.vSync_width; var->sync = 0; - if(rinfo->panel_info.hAct_high) + if (rinfo->panel_info.hAct_high) var->sync |= FB_SYNC_HOR_HIGH_ACT; - if(rinfo->panel_info.vAct_high) + if (rinfo->panel_info.vAct_high) var->sync |= FB_SYNC_VERT_HIGH_ACT; var->vmode = 0; has_default_mode = 1; @@ -490,7 +493,7 @@ void radeon_check_modes(struct radeonfb_info *rinfo, struct mode_option *resolut /* * Now build modedb from EDID */ - if(rinfo->mon1_EDID) + if (rinfo->mon1_EDID) { fb_edid_to_monspecs(rinfo->mon1_EDID, &info->monspecs); rinfo->mon1_modedb = info->monspecs.modedb; @@ -501,18 +504,18 @@ void radeon_check_modes(struct radeonfb_info *rinfo, struct mode_option *resolut * we try to read it from card), we try to pick a default mode * and create some panel infos. Whatever... */ - if(rinfo->mon1_type != MT_CRT && !rinfo->panel_info.valid) + if (rinfo->mon1_type != MT_CRT && !rinfo->panel_info.valid) { struct fb_videomode *modedb; int dbsize; - if(rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) + if (rinfo->panel_info.xres == 0 || rinfo->panel_info.yres == 0) { unsigned long tmp = INREG(FP_HORZ_STRETCH) & HORZ_PANEL_SIZE; rinfo->panel_info.xres = ((tmp >> HORZ_PANEL_SHIFT) + 1) * 8; tmp = INREG(FP_VERT_STRETCH) & VERT_PANEL_SIZE; rinfo->panel_info.yres = (tmp >> VERT_PANEL_SHIFT) + 1; } - if((rinfo->panel_info.xres <= 8) || (rinfo->panel_info.yres <= 1)) + if ((rinfo->panel_info.xres <= 8) || (rinfo->panel_info.yres <= 1)) { rinfo->mon1_type = MT_CRT; goto pickup_default; @@ -523,7 +526,7 @@ void radeon_check_modes(struct radeonfb_info *rinfo, struct mode_option *resolut xres_yres.width = rinfo->panel_info.xres; xres_yres.height = rinfo->panel_info.yres; xres_yres.bpp = xres_yres.freq = 0; - if(fb_find_mode(&info->var, info, &xres_yres, modedb, dbsize, NULL, (resolution->bpp >= 8) ? (unsigned int)resolution->bpp : 8) == 0) + if (fb_find_mode(&info->var, info, &xres_yres, modedb, dbsize, NULL, (resolution->bpp >= 8) ? (unsigned int)resolution->bpp : 8) == 0) { rinfo->mon1_type = MT_CRT; goto pickup_default; @@ -535,26 +538,26 @@ pickup_default: /* * Apply passed-in mode option if any */ - if(resolution->used) + if (resolution->used) { - if(fb_find_mode(&info->var, info, resolution, info->monspecs.modedb, + if (fb_find_mode(&info->var, info, resolution, info->monspecs.modedb, info->monspecs.modedb_len, NULL, (resolution->bpp >= 8) ? (unsigned int)resolution->bpp : 8) != 0) has_default_mode = 1; } /* * Still no mode, let's pick up a default from the db */ - if(!has_default_mode && info->monspecs.modedb != NULL) + if (!has_default_mode && info->monspecs.modedb != NULL) { struct fb_monspecs *specs = &info->monspecs; struct fb_videomode *modedb = NULL; /* get preferred timing */ - if(specs->misc & FB_MISC_1ST_DETAIL) + if (specs->misc & FB_MISC_1ST_DETAIL) { int i; for(i = 0; i < specs->modedb_len; i++) { - if(specs->modedb[i].flag & FB_MODE_IS_FIRST) + if (specs->modedb[i].flag & FB_MODE_IS_FIRST) { modedb = &specs->modedb[i]; break; @@ -566,7 +569,7 @@ pickup_default: /* otherwise, get first mode in database */ modedb = &specs->modedb[0]; } - if(modedb != NULL) + if (modedb != NULL) { info->var.bits_per_pixel = 8; radeon_videomode_to_var(&info->var, modedb); @@ -614,7 +617,7 @@ int radeon_match_mode(struct radeonfb_info *rinfo, /* Start with a copy of the requested mode */ memcpy(dest, src, sizeof(struct fb_var_screeninfo)); /* Check if we have a modedb built from EDID */ - if(rinfo->mon1_modedb) + if (rinfo->mon1_modedb) { db = rinfo->mon1_modedb; dbsize = rinfo->mon1_dbsize; @@ -626,7 +629,7 @@ int radeon_match_mode(struct radeonfb_info *rinfo, * FB_ACTIVATE_NOW, just do basic checking and return if the * mode match */ - if((src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST + if ((src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST || (src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) { /* We don't have an RMX, validate timings. If we don't have @@ -634,9 +637,9 @@ int radeon_match_mode(struct radeonfb_info *rinfo, * 640x480-60, but I assume userland knows what it's doing here * (though I may be proven wrong...) */ - if((has_rmx == 0) && rinfo->mon1_modedb) + if ((has_rmx == 0) && rinfo->mon1_modedb) { - if(fb_validate_mode((struct fb_var_screeninfo *)src, rinfo->info)) + if (fb_validate_mode((struct fb_var_screeninfo *)src, rinfo->info)) return -1; //-EINVAL; } return 0; @@ -648,13 +651,13 @@ int radeon_match_mode(struct radeonfb_info *rinfo, for(i = 0; i < dbsize; i++) { int d; - if((db[i].yres < src->yres) || (db[i].xres < src->xres)) + if ((db[i].yres < src->yres) || (db[i].xres < src->xres)) continue; d = radeon_compare_modes(src, &db[i]); /* If the new mode is at least as good as the previous one, * then it's our new candidate */ - if(d < distance) + if (d < distance) { candidate = &db[i]; distance = d; @@ -662,7 +665,7 @@ int radeon_match_mode(struct radeonfb_info *rinfo, } db = NULL; /* If we have a scaler, we allow any mode from the database */ - if(native_db && has_rmx) + if (native_db && has_rmx) { db = vesa_modes; dbsize = 34; @@ -670,13 +673,13 @@ int radeon_match_mode(struct radeonfb_info *rinfo, } } /* If we have found a match, return it */ - if(candidate != NULL) + if (candidate != NULL) { radeon_videomode_to_var(dest, candidate); return 0; } /* If we haven't and don't have a scaler, fail */ - if(!has_rmx) + if (!has_rmx) return -1; //-EINVAL; return 0; } diff --git a/util/bas_string.c b/util/bas_string.c index d39aaec..9dd12e1 100644 --- a/util/bas_string.c +++ b/util/bas_string.c @@ -68,6 +68,19 @@ int memcmp(const char *s1, const char *s2, size_t max) return cmp; } +int strcmp(const char *s1, const char *s2) +{ + int i; + int cmp; + + for (i = 0; *s1++ && *s2++; i++) + { + cmp * (*s1 - *s2); + if (cmp != 0) return cmp; + } + return cmp; +} + int strncmp(const char *s1, const char *s2, size_t max) { int i; diff --git a/video/fbmem.c b/video/fbmem.c index 8ff20a7..d0787c1 100644 --- a/video/fbmem.c +++ b/video/fbmem.c @@ -11,15 +11,25 @@ * for more details. */ -#include +#include "bas_types.h" +#include "bas_printf.h" +#include "bas_string.h" #include "fb.h" #include "radeonfb.h" +#include "driver_mem.h" + +#define DBG_FBMEM +#ifdef DBG_FBMEM +#define dbg(format, arg...) do { xprintf("DEBUG: " format, ##arg); } while (0) +#else +#define dbg(format, arg...) do { ; } while (0) +#endif /* DBG_FBMEM */ long mem_cmp(char *p1, char *p2, long size) { while(size--) { - if(*p1++ != *p2++) + if (*p1++ != *p2++) return(1); } return(0); @@ -37,14 +47,14 @@ int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var) int yoffset = var->yoffset; int err; // DPRINT("fb_pan_display\r\n"); - if((xoffset < 0) || (yoffset < 0) + if ((xoffset < 0) || (yoffset < 0) || ((xoffset + info->var.xres) > info->var.xres_virtual)) return -1; //-EINVAL; - if((err = info->fbops->fb_pan_display(var, info))) + if ((err = info->fbops->fb_pan_display(var, info))) return err; info->var.xoffset = var->xoffset; info->var.yoffset = var->yoffset; - if(var->vmode & FB_VMODE_YWRAP) + if (var->vmode & FB_VMODE_YWRAP) info->var.vmode |= FB_VMODE_YWRAP; else info->var.vmode &= ~FB_VMODE_YWRAP; @@ -55,15 +65,15 @@ int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) { int err; // DPRINT("fb_set_var\r\n"); - if(var->activate & FB_ACTIVATE_INV_MODE) + if (var->activate & FB_ACTIVATE_INV_MODE) /* return 1 if equal */ return(!mem_cmp((char *)&info->var, (char *)var, sizeof(struct fb_var_screeninfo))); - if((var->activate & FB_ACTIVATE_FORCE) + if ((var->activate & FB_ACTIVATE_FORCE) || mem_cmp((char *)&info->var, (char *)var, sizeof(struct fb_var_screeninfo))) { - if((err = info->fbops->fb_check_var(var, info))) + if ((err = info->fbops->fb_check_var(var, info))) return err; - if((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) + if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) { memcpy(&info->var, var, sizeof(struct fb_var_screeninfo)); info->fbops->fb_set_par(info); @@ -75,19 +85,19 @@ int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) int fb_blank(struct fb_info *info, int blank) { - // DPRINT("fb_blank\r\n"); - if(blank > FB_BLANK_POWERDOWN) + dbg("fb_blank\r\n"); + if (blank > FB_BLANK_POWERDOWN) blank = FB_BLANK_POWERDOWN; return(info->fbops->fb_blank(blank, info)); } -int fb_ioctl(unsigned int cmd, unsigned long arg) +int fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { - struct fb_info *info = info_fvdi; struct fb_var_screeninfo var; struct fb_fix_screeninfo fix; - void *argp = (void *)arg; + void *argp = (void *) arg; int i; + switch(cmd) { case FBIOGET_VSCREENINFO: @@ -96,7 +106,7 @@ int fb_ioctl(unsigned int cmd, unsigned long arg) case FBIOPUT_VSCREENINFO: memcpy(&var, argp, sizeof(var)); i = fb_set_var(info, &var); - if(i) + if (i) return i; memcpy(argp, &var, sizeof(var)); return 0; @@ -106,7 +116,7 @@ int fb_ioctl(unsigned int cmd, unsigned long arg) case FBIOPAN_DISPLAY: memcpy(&var, argp, sizeof(var)); i = fb_pan_display(info, &var); - if(i) + if (i) return i; memcpy(argp, &var, sizeof(var)); return 0; @@ -123,10 +133,6 @@ int fb_ioctl(unsigned int cmd, unsigned long arg) } -#if 1 - -static struct radeonfb_info struct_radeon_info; - /** * framebuffer_alloc - creates a new frame buffer info structure * @@ -142,24 +148,23 @@ static struct radeonfb_info struct_radeon_info; */ struct fb_info *framebuffer_alloc(unsigned long size) { - static struct fb_info struct_info; - struct fb_info *info = &struct_info; - memset(info, 0, sizeof(struct fb_info)); - if(size) + struct fb_info *info = driver_mem_alloc(sizeof(struct fb_info)); + + if (info == NULL) { - if(size <= sizeof(struct radeonfb_info)) - { - memset(&struct_radeon_info, 0, sizeof(struct radeonfb_info)); - info->par = (void *)&struct_radeon_info; - } - else - { - char *p = Funcs_malloc(size, 3); - if(!p) - return NULL; - memset(p, 0, size); - info->par = p; - } + dbg("%s: could not allocate fb_info structure\r\n", __FUNCTION__); + return 0; + } + memset(info, 0, sizeof(struct fb_info)); + + if (size) + { + char *p = driver_mem_alloc(size); + + if (!p) + return NULL; + memset(p, 0, size); + info->par = p; } return info; } @@ -175,59 +180,6 @@ struct fb_info *framebuffer_alloc(unsigned long size) */ void framebuffer_release(struct fb_info *info) { - if(info->par != (void *)&struct_radeon_info) - Funcs_free(info->par); + driver_mem_free(info->par); } -#else - -/** - * framebuffer_alloc - creates a new frame buffer info structure - * - * @size: size of driver private data, can be zero - * @dev: pointer to the device for this fb, this can be NULL - * - * Creates a new frame buffer info structure. Also reserves @size bytes - * for driver private data (info->par). info->par (if any) will be - * aligned to sizeof(long). - * - * Returns the new structure, or NULL if an error occured. - * - */ -struct fb_info *framebuffer_alloc(unsigned long size) -{ -#define BYTES_PER_LONG (32/8) -#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) - int fb_info_size = sizeof(struct fb_info); - struct fb_info *info; - char *p; - if(size) - fb_info_size += PADDING; - p = Funcs_malloc(fb_info_size + size, 3); - if(!p) - return NULL; - memset(p, 0, fb_info_size + size); - info = (struct fb_info *) p; - if(size) - info->par = p + fb_info_size; - return info; -#undef PADDING -#undef BYTES_PER_LONG -} - -/** - * framebuffer_release - marks the structure available for freeing - * - * @info: frame buffer info structure - * - * Drop the reference count of the class_device embedded in the - * framebuffer info structure. - * - */ -void framebuffer_release(struct fb_info *info) -{ - Funcs_free(info); -} - -#endif - diff --git a/x86emu/biosemu.c b/x86emu/biosemu.c index 8cd040e..32310b4 100644 --- a/x86emu/biosemu.c +++ b/x86emu/biosemu.c @@ -1,11 +1,20 @@ #define RINFO_ONLY #include "radeonfb.h" +#include "bas_printf.h" #include "bas_string.h" +#include "util.h" #include "x86emu.h" #include "pci.h" #include "pci_ids.h" // #include "vgatables.h" +#define DBG_EMULATOR +#ifdef DBG_EMULATOR +#define dbg(format, arg...) do { xprintf("DEBUG: " format, ##arg); } while (0) +#else +#define dbg(format, arg...) do { ; } while (0) +#endif /* DBG_EMULATOR */ + #define USE_SDRAM #define DIRECT_ACCESS @@ -22,11 +31,6 @@ #define SYS_BIOS 0xF0000 #define SIZE_EMU 0x100000 -#ifdef DIRECT_ACCESS -extern uint16_t swpw(uint16_t val); -extern uint32_t swap_long(uint32_t val); -#endif - typedef struct { long ident; @@ -103,17 +107,12 @@ static uint8_t inb(uint16_t port) { uint8_t val = 0; - if ((port >= offset_port) && (port <= offset_port+0xFF)) + if ((port >= offset_port) && (port <= offset_port + 0xFF)) { -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("inb(", port); -#endif + dbg("inb("); val = *(uint8_t *)(offset_io+(uint32_t)port); -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("0x%x) = 0x%x\r\n", port, val); } return val; } @@ -124,14 +123,9 @@ static uint16_t inw(uint16_t port) if ((port >= offset_port) && (port <= offset_port+0xFF)) { -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("inw(", port); -#endif + dbg("inw("); val = swpw(*(uint16_t *)(offset_io+(uint32_t)port)); -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("0x%x) = 0x%x\r\n", port, val); } return val; } @@ -141,27 +135,19 @@ static uint32_t inl(uint16_t port) uint32_t val = 0; if ((port >= offset_port) && (port <= offset_port+0xFF)) { -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("inl(", port); -#endif + dbg("inl("); val = swpl(*(uint32_t *)(offset_io+(uint32_t)port)); -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("0x%x) = 0x%x\r\n", port, val); } else if (port == 0xCF8) { + dbg("inl("); val = config_address_reg; -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("inl(", port); - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("0x%x) = 0x%x\r\n", port, val); } - else if ((port == 0xCFC) && ((config_address_reg & 0x80000000) !=0)) + else if ((port == 0xCFC) && ((config_address_reg & 0x80000000) != 0)) { - switch(config_address_reg & 0xFC) + switch (config_address_reg & 0xFC) { case PCIIDR: val = ((uint32_t) rinfo_biosemu->chipset << 16) + PCI_VENDOR_ID_ATI; @@ -173,59 +159,39 @@ static uint32_t inl(uint16_t port) val = pci_read_config_longword(rinfo_biosemu->handle, config_address_reg & 0xFC); break; } -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("inl(", port); - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("inl(0x%x) = 0x%x\r\n", port, val); } return val; } void outb(uint8_t val, uint16_t port) { - if ((port >= offset_port) && (port <= offset_port+0xFF)) + if ((port >= offset_port) && (port <= offset_port + 0xFF)) { -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("outb(", port); - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("outb(0x%x, 0x%x)\r\n", port, val); *(uint8_t *)(offset_io + (uint32_t) port) = val; } } void outw(uint16_t val, uint16_t port) { - if ((port >= offset_port) && (port <= offset_port+0xFF)) + if ((port >= offset_port) && (port <= offset_port + 0xFF)) { -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("outw(", port); - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("outw(0x%x, 0x%x)\r\n", port, val); *(uint16_t *)(offset_io + (uint32_t) port) = swpw(val); } } void outl(uint32_t val, uint16_t port) { - if ((port >= offset_port) && (port <= offset_port+0xFF)) + if ((port >= offset_port) && (port <= offset_port + 0xFF)) { -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("outl(", port); - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("outl(0x%x, 0x%x)\r\n", port, val); *(uint32_t *)(offset_io + (uint32_t) port) = swpl(val); } else if (port == 0xCF8) { -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("outl(", port); - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("outl(0x%x, 0x%x)\r\n", port, val); config_address_reg = val; } else if ((port == 0xCFC) && ((config_address_reg & 0x80000000) !=0)) @@ -234,11 +200,7 @@ void outl(uint32_t val, uint16_t port) offset_port = (uint16_t)val & 0xFFFC; else { -#ifdef DEBUG_X86EMU_PCI - DPRINTVALHEX("outl(", port); - DPRINTVALHEX(") = ", val); - DPRINT("\r\n"); -#endif + dbg("outl(0x%x, 0x%x)\r\n", port, val); pci_write_config_longword(rinfo_biosemu->handle, config_address_reg & 0xFC, val); } } @@ -554,11 +516,11 @@ void biosfn_set_video_mode(uint8_t mode) memsetw(vga_modes[line].sstart,0x0000,0x4000); // 32k else { - outb(0x02,VGAREG_SEQU_ADDRESS); - mmask = inb( VGAREG_SEQU_DATA ); - outb(0x0f,VGAREG_SEQU_DATA); // all planes - memsetw(vga_modes[line].sstart,0x0000,0x8000); // 64k - outb(mmask,VGAREG_SEQU_DATA); + outb(0x02, VGAREG_SEQU_ADDRESS); + mmask = inb(VGAREG_SEQU_DATA); + outb(0x0f, VGAREG_SEQU_DATA); // all planes + memsetw(vga_modes[line].sstart, 0x0000, 0x8000); // 64k + outb(mmask, VGAREG_SEQU_DATA); } } @@ -572,7 +534,7 @@ void run_bios(struct radeonfb_info *rinfo) struct pci_data *rom_data; unsigned long rom_size=0; unsigned long image_size=0; - unsigned long biosmem=0x01000000; /* when run_bios() is called, SDRAM is valid but not added to the system */ + unsigned long biosmem = 0x01000000; /* when run_bios() is called, SDRAM is valid but not added to the system */ unsigned long addr; unsigned short initialcs; unsigned short initialip;