2016-01-20 05:45:20 +01:00
|
|
|
#include <syscall.h>
|
|
|
|
|
2012-11-12 22:22:52 +01:00
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/i915_drm.h>
|
2012-01-25 05:04:03 +01:00
|
|
|
#include "i915_drv.h"
|
|
|
|
|
2011-12-18 14:35:29 +01:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mod_devicetable.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
|
2016-01-22 06:09:08 +01:00
|
|
|
#include "getopt.h"
|
|
|
|
|
2012-02-03 07:54:20 +01:00
|
|
|
#include "bitmap.h"
|
2016-01-22 06:09:08 +01:00
|
|
|
#include "i915_kos32.h"
|
2012-01-30 08:06:25 +01:00
|
|
|
|
2016-01-20 05:45:20 +01:00
|
|
|
#define DRV_NAME "i915 v4.4"
|
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
#define I915_DEV_CLOSE 0
|
|
|
|
#define I915_DEV_INIT 1
|
|
|
|
#define I915_DEV_READY 2
|
|
|
|
|
2016-01-22 06:09:08 +01:00
|
|
|
static int my_atoi(char **cmd);
|
|
|
|
static char* parse_mode(char *p, videomode_t *mode);
|
2015-01-05 20:15:42 +01:00
|
|
|
void cpu_detect1();
|
|
|
|
int kmap_init();
|
2012-02-04 14:23:46 +01:00
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
unsigned long volatile jiffies;
|
2016-01-22 06:09:08 +01:00
|
|
|
int oops_in_progress;
|
2012-02-04 14:23:46 +01:00
|
|
|
int x86_clflush_size;
|
2013-04-26 13:01:23 +02:00
|
|
|
unsigned int tsc_khz;
|
2016-01-22 06:09:08 +01:00
|
|
|
struct workqueue_struct *system_wq;
|
|
|
|
int driver_wq_state;
|
|
|
|
struct drm_device *main_device;
|
|
|
|
struct drm_file *drm_file_handlers[256];
|
|
|
|
videomode_t usermode;
|
|
|
|
extern int __getopt_initialized;
|
2013-10-29 08:50:17 +01:00
|
|
|
|
|
|
|
void i915_driver_thread()
|
|
|
|
{
|
2014-08-26 12:13:45 +02:00
|
|
|
struct drm_i915_private *dev_priv = NULL;
|
|
|
|
struct workqueue_struct *cwq = NULL;
|
2013-10-29 08:50:17 +01:00
|
|
|
static int dpms = 1;
|
|
|
|
static int dpms_lock = 0;
|
|
|
|
oskey_t key;
|
|
|
|
unsigned long irqflags;
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
printf("%s\n",__FUNCTION__);
|
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
while(driver_wq_state == I915_DEV_INIT)
|
|
|
|
{
|
2016-01-20 05:45:20 +01:00
|
|
|
jiffies = GetClockNs() / 10000000;
|
2014-08-26 12:13:45 +02:00
|
|
|
delay(1);
|
|
|
|
};
|
|
|
|
|
2016-01-20 05:45:20 +01:00
|
|
|
if( driver_wq_state == I915_DEV_CLOSE)
|
|
|
|
{
|
|
|
|
asm volatile ("int $0x40"::"a"(-1));
|
|
|
|
};
|
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
dev_priv = main_device->dev_private;
|
|
|
|
cwq = dev_priv->wq;
|
|
|
|
|
2013-10-29 08:50:17 +01:00
|
|
|
asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(1),"c"(1));
|
|
|
|
asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(4),"c"(0x46),"d"(0x330));
|
|
|
|
asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(4),"c"(0xC6),"d"(0x330));
|
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
while(driver_wq_state != I915_DEV_CLOSE)
|
2013-10-29 08:50:17 +01:00
|
|
|
{
|
2016-01-20 05:45:20 +01:00
|
|
|
jiffies = GetClockNs() / 10000000;
|
2014-08-26 12:13:45 +02:00
|
|
|
|
2013-10-29 08:50:17 +01:00
|
|
|
key = get_key();
|
|
|
|
|
|
|
|
if( (key.val != 1) && (key.state == 0x02))
|
|
|
|
{
|
|
|
|
if(key.code == 0x46 && dpms_lock == 0)
|
|
|
|
{
|
|
|
|
dpms_lock = 1;
|
|
|
|
if(dpms == 1)
|
|
|
|
{
|
|
|
|
i915_dpms(main_device, DRM_MODE_DPMS_OFF);
|
|
|
|
printf("dpms off\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i915_dpms(main_device, DRM_MODE_DPMS_ON);
|
|
|
|
printf("dpms on\n");
|
|
|
|
};
|
|
|
|
dpms ^= 1;
|
|
|
|
}
|
|
|
|
else if(key.code == 0xC6)
|
|
|
|
dpms_lock = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cwq->lock, irqflags);
|
|
|
|
|
|
|
|
while (!list_empty(&cwq->worklist))
|
|
|
|
{
|
|
|
|
struct work_struct *work = list_entry(cwq->worklist.next,
|
|
|
|
struct work_struct, entry);
|
|
|
|
work_func_t f = work->func;
|
|
|
|
list_del_init(cwq->worklist.next);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cwq->lock, irqflags);
|
|
|
|
f(work);
|
|
|
|
spin_lock_irqsave(&cwq->lock, irqflags);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cwq->lock, irqflags);
|
|
|
|
|
|
|
|
delay(1);
|
|
|
|
};
|
|
|
|
|
|
|
|
asm volatile ("int $0x40"::"a"(-1));
|
|
|
|
}
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
u32 __attribute__((externally_visible)) drvEntry(int action, char *cmdline)
|
2011-12-18 14:35:29 +01:00
|
|
|
{
|
2014-08-26 12:13:45 +02:00
|
|
|
static pci_dev_t device;
|
|
|
|
const struct pci_device_id *ent;
|
2016-01-22 06:09:08 +01:00
|
|
|
char *safecmdline;
|
2013-10-26 15:34:57 +02:00
|
|
|
int err = 0;
|
2011-12-18 14:35:29 +01:00
|
|
|
|
|
|
|
if(action != 1)
|
2013-07-05 09:43:48 +02:00
|
|
|
{
|
2014-08-26 12:13:45 +02:00
|
|
|
driver_wq_state = I915_DEV_CLOSE;
|
2011-12-18 14:35:29 +01:00
|
|
|
return 0;
|
2013-07-05 09:43:48 +02:00
|
|
|
};
|
2011-12-18 14:35:29 +01:00
|
|
|
|
|
|
|
if( GetService("DISPLAY") != 0 )
|
|
|
|
return 0;
|
|
|
|
|
2016-01-20 05:45:20 +01:00
|
|
|
printf("\n%s build %s %s\nusage: i915 [options]\n"
|
2016-01-22 06:09:08 +01:00
|
|
|
"-f\n"
|
|
|
|
"--fbsize <0-9> Set framebuffer size in megabytes (default: 16)\n",
|
2016-01-20 05:45:20 +01:00
|
|
|
DRV_NAME, __DATE__, __TIME__);
|
|
|
|
|
2016-01-22 06:09:08 +01:00
|
|
|
printf("--rc6 <-1,0-7> Enable power-saving render C-state 6.\n"
|
|
|
|
" Different stages can be selected via bitmask values\n"
|
|
|
|
" (0 = disable; 1 = enable rc6; 2 = enable deep rc6;\n"
|
|
|
|
" 4 = enable deepest rc6).\n"
|
|
|
|
" For example, 3 would enable rc6 and deep rc6,\n"
|
|
|
|
" and 7 would enable everything.\n"
|
|
|
|
" default: -1 (use per-chip default)\n");
|
|
|
|
printf("--fbc <-1,0,1> Enable frame buffer compression for power savings\n"
|
|
|
|
" (default: -1 (use per-chip default))\n");
|
|
|
|
printf("-l\n"
|
|
|
|
"--log <path> path to log file\n");
|
|
|
|
printf("-m\n"
|
|
|
|
"--mode <WxHxHz> set videomode\n");
|
|
|
|
printf("-v\n"
|
|
|
|
"--video <CONNECTOR>:<xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]\n"
|
|
|
|
" set videomode for CONNECTOR\n");
|
2016-01-20 05:45:20 +01:00
|
|
|
|
2012-01-30 08:06:25 +01:00
|
|
|
if( cmdline && *cmdline )
|
2016-01-22 06:09:08 +01:00
|
|
|
{
|
|
|
|
int argc, i, c;
|
|
|
|
char **argv;
|
|
|
|
|
|
|
|
safecmdline = __builtin_strdup(cmdline);
|
|
|
|
printf("cmdline %s\n", safecmdline);
|
|
|
|
|
|
|
|
argc = split_cmdline(safecmdline, NULL);
|
|
|
|
argv = __builtin_malloc((argc+1)*sizeof(char*));
|
|
|
|
split_cmdline(safecmdline, argv);
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
|
|
|
{"log", required_argument, 0, 'l'},
|
|
|
|
{"mode", required_argument, 0, 'm'},
|
|
|
|
{"fbsize",required_argument, 0, 'f'},
|
|
|
|
{"video", required_argument, 0, 'v'},
|
|
|
|
{"rc6", required_argument, 0, OPTION_RC6},
|
|
|
|
{"fbc", required_argument, 0, OPTION_FBC},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
c = getopt_long (argc, argv, "f:l:m:v:",
|
|
|
|
long_options, &option_index);
|
|
|
|
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case OPTION_RC6:
|
|
|
|
i915.enable_rc6 = my_atoi(&optarg);
|
|
|
|
printf("i915.rc6 = %d\n",i915.enable_rc6);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_FBC:
|
|
|
|
i915.enable_fbc = my_atoi(&optarg);
|
|
|
|
printf("i915.fbc = %d\n",i915.enable_fbc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
i915.fbsize = my_atoi(&optarg);
|
|
|
|
printf("i915.fbsize =%d\n",i915.fbsize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
i915.log_file = optarg;
|
|
|
|
break;
|
2011-12-18 14:35:29 +01:00
|
|
|
|
2016-01-22 06:09:08 +01:00
|
|
|
case 'm':
|
|
|
|
parse_mode(optarg, &usermode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
i915.cmdline_mode = optarg;
|
|
|
|
printf("i915.cmdline_mode =%s\n",i915.cmdline_mode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if( i915.log_file && !dbg_open(i915.log_file))
|
2016-01-20 05:45:20 +01:00
|
|
|
{
|
2016-01-22 06:09:08 +01:00
|
|
|
printf("Can't open %s\nExit\n", i915.log_file);
|
2016-01-20 05:45:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dbgprintf("\nLOG: %s build %s %s\n",DRV_NAME,__DATE__, __TIME__);
|
2011-12-18 14:35:29 +01:00
|
|
|
}
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
cpu_detect1();
|
2012-02-16 11:48:38 +01:00
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
err = enum_pci_devices();
|
|
|
|
if( unlikely(err != 0) )
|
|
|
|
{
|
|
|
|
dbgprintf("Device enumeration failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
err = kmap_init();
|
|
|
|
if( unlikely(err != 0) )
|
|
|
|
{
|
|
|
|
dbgprintf("kmap initialization failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-09 20:24:25 +02:00
|
|
|
dmi_scan_machine();
|
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
driver_wq_state = I915_DEV_INIT;
|
|
|
|
CreateKernelThread(i915_driver_thread);
|
2011-12-18 14:35:29 +01:00
|
|
|
|
|
|
|
err = i915_init();
|
2014-08-26 12:13:45 +02:00
|
|
|
if(unlikely(err!= 0))
|
2012-01-25 05:04:03 +01:00
|
|
|
{
|
2014-08-26 12:13:45 +02:00
|
|
|
driver_wq_state = I915_DEV_CLOSE;
|
2013-03-01 07:45:16 +01:00
|
|
|
dbgprintf("Epic Fail :(\n");
|
2016-01-20 05:45:20 +01:00
|
|
|
delay(100);
|
2013-03-01 07:45:16 +01:00
|
|
|
return 0;
|
2012-01-25 05:04:03 +01:00
|
|
|
};
|
2013-11-22 15:45:09 +01:00
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
driver_wq_state = I915_DEV_READY;
|
|
|
|
|
2013-11-22 15:45:09 +01:00
|
|
|
init_display_kms(main_device, &usermode);
|
2011-12-18 14:35:29 +01:00
|
|
|
|
2012-01-25 05:04:03 +01:00
|
|
|
err = RegService("DISPLAY", display_handler);
|
2011-12-18 14:35:29 +01:00
|
|
|
|
2012-01-25 05:04:03 +01:00
|
|
|
if( err != 0)
|
|
|
|
dbgprintf("Set DISPLAY handler\n");
|
2011-12-18 14:35:29 +01:00
|
|
|
|
|
|
|
return err;
|
|
|
|
};
|
|
|
|
|
2016-01-22 06:09:08 +01:00
|
|
|
int do_command_line(const char* usercmd)
|
|
|
|
{
|
|
|
|
char *cmdline;
|
|
|
|
int argc, i, c;
|
|
|
|
char **argv;
|
2016-01-27 06:47:59 +01:00
|
|
|
int retval = 0;
|
2016-01-22 06:09:08 +01:00
|
|
|
|
|
|
|
if( (usercmd == NULL) || (*usercmd == 0) )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
cmdline = __builtin_strdup(usercmd);
|
|
|
|
printf("cmdline %s\n", cmdline);
|
|
|
|
|
|
|
|
argc = split_cmdline(cmdline, NULL);
|
|
|
|
argv = __builtin_malloc((argc+1)*sizeof(char*));
|
|
|
|
split_cmdline(cmdline, argv);
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
|
|
|
__getopt_initialized = 0;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
2016-01-27 06:47:59 +01:00
|
|
|
{"list-connectors", no_argument, 0, OPTION_CONNECTORS},
|
|
|
|
{"list-connector-modes", required_argument, 0, OPTION_CONN_MODES},
|
|
|
|
{"video", required_argument, 0, 'v'},
|
2016-01-22 06:09:08 +01:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
c = getopt_long (argc, argv, "v:",
|
|
|
|
long_options, &option_index);
|
|
|
|
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case 'v':
|
|
|
|
printf("cmdline_mode %s\n",optarg);
|
2016-01-27 06:47:59 +01:00
|
|
|
retval = set_cmdline_mode_ext(main_device, optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_CONNECTORS:
|
|
|
|
list_connectors(main_device);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_CONN_MODES:
|
|
|
|
retval = list_connector_modes(main_device, optarg);
|
2016-01-22 06:09:08 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__builtin_free(argv);
|
|
|
|
__builtin_free(cmdline);
|
|
|
|
|
2016-01-27 06:47:59 +01:00
|
|
|
return retval;
|
2016-01-22 06:09:08 +01:00
|
|
|
};
|
2013-04-24 22:04:21 +02:00
|
|
|
|
2012-02-04 14:23:46 +01:00
|
|
|
#define CURRENT_API 0x0200 /* 2.00 */
|
|
|
|
#define COMPATIBLE_API 0x0100 /* 1.00 */
|
|
|
|
|
|
|
|
#define API_VERSION (COMPATIBLE_API << 16) | CURRENT_API
|
2012-02-16 11:48:38 +01:00
|
|
|
#define DISPLAY_VERSION API_VERSION
|
2012-01-25 05:04:03 +01:00
|
|
|
|
|
|
|
|
2016-01-20 05:45:20 +01:00
|
|
|
#define SRV_GETVERSION 0
|
|
|
|
#define SRV_ENUM_MODES 1
|
|
|
|
#define SRV_SET_MODE 2
|
|
|
|
#define SRV_GET_CAPS 3
|
2016-01-22 06:09:08 +01:00
|
|
|
#define SRV_CMDLINE 4
|
2012-01-25 05:04:03 +01:00
|
|
|
|
2016-01-20 05:45:20 +01:00
|
|
|
#define SRV_GET_PCI_INFO 20
|
2013-11-17 07:47:10 +01:00
|
|
|
#define SRV_I915_GET_PARAM 21
|
2016-01-20 05:45:20 +01:00
|
|
|
#define SRV_I915_GEM_CREATE 22
|
|
|
|
#define SRV_DRM_GEM_CLOSE 23
|
2013-11-17 07:47:10 +01:00
|
|
|
#define SRV_DRM_GEM_FLINK 24
|
|
|
|
#define SRV_DRM_GEM_OPEN 25
|
|
|
|
#define SRV_I915_GEM_PIN 26
|
|
|
|
#define SRV_I915_GEM_UNPIN 27
|
2015-01-10 17:53:44 +01:00
|
|
|
#define SRV_I915_GEM_GET_CACHING 28
|
|
|
|
#define SRV_I915_GEM_SET_CACHING 29
|
|
|
|
#define SRV_I915_GEM_PWRITE 30
|
|
|
|
#define SRV_I915_GEM_BUSY 31
|
|
|
|
#define SRV_I915_GEM_SET_DOMAIN 32
|
|
|
|
#define SRV_I915_GEM_MMAP 33
|
|
|
|
#define SRV_I915_GEM_SET_TILING 34
|
|
|
|
#define SRV_I915_GEM_GET_TILING 35
|
|
|
|
#define SRV_I915_GEM_GET_APERTURE 36
|
|
|
|
#define SRV_I915_GEM_MMAP_GTT 37
|
|
|
|
#define SRV_I915_GEM_THROTTLE 38
|
|
|
|
#define SRV_I915_GEM_EXECBUFFER2 39
|
|
|
|
#define SRV_I915_GEM_WAIT 40
|
|
|
|
#define SRV_I915_GEM_CONTEXT_CREATE 41
|
|
|
|
#define SRV_I915_GEM_CONTEXT_DESTROY 42
|
|
|
|
#define SRV_I915_REG_READ 43
|
|
|
|
|
|
|
|
#define SRV_FBINFO 44
|
|
|
|
#define SRV_MASK_UPDATE 45
|
|
|
|
#define SRV_MASK_UPDATE_EX 46
|
2013-02-18 15:33:08 +01:00
|
|
|
|
2012-01-25 05:04:03 +01:00
|
|
|
#define check_input(size) \
|
|
|
|
if( unlikely((inp==NULL)||(io->inp_size != (size))) ) \
|
|
|
|
break;
|
|
|
|
|
|
|
|
#define check_output(size) \
|
|
|
|
if( unlikely((outp==NULL)||(io->out_size != (size))) ) \
|
|
|
|
break;
|
|
|
|
|
|
|
|
int _stdcall display_handler(ioctl_t *io)
|
|
|
|
{
|
2013-02-18 15:33:08 +01:00
|
|
|
struct drm_file *file;
|
|
|
|
|
2016-01-20 05:45:20 +01:00
|
|
|
int retval = -1;
|
2015-01-05 20:15:42 +01:00
|
|
|
u32 *inp;
|
|
|
|
u32 *outp;
|
2012-01-25 05:04:03 +01:00
|
|
|
|
|
|
|
inp = io->input;
|
|
|
|
outp = io->output;
|
|
|
|
|
2013-02-18 15:33:08 +01:00
|
|
|
file = drm_file_handlers[0];
|
|
|
|
|
2012-01-25 05:04:03 +01:00
|
|
|
switch(io->io_code)
|
|
|
|
{
|
|
|
|
case SRV_GETVERSION:
|
|
|
|
check_output(4);
|
2012-02-04 14:23:46 +01:00
|
|
|
*outp = DISPLAY_VERSION;
|
2012-01-25 05:04:03 +01:00
|
|
|
retval = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_ENUM_MODES:
|
2012-11-12 22:22:52 +01:00
|
|
|
// dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
|
|
|
|
// inp, io->inp_size, io->out_size );
|
2012-01-30 08:06:25 +01:00
|
|
|
check_output(4);
|
2012-01-25 05:04:03 +01:00
|
|
|
// check_input(*outp * sizeof(videomode_t));
|
2016-01-22 06:09:08 +01:00
|
|
|
retval = get_videomodes((videomode_t*)inp, outp);
|
2012-01-25 05:04:03 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_SET_MODE:
|
2012-11-12 22:22:52 +01:00
|
|
|
// dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
|
|
|
|
// inp, io->inp_size);
|
2012-01-25 05:04:03 +01:00
|
|
|
check_input(sizeof(videomode_t));
|
2016-01-22 06:09:08 +01:00
|
|
|
retval = set_user_mode((videomode_t*)inp);
|
2012-01-25 05:04:03 +01:00
|
|
|
break;
|
2012-11-13 10:18:58 +01:00
|
|
|
|
2012-02-16 11:48:38 +01:00
|
|
|
case SRV_GET_CAPS:
|
|
|
|
retval = get_driver_caps((hwcaps_t*)inp);
|
|
|
|
break;
|
|
|
|
|
2016-01-22 06:09:08 +01:00
|
|
|
case SRV_CMDLINE:
|
|
|
|
retval = do_command_line((char*)inp);
|
|
|
|
break;
|
|
|
|
|
2013-02-21 05:10:35 +01:00
|
|
|
case SRV_GET_PCI_INFO:
|
2013-02-18 15:33:08 +01:00
|
|
|
get_pci_info((struct pci_device *)inp);
|
2012-01-25 05:04:03 +01:00
|
|
|
retval = 0;
|
|
|
|
break;
|
2012-11-12 22:22:52 +01:00
|
|
|
|
2013-11-17 07:47:10 +01:00
|
|
|
case SRV_I915_GET_PARAM:
|
|
|
|
retval = i915_getparam(main_device, inp, file);
|
2013-02-18 15:33:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_GEM_CREATE:
|
|
|
|
retval = i915_gem_create_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_DRM_GEM_CLOSE:
|
|
|
|
retval = drm_gem_close_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
2013-11-17 07:47:10 +01:00
|
|
|
case SRV_DRM_GEM_FLINK:
|
|
|
|
retval = drm_gem_flink_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_DRM_GEM_OPEN:
|
|
|
|
retval = drm_gem_open_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
2015-01-10 17:53:44 +01:00
|
|
|
case SRV_I915_GEM_GET_CACHING:
|
|
|
|
retval = i915_gem_get_caching_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
2013-11-17 07:47:10 +01:00
|
|
|
case SRV_I915_GEM_SET_CACHING:
|
|
|
|
retval = i915_gem_set_caching_ioctl(main_device, inp, file);
|
2013-02-21 05:10:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_GEM_PWRITE:
|
|
|
|
retval = i915_gem_pwrite_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_GEM_BUSY:
|
|
|
|
retval = i915_gem_busy_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_GEM_SET_DOMAIN:
|
|
|
|
retval = i915_gem_set_domain_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
2013-02-23 10:47:31 +01:00
|
|
|
case SRV_I915_GEM_MMAP:
|
|
|
|
retval = i915_gem_mmap_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
2013-11-17 07:47:10 +01:00
|
|
|
case SRV_I915_GEM_SET_TILING:
|
|
|
|
retval = i915_gem_set_tiling(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_GEM_GET_TILING:
|
|
|
|
retval = i915_gem_get_tiling(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_GEM_GET_APERTURE:
|
|
|
|
// printf("SRV_I915_GEM_GET_APERTURE ");
|
|
|
|
retval = i915_gem_get_aperture_ioctl(main_device, inp, file);
|
|
|
|
// printf(" retval=%d\n", retval);
|
|
|
|
break;
|
|
|
|
|
2013-04-24 22:04:21 +02:00
|
|
|
case SRV_I915_GEM_MMAP_GTT:
|
|
|
|
retval = i915_gem_mmap_gtt_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
2013-11-17 07:47:10 +01:00
|
|
|
case SRV_I915_GEM_THROTTLE:
|
|
|
|
retval = i915_gem_throttle_ioctl(main_device, inp, file);
|
2013-02-23 10:47:31 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_GEM_EXECBUFFER2:
|
2013-11-17 07:47:10 +01:00
|
|
|
// printf("SRV_I915_GEM_EXECBUFFER2\n");
|
2013-02-23 10:47:31 +01:00
|
|
|
retval = i915_gem_execbuffer2(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
2013-11-17 07:47:10 +01:00
|
|
|
case SRV_I915_GEM_WAIT:
|
|
|
|
retval = i915_gem_wait_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_GEM_CONTEXT_CREATE:
|
|
|
|
retval = i915_gem_context_create_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_GEM_CONTEXT_DESTROY:
|
|
|
|
retval = i915_gem_context_destroy_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_I915_REG_READ:
|
|
|
|
retval = i915_reg_read_ioctl(main_device, inp, file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRV_FBINFO:
|
|
|
|
retval = i915_fbinfo(inp);
|
|
|
|
break;
|
|
|
|
|
2013-02-28 12:35:11 +01:00
|
|
|
case SRV_MASK_UPDATE:
|
|
|
|
retval = i915_mask_update(main_device, inp, file);
|
|
|
|
break;
|
2014-01-27 21:10:22 +01:00
|
|
|
|
|
|
|
case SRV_MASK_UPDATE_EX:
|
|
|
|
retval = i915_mask_update_ex(main_device, inp, file);
|
|
|
|
break;
|
2012-01-25 05:04:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-18 14:35:29 +01:00
|
|
|
#define PCI_CLASS_REVISION 0x08
|
|
|
|
#define PCI_CLASS_DISPLAY_VGA 0x0300
|
|
|
|
#define PCI_CLASS_BRIDGE_HOST 0x0600
|
2011-12-19 19:13:14 +01:00
|
|
|
#define PCI_CLASS_BRIDGE_ISA 0x0601
|
2011-12-18 14:35:29 +01:00
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
int pci_scan_filter(u32 id, u32 busnr, u32 devfn)
|
2011-12-18 14:35:29 +01:00
|
|
|
{
|
2015-01-05 20:15:42 +01:00
|
|
|
u16 vendor, device;
|
|
|
|
u32 class;
|
2011-12-18 14:35:29 +01:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
vendor = id & 0xffff;
|
|
|
|
device = (id >> 16) & 0xffff;
|
|
|
|
|
|
|
|
if(vendor == 0x8086)
|
|
|
|
{
|
|
|
|
class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
|
|
|
|
class >>= 16;
|
|
|
|
|
|
|
|
if( (class == PCI_CLASS_DISPLAY_VGA) ||
|
2011-12-19 19:13:14 +01:00
|
|
|
(class == PCI_CLASS_BRIDGE_HOST) ||
|
|
|
|
(class == PCI_CLASS_BRIDGE_ISA))
|
2011-12-18 14:35:29 +01:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
2012-01-30 08:06:25 +01:00
|
|
|
|
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
struct mtrr
|
|
|
|
{
|
2015-01-05 20:15:42 +01:00
|
|
|
u64 base;
|
|
|
|
u64 mask;
|
2014-08-26 12:13:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cpuinfo
|
|
|
|
{
|
2015-01-05 20:15:42 +01:00
|
|
|
u64 caps;
|
|
|
|
u64 def_mtrr;
|
|
|
|
u64 mtrr_cap;
|
2014-08-26 12:13:45 +02:00
|
|
|
int var_mtrr_count;
|
|
|
|
int fix_mtrr_count;
|
|
|
|
struct mtrr var_mtrr[9];
|
|
|
|
char model_name[64];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg))
|
|
|
|
#define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1)
|
|
|
|
|
|
|
|
#define MSR_MTRRdefType 0x000002ff
|
|
|
|
|
|
|
|
#define IA32_MTRRCAP 0xFE
|
|
|
|
#define IA32_CR_PAT_MSR 0x277
|
|
|
|
|
|
|
|
#define PAT_TYPE_UC 0
|
|
|
|
#define PAT_TYPE_WC 1
|
|
|
|
#define PAT_TYPE_WB 6
|
|
|
|
#define PAT_TYPE_UCM 7
|
|
|
|
|
|
|
|
|
|
|
|
#define MTRR_UC 0
|
|
|
|
#define MTRR_WC 1
|
|
|
|
#define MTRR_WB 6
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
static inline u64 read_msr(u32 msr)
|
2014-08-26 12:13:45 +02:00
|
|
|
{
|
|
|
|
union {
|
2015-01-05 20:15:42 +01:00
|
|
|
u64 val;
|
2014-08-26 12:13:45 +02:00
|
|
|
struct {
|
2015-01-05 20:15:42 +01:00
|
|
|
u32 low;
|
|
|
|
u32 high;
|
2014-08-26 12:13:45 +02:00
|
|
|
};
|
|
|
|
}tmp;
|
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
"rdmsr"
|
|
|
|
: "=a" (tmp.low), "=d" (tmp.high)
|
|
|
|
: "c" (msr));
|
|
|
|
return tmp.val;
|
|
|
|
}
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
static inline void write_msr(u32 msr, u64 val)
|
2014-08-26 12:13:45 +02:00
|
|
|
{
|
|
|
|
union {
|
2015-01-05 20:15:42 +01:00
|
|
|
u64 val;
|
2014-08-26 12:13:45 +02:00
|
|
|
struct {
|
2015-01-05 20:15:42 +01:00
|
|
|
u32 low;
|
|
|
|
u32 high;
|
2014-08-26 12:13:45 +02:00
|
|
|
};
|
|
|
|
}tmp;
|
|
|
|
|
|
|
|
tmp.val = val;
|
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
"wrmsr"
|
|
|
|
:: "a" (tmp.low), "d" (tmp.high), "c" (msr));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SIZE_OR_MASK_BITS(n) (~((1ULL << ((n) - PAGE_SHIFT)) - 1))
|
|
|
|
|
|
|
|
static void set_mtrr(unsigned int reg, unsigned long base,
|
|
|
|
unsigned long size, int type)
|
|
|
|
{
|
|
|
|
unsigned int base_lo, base_hi, mask_lo, mask_hi;
|
|
|
|
u64 size_or_mask, size_and_mask;
|
|
|
|
|
|
|
|
size_or_mask = SIZE_OR_MASK_BITS(36);
|
|
|
|
size_and_mask = 0x00f00000;
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
/*
|
|
|
|
* The invalid bit is kept in the mask, so we simply
|
|
|
|
* clear the relevant mask register to disable a range.
|
|
|
|
*/
|
|
|
|
native_write_msr(MTRRphysMask_MSR(reg), 0, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
base_lo = base << PAGE_SHIFT | type;
|
|
|
|
base_hi = (base & size_and_mask) >> (32 - PAGE_SHIFT);
|
|
|
|
mask_lo = -size << PAGE_SHIFT | 0x800;
|
|
|
|
mask_hi = (-size & size_and_mask) >> (32 - PAGE_SHIFT);
|
|
|
|
|
|
|
|
native_write_msr(MTRRphysBase_MSR(reg), base_lo, base_hi);
|
|
|
|
native_write_msr(MTRRphysMask_MSR(reg), mask_lo, mask_hi);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static u32 deftype_lo, deftype_hi;
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
void cpu_detect1()
|
2012-02-04 14:23:46 +01:00
|
|
|
{
|
2014-08-26 12:13:45 +02:00
|
|
|
struct cpuinfo cpuinfo;
|
2012-02-04 14:23:46 +01:00
|
|
|
|
2014-08-26 12:13:45 +02:00
|
|
|
u32 junk, tfms, cap0, misc;
|
|
|
|
int i;
|
2015-01-05 20:15:42 +01:00
|
|
|
|
2012-02-04 14:23:46 +01:00
|
|
|
cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
|
|
|
|
|
|
|
|
if (cap0 & (1<<19))
|
|
|
|
{
|
|
|
|
x86_clflush_size = ((misc >> 8) & 0xff) * 8;
|
|
|
|
}
|
2013-04-26 13:01:23 +02:00
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
#if 0
|
2014-08-26 12:13:45 +02:00
|
|
|
cpuid(0x80000002, (unsigned int*)&cpuinfo.model_name[0], (unsigned int*)&cpuinfo.model_name[4],
|
|
|
|
(unsigned int*)&cpuinfo.model_name[8], (unsigned int*)&cpuinfo.model_name[12]);
|
|
|
|
cpuid(0x80000003, (unsigned int*)&cpuinfo.model_name[16], (unsigned int*)&cpuinfo.model_name[20],
|
|
|
|
(unsigned int*)&cpuinfo.model_name[24], (unsigned int*)&cpuinfo.model_name[28]);
|
|
|
|
cpuid(0x80000004, (unsigned int*)&cpuinfo.model_name[32], (unsigned int*)&cpuinfo.model_name[36],
|
|
|
|
(unsigned int*)&cpuinfo.model_name[40], (unsigned int*)&cpuinfo.model_name[44]);
|
|
|
|
|
|
|
|
printf("\n%s\n\n",cpuinfo.model_name);
|
|
|
|
|
|
|
|
cpuinfo.def_mtrr = read_msr(MSR_MTRRdefType);
|
|
|
|
cpuinfo.mtrr_cap = read_msr(IA32_MTRRCAP);
|
|
|
|
|
|
|
|
printf("MSR_MTRRdefType %016llx\n\n", cpuinfo.def_mtrr);
|
|
|
|
|
|
|
|
cpuinfo.var_mtrr_count = (u8_t)cpuinfo.mtrr_cap;
|
|
|
|
|
|
|
|
for(i = 0; i < cpuinfo.var_mtrr_count; i++)
|
|
|
|
{
|
|
|
|
u64_t mtrr_base;
|
|
|
|
u64_t mtrr_mask;
|
|
|
|
|
|
|
|
cpuinfo.var_mtrr[i].base = read_msr(MTRRphysBase_MSR(i));
|
|
|
|
cpuinfo.var_mtrr[i].mask = read_msr(MTRRphysMask_MSR(i));
|
|
|
|
|
|
|
|
printf("MTRR_%d base: %016llx mask: %016llx\n", i,
|
|
|
|
cpuinfo.var_mtrr[i].base,
|
|
|
|
cpuinfo.var_mtrr[i].mask);
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int cr0, cr3, cr4, eflags;
|
|
|
|
|
|
|
|
eflags = safe_cli();
|
|
|
|
|
|
|
|
/* Enter the no-fill (CD=1, NW=0) cache mode and flush caches. */
|
|
|
|
cr0 = read_cr0() | (1<<30);
|
|
|
|
write_cr0(cr0);
|
|
|
|
wbinvd();
|
|
|
|
|
|
|
|
cr4 = read_cr4();
|
|
|
|
write_cr4(cr4 & ~(1<<7));
|
|
|
|
|
|
|
|
cr3 = read_cr3();
|
|
|
|
write_cr3(cr3);
|
|
|
|
|
|
|
|
/* Save MTRR state */
|
|
|
|
rdmsr(MSR_MTRRdefType, deftype_lo, deftype_hi);
|
|
|
|
|
|
|
|
/* Disable MTRRs, and set the default type to uncached */
|
|
|
|
native_write_msr(MSR_MTRRdefType, deftype_lo & ~0xcff, deftype_hi);
|
|
|
|
wbinvd();
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
set_mtrr(i++,0,0x80000000>>12,MTRR_WB);
|
|
|
|
set_mtrr(i++,0x80000000>>12,0x40000000>>12,MTRR_WB);
|
|
|
|
set_mtrr(i++,0xC0000000>>12,0x20000000>>12,MTRR_WB);
|
|
|
|
set_mtrr(i++,0xdb800000>>12,0x00800000>>12,MTRR_UC);
|
|
|
|
set_mtrr(i++,0xdc000000>>12,0x04000000>>12,MTRR_UC);
|
|
|
|
set_mtrr(i++,0xE0000000>>12,0x10000000>>12,MTRR_WC);
|
|
|
|
|
|
|
|
for(; i < cpuinfo.var_mtrr_count; i++)
|
|
|
|
set_mtrr(i,0,0,0);
|
|
|
|
|
|
|
|
write_cr3(cr3);
|
|
|
|
|
|
|
|
/* Intel (P6) standard MTRRs */
|
|
|
|
native_write_msr(MSR_MTRRdefType, deftype_lo, deftype_hi);
|
|
|
|
|
|
|
|
/* Enable caches */
|
|
|
|
write_cr0(read_cr0() & ~(1<<30));
|
|
|
|
|
|
|
|
/* Restore value of CR4 */
|
|
|
|
write_cr4(cr4);
|
|
|
|
|
|
|
|
safe_sti(eflags);
|
|
|
|
|
|
|
|
printf("\nnew MTRR map\n\n");
|
|
|
|
|
|
|
|
for(i = 0; i < cpuinfo.var_mtrr_count; i++)
|
|
|
|
{
|
|
|
|
u64_t mtrr_base;
|
|
|
|
u64_t mtrr_mask;
|
|
|
|
|
|
|
|
cpuinfo.var_mtrr[i].base = read_msr(MTRRphysBase_MSR(i));
|
|
|
|
cpuinfo.var_mtrr[i].mask = read_msr(MTRRphysMask_MSR(i));
|
|
|
|
|
|
|
|
printf("MTRR_%d base: %016llx mask: %016llx\n", i,
|
|
|
|
cpuinfo.var_mtrr[i].base,
|
|
|
|
cpuinfo.var_mtrr[i].mask);
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-04-26 13:01:23 +02:00
|
|
|
tsc_khz = (unsigned int)(GetCpuFreq()/1000);
|
2012-02-04 14:23:46 +01:00
|
|
|
}
|
|
|
|
|
2013-02-13 09:23:54 +01:00
|
|
|
|
|
|
|
int get_driver_caps(hwcaps_t *caps)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch(caps->idx)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
caps->opt[0] = 0;
|
|
|
|
caps->opt[1] = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
caps->cap1.max_tex_width = 4096;
|
|
|
|
caps->cap1.max_tex_height = 4096;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = 1;
|
|
|
|
};
|
|
|
|
caps->idx = 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-18 15:33:08 +01:00
|
|
|
|
|
|
|
void get_pci_info(struct pci_device *dev)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev = main_device->pdev;
|
|
|
|
|
|
|
|
memset(dev, sizeof(*dev), 0);
|
|
|
|
|
|
|
|
dev->domain = 0;
|
|
|
|
dev->bus = pdev->busnr;
|
|
|
|
dev->dev = pdev->devfn >> 3;
|
|
|
|
dev->func = pdev->devfn & 7;
|
|
|
|
dev->vendor_id = pdev->vendor;
|
|
|
|
dev->device_id = pdev->device;
|
|
|
|
dev->revision = pdev->revision;
|
|
|
|
};
|
2013-11-17 07:47:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-22 15:45:09 +01:00
|
|
|
char *strstr(const char *cs, const char *ct);
|
|
|
|
|
|
|
|
static int my_atoi(char **cmd)
|
|
|
|
{
|
|
|
|
char* p = *cmd;
|
|
|
|
int val = 0;
|
|
|
|
int sign = 1;
|
|
|
|
|
|
|
|
if(*p == '-')
|
|
|
|
{
|
|
|
|
sign = -1;
|
|
|
|
p++;
|
|
|
|
};
|
|
|
|
|
|
|
|
for (;; *p++) {
|
|
|
|
switch (*p) {
|
|
|
|
case '0' ... '9':
|
|
|
|
val = 10*val+(*p-'0');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*cmd = p;
|
|
|
|
return val*sign;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-22 06:09:08 +01:00
|
|
|
static char* parse_mode(char *p, videomode_t *mode)
|
2013-11-22 15:45:09 +01:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
|
|
|
while( (c = *p++) == ' ');
|
|
|
|
|
|
|
|
if( c )
|
|
|
|
{
|
|
|
|
p--;
|
|
|
|
|
|
|
|
mode->width = my_atoi(&p);
|
|
|
|
if(*p == 'x') p++;
|
|
|
|
|
|
|
|
mode->height = my_atoi(&p);
|
|
|
|
if(*p == 'x') p++;
|
|
|
|
|
|
|
|
mode->bpp = 32;
|
|
|
|
|
|
|
|
mode->freq = my_atoi(&p);
|
|
|
|
|
|
|
|
if( mode->freq == 0 )
|
|
|
|
mode->freq = 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
};
|
|
|
|
|