int g2d_allocate_mva(unsigned int va, unsigned int *mva, unsigned int size) { int err = 0; if (!_m4u_g2d_func.isInit) { G2D_ERR("m4u is not initialized\n"); return -1; } G2D_DBG("try to allocate mva with 0x%x (%d)\n", va, size); err = _m4u_g2d_func.m4u_alloc_mva(M4U_CLNTMOD_G2D, va, size, mva); if (err != 0) { G2D_ERR("failed to allocate mva\n"); return -1; } err = _m4u_g2d_func.m4u_insert_tlb_range(M4U_CLNTMOD_G2D, *mva, *mva + size - 1, RT_RANGE_HIGH_PRIORITY, 1); if (err != 0) { G2D_ERR("failed to insert m4u tlb\n"); _m4u_g2d_func.m4u_dealloc_mva(M4U_CLNTMOD_G2D, va, size, *mva); return -1; } return 0; }
static int g2d_probe(struct platform_device *pdev) { struct class_device; struct class_device *class_dev = NULL; G2D_INF("\n\n\n===================== G2D probe ======================\n\n\n"); if (alloc_chrdev_region(&g2d_devno, 0, 1, G2D_DEVNAME)) { G2D_ERR("can't get device major number...\n"); return -EFAULT; } G2D_INF("get device major number (%d)\n", g2d_devno); g2d_cdev = cdev_alloc(); g2d_cdev->owner = THIS_MODULE; g2d_cdev->ops = &g2d_fops; cdev_add(g2d_cdev, g2d_devno, 1); g2d_class = class_create(THIS_MODULE, G2D_DEVNAME); class_dev = (struct class_device *)device_create(g2d_class, NULL, g2d_devno, NULL, G2D_DEVNAME); #ifdef G2D_QUEUE if (_g2d_create_workqueue()) { G2D_ERR("failed to create workqueue\n"); return -EFAULT; } if (_g2d_create_queuebuffer()) { G2D_ERR("failed to create queue buffer\n"); return -EFAULT; } #else init_waitqueue_head(&isr_wait_queue); if (!g2d_cmd_buffer) { g2d_cmd_buffer = (g2d_command_t *)kzalloc(sizeof(g2d_command_t), GFP_KERNEL); if (!g2d_cmd_buffer) return -EFAULT; } #endif mt6575_irq_set_sens(MT6575_G2D_IRQ_ID, MT65xx_EDGE_SENSITIVE); mt6575_irq_set_polarity(MT6575_G2D_IRQ_ID, MT65xx_POLARITY_LOW); if (request_irq(MT6575_G2D_IRQ_ID, g2d_drv_isr, 0, "G2D ISR" , NULL)) { G2D_ERR("request irq failed\n"); } G2D_INF("probe is done\n"); NOT_REFERENCED(class_dev); return 0; }
int _g2d_queue_command(unsigned long arg, bool sync) { int next_cmd = 0; spin_lock(&g2d_cmd_spinlock); next_cmd = g2d_current_cmd + 1; if (next_cmd >= G2D_QUEUE_BUFFER_COUNT) next_cmd = 0; down(&g2d_cmd_buffer[next_cmd].lock); if (copy_from_user(&g2d_cmd_buffer[next_cmd].ctx, (void *)arg, sizeof(g2d_context_t))) { G2D_ERR("copy from user is failed\n"); spin_unlock(&g2d_cmd_spinlock); return -EFAULT; } g2d_cmd_buffer[next_cmd].sync_cmd = sync; queue_work(g2d_workqueue, &g2d_cmd_buffer[next_cmd].work); g2d_current_cmd = next_cmd; spin_unlock(&g2d_cmd_spinlock); if (sync) down(&g2d_cmd_buffer[next_cmd].sync); return 0; }
void _g2d_command_handler(g2d_command_t *cmd) { G2D_DBG("start to handle command (0x%04x)\n", cmd->ctx.flag); switch (cmd->ctx.flag) { case G2D_FLAG_END_OF_FRAME: g2d_drv_fb_queue_buffer(cmd->ctx.fb_id); break; case G2D_FLAG_FLUSH: break; case G2D_FLAG_MIRROR_FRONT_FB: if (g2d_drv_fb_fill_mirror_cmd(&cmd->ctx) != 0) break; default: { #ifdef G2D_PROFILE struct timeval t1, t2; do_gettimeofday(&t1); #endif g2d_drv_power_on(); g2d_drv_run(&cmd->ctx); while (g2d_drv_get_status()) { wait_event_interruptible_timeout(isr_wait_queue, !g2d_drv_get_status(), (30 * HZ / 1000)); if (g2d_drv_get_status()) G2D_ERR("TIMEOUT: G2D is still busy"); } #ifdef G2D_PROFILE do_gettimeofday(&t2); G2D_INF("process time (%u)\n", (t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec)); #endif #ifdef G2D_DEBUG _g2d_reg_dump(); #endif g2d_drv_reset(); g2d_drv_power_off(); } break; } G2D_DBG("handle command (0x%04x) W2M(0x%08x) L0(0x%08x) L1(0x%08x) L2(0x%08x) L3(0x%08x) done\n", cmd->ctx.flag, ioread32(0xF20C5044), ioread32(0xF20C5084), ioread32(0xF20C50C4), ioread32(0xF20C5104), ioread32(0xF20C5144)); memset(&cmd->ctx, 0, sizeof(g2d_context_t)); #ifdef G2D_QUEUE if (cmd->sync_cmd) { cmd->sync_cmd = false; up(&cmd->sync); } up(&cmd->lock); #endif }
unsigned int _m4u_g2d_init(void) { M4U_PORT_STRUCT m4u_port; if (!_m4u_g2d_func.isInit) { G2D_ERR("m4u is not initialized\n"); return -1; } m4u_port.ePortID = M4U_PORT_G2D_R; m4u_port.Virtuality = 1; m4u_port.Security = 0; m4u_port.Distance = 1; m4u_port.Direction = 0; _m4u_g2d_func.m4u_config_port(&m4u_port); m4u_port.ePortID = M4U_PORT_G2D_W; m4u_port.Virtuality = 1; m4u_port.Security = 0; m4u_port.Distance = 1; m4u_port.Direction = 0; _m4u_g2d_func.m4u_config_port(&m4u_port); return 0; }
static int __init g2d_init(void) { G2D_INF("initializeing driver...\n"); if (platform_device_register(&g2d_device)) { G2D_ERR("failed to register device\n"); return -ENODEV; } if (platform_driver_register(&g2d_driver)) { G2D_ERR("failed to register driver\n"); platform_device_unregister(&g2d_device); return -ENODEV; } return 0; }
int g2d_deallocate_mva(unsigned int va, unsigned int mva, unsigned int size) { if (!_m4u_g2d_func.isInit) { G2D_ERR("m4u is not initialized\n"); return -1; } G2D_DBG("try to deallocate mva with 0x%x (%d)\n", va, size); _m4u_g2d_func.m4u_invalid_tlb_range(M4U_CLNTMOD_G2D, mva, mva + size - 1); _m4u_g2d_func.m4u_dealloc_mva(M4U_CLNTMOD_G2D, va, size, mva); return 0; }
static unsigned int _g2d_get_pitch_byte(int pitch_pixel, int color_format) { unsigned int pitch_byte; pitch_byte = pitch_pixel; switch (color_format) { case G2D_COLOR_FORMAT_RGB565: case G2D_COLOR_FORMAT_UYVY: pitch_byte *= 2; break; case G2D_COLOR_FORMAT_RGB888: case G2D_COLOR_FORMAT_BGR888: pitch_byte *= 3; break; case G2D_COLOR_FORMAT_ARGB8888: case G2D_COLOR_FORMAT_ABGR8888: case G2D_COLOR_FORMAT_PARGB8888: case G2D_COLOR_FORMAT_PABGR8888: case G2D_COLOR_FORMAT_XRGB8888: case G2D_COLOR_FORMAT_XBGR8888: case G2D_COLOR_FORMAT_BGRA8888: pitch_byte *= 4; break; default: G2D_ERR("***** invalid color format (%02X) *****\n", color_format); ASSERT(0); break; } return pitch_byte; }
static long g2d_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int ret = 0; switch (cmd) { #ifdef G2D_QUEUE case G2D_IOCTL_ASYNCCMD: ret = _g2d_queue_command(arg, false); G2D_DBG("insert async command successfully\n"); break; case G2D_IOCTL_SYNCCMD: ret = _g2d_queue_command(arg, true); G2D_DBG("insert sync command successfully\n"); break; #else case G2D_IOCTL_SYNCCMD: spin_lock(&g2d_cmd_spinlock); if (copy_from_user(&g2d_cmd_buffer->ctx, (void *)arg, sizeof(g2d_context_t))) { G2D_ERR("copy from user is failed\n"); return -EFAULT; } _g2d_command_handler(g2d_cmd_buffer); spin_unlock(&g2d_cmd_spinlock); break; #endif case G2D_IOCTL_CONNECTFB: if (g2d_drv_fb_init() != 0) { G2D_ERR("failed to connect fb driver\n"); return -EFAULT; } break; case G2D_IOCTL_DISCONNECTFB: g2d_drv_fb_deinit(); break; case G2D_IOCTL_DEQUEUEFB: { fb_buffer_t *buffer = g2d_drv_fb_dequeue_buffer(); if (buffer == NULL) { G2D_ERR("failed to get framebuffer\n"); return -EFAULT; } if (copy_to_user((void *)arg, &buffer->info, sizeof(g2d_buffer_t))) { G2D_ERR("copy to user is failed\n"); return -EFAULT; } } break; case G2D_IOCTL_ENQUEUEFB: #ifdef G2D_QUEUE { g2d_context_t ctx; memset(&ctx, 0, sizeof(g2d_context_t)); ctx.flag = G2D_FLAG_END_OF_FRAME; if (copy_from_user(&ctx.fb_id, (void *)arg, sizeof(int))) { G2D_ERR("copy from user is failed\n"); return -EFAULT; } _g2d_queue_command2(&ctx, false); } #else { spin_lock(&g2d_cmd_spinlock); g2d_cmd_buffer->ctx.flag = G2D_FLAG_END_OF_FRAME; if (copy_from_user(&g2d_cmd_buffer->ctx.fb_id, (void *)arg, sizeof(int))) { G2D_ERR("copy from user is failed\n"); return -EFAULT; } _g2d_command_handler(g2d_cmd_buffer); spin_unlock(&g2d_cmd_spinlock); } #endif break; } return ret; }