📄 ivtv-yuv.c
字号:
/* yuv support Copyright (C) 2007 Ian Armstrong <ian@iarmst.demon.co.uk> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "ivtv-driver.h"#include "ivtv-udma.h"#include "ivtv-yuv.h"/* YUV buffer offsets */const u32 yuv_offset[IVTV_YUV_BUFFERS] = { 0x001a8600, 0x00240400, 0x002d8200, 0x00370000, 0x00029000, 0x000C0E00, 0x006B0400, 0x00748200};static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma, struct ivtv_dma_frame *args){ struct ivtv_dma_page_info y_dma; struct ivtv_dma_page_info uv_dma; struct yuv_playback_info *yi = &itv->yuv_info; u8 frame = yi->draw_frame; struct yuv_frame_info *f = &yi->new_frame_info[frame]; int i; int y_pages, uv_pages; unsigned long y_buffer_offset, uv_buffer_offset; int y_decode_height, uv_decode_height, y_size; y_buffer_offset = IVTV_DECODER_OFFSET + yuv_offset[frame]; uv_buffer_offset = y_buffer_offset + IVTV_YUV_BUFFER_UV_OFFSET; y_decode_height = uv_decode_height = f->src_h + f->src_y; if (f->offset_y) y_buffer_offset += 720 * 16; if (y_decode_height & 15) y_decode_height = (y_decode_height + 16) & ~15; if (uv_decode_height & 31) uv_decode_height = (uv_decode_height + 32) & ~31; y_size = 720 * y_decode_height; /* Still in USE */ if (dma->SG_length || dma->page_count) { IVTV_DEBUG_WARN ("prep_user_dma: SG_length %d page_count %d still full?\n", dma->SG_length, dma->page_count); return -EBUSY; } ivtv_udma_get_page_info (&y_dma, (unsigned long)args->y_source, 720 * y_decode_height); ivtv_udma_get_page_info (&uv_dma, (unsigned long)args->uv_source, 360 * uv_decode_height); /* Get user pages for DMA Xfer */ down_read(¤t->mm->mmap_sem); y_pages = get_user_pages(current, current->mm, y_dma.uaddr, y_dma.page_count, 0, 1, &dma->map[0], NULL); uv_pages = get_user_pages(current, current->mm, uv_dma.uaddr, uv_dma.page_count, 0, 1, &dma->map[y_pages], NULL); up_read(¤t->mm->mmap_sem); dma->page_count = y_dma.page_count + uv_dma.page_count; if (y_pages + uv_pages != dma->page_count) { IVTV_DEBUG_WARN ("failed to map user pages, returned %d instead of %d\n", y_pages + uv_pages, dma->page_count); for (i = 0; i < dma->page_count; i++) { put_page(dma->map[i]); } dma->page_count = 0; return -EINVAL; } /* Fill & map SG List */ if (ivtv_udma_fill_sg_list (dma, &uv_dma, ivtv_udma_fill_sg_list (dma, &y_dma, 0)) < 0) { IVTV_DEBUG_WARN("could not allocate bounce buffers for highmem userspace buffers\n"); for (i = 0; i < dma->page_count; i++) { put_page(dma->map[i]); } dma->page_count = 0; return -ENOMEM; } dma->SG_length = pci_map_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE); /* Fill SG Array with new values */ ivtv_udma_fill_sg_array(dma, y_buffer_offset, uv_buffer_offset, y_size); /* If we've offset the y plane, ensure top area is blanked */ if (f->offset_y && yi->blanking_dmaptr) { dma->SGarray[dma->SG_length].size = cpu_to_le32(720*16); dma->SGarray[dma->SG_length].src = cpu_to_le32(yi->blanking_dmaptr); dma->SGarray[dma->SG_length].dst = cpu_to_le32(IVTV_DECODER_OFFSET + yuv_offset[frame]); dma->SG_length++; } /* Tag SG Array with Interrupt Bit */ dma->SGarray[dma->SG_length - 1].size |= cpu_to_le32(0x80000000); ivtv_udma_sync_for_device(itv); return 0;}/* We rely on a table held in the firmware - Quick check. */int ivtv_yuv_filter_check(struct ivtv *itv){ int i, y, uv; for (i = 0, y = 16, uv = 4; i < 16; i++, y += 24, uv += 12) { if ((read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + y) != i << 16) || (read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + uv) != i << 16)) { IVTV_WARN ("YUV filter table not found in firmware.\n"); return -1; } } return 0;}static void ivtv_yuv_filter(struct ivtv *itv, int h_filter, int v_filter_1, int v_filter_2){ u32 i, line; /* If any filter is -1, then don't update it */ if (h_filter > -1) { if (h_filter > 4) h_filter = 4; i = IVTV_YUV_HORIZONTAL_FILTER_OFFSET + (h_filter * 384); for (line = 0; line < 16; line++) { write_reg(read_dec(i), 0x02804); write_reg(read_dec(i), 0x0281c); i += 4; write_reg(read_dec(i), 0x02808); write_reg(read_dec(i), 0x02820); i += 4; write_reg(read_dec(i), 0x0280c); write_reg(read_dec(i), 0x02824); i += 4; write_reg(read_dec(i), 0x02810); write_reg(read_dec(i), 0x02828); i += 4; write_reg(read_dec(i), 0x02814); write_reg(read_dec(i), 0x0282c); i += 8; write_reg(0, 0x02818); write_reg(0, 0x02830); } IVTV_DEBUG_YUV("h_filter -> %d\n", h_filter); } if (v_filter_1 > -1) { if (v_filter_1 > 4) v_filter_1 = 4; i = IVTV_YUV_VERTICAL_FILTER_OFFSET + (v_filter_1 * 192); for (line = 0; line < 16; line++) { write_reg(read_dec(i), 0x02900); i += 4; write_reg(read_dec(i), 0x02904); i += 8; write_reg(0, 0x02908); } IVTV_DEBUG_YUV("v_filter_1 -> %d\n", v_filter_1); } if (v_filter_2 > -1) { if (v_filter_2 > 4) v_filter_2 = 4; i = IVTV_YUV_VERTICAL_FILTER_OFFSET + (v_filter_2 * 192); for (line = 0; line < 16; line++) { write_reg(read_dec(i), 0x0290c); i += 4; write_reg(read_dec(i), 0x02910); i += 8; write_reg(0, 0x02914); } IVTV_DEBUG_YUV("v_filter_2 -> %d\n", v_filter_2); }}static void ivtv_yuv_handle_horizontal(struct ivtv *itv, struct yuv_frame_info *f){ struct yuv_playback_info *yi = &itv->yuv_info; u32 reg_2834, reg_2838, reg_283c; u32 reg_2844, reg_2854, reg_285c; u32 reg_2864, reg_2874, reg_2890; u32 reg_2870, reg_2870_base, reg_2870_offset; int x_cutoff; int h_filter; u32 master_width; IVTV_DEBUG_WARN ("Adjust to width %d src_w %d dst_w %d src_x %d dst_x %d\n", f->tru_w, f->src_w, f->dst_w, f->src_x, f->dst_x); /* How wide is the src image */ x_cutoff = f->src_w + f->src_x; /* Set the display width */ reg_2834 = f->dst_w; reg_2838 = reg_2834; /* Set the display position */ reg_2890 = f->dst_x; /* Index into the image horizontally */ reg_2870 = 0; /* 2870 is normally fudged to align video coords with osd coords. If running full screen, it causes an unwanted left shift Remove the fudge if we almost fill the screen. Gradually adjust the offset to avoid the video 'snapping' left/right if it gets dragged through this region. Only do this if osd is full width. */ if (f->vis_w == 720) { if ((f->tru_x - f->pan_x > -1) && (f->tru_x - f->pan_x <= 40) && (f->dst_w >= 680)) reg_2870 = 10 - (f->tru_x - f->pan_x) / 4; else if ((f->tru_x - f->pan_x < 0) && (f->tru_x - f->pan_x >= -20) && (f->dst_w >= 660)) reg_2870 = (10 + (f->tru_x - f->pan_x) / 2); if (f->dst_w >= f->src_w) reg_2870 = reg_2870 << 16 | reg_2870; else reg_2870 = ((reg_2870 & ~1) << 15) | (reg_2870 & ~1); } if (f->dst_w < f->src_w) reg_2870 = 0x000d000e - reg_2870; else reg_2870 = 0x0012000e - reg_2870; /* We're also using 2870 to shift the image left (src_x & negative dst_x) */ reg_2870_offset = (f->src_x * ((f->dst_w << 21) / f->src_w)) >> 19; if (f->dst_w >= f->src_w) { x_cutoff &= ~1; master_width = (f->src_w * 0x00200000) / (f->dst_w); if (master_width * f->dst_w != f->src_w * 0x00200000) master_width++; reg_2834 = (reg_2834 << 16) | x_cutoff; reg_2838 = (reg_2838 << 16) | x_cutoff; reg_283c = master_width >> 2; reg_2844 = master_width >> 2; reg_2854 = master_width; reg_285c = master_width >> 1; reg_2864 = master_width >> 1; /* We also need to factor in the scaling (src_w - dst_w) / (src_w / 4) */ if (f->dst_w > f->src_w) reg_2870_base = ((f->dst_w - f->src_w)<<16) / (f->src_w <<14); else reg_2870_base = 0; reg_2870 += (((reg_2870_offset << 14) & 0xFFFF0000) | reg_2870_offset >> 2) + (reg_2870_base << 17 | reg_2870_base); reg_2874 = 0; } else if (f->dst_w < f->src_w / 2) { master_width = (f->src_w * 0x00080000) / f->dst_w; if (master_width * f->dst_w != f->src_w * 0x00080000) master_width++; reg_2834 = (reg_2834 << 16) | x_cutoff; reg_2838 = (reg_2838 << 16) | x_cutoff; reg_283c = master_width >> 2; reg_2844 = master_width >> 1; reg_2854 = master_width; reg_285c = master_width >> 1; reg_2864 = master_width >> 1; reg_2870 += ((reg_2870_offset << 15) & 0xFFFF0000) | reg_2870_offset; reg_2870 += (5 - (((f->src_w + f->src_w / 2) - 1) / f->dst_w)) << 16; reg_2874 = 0x00000012; } else { master_width = (f->src_w * 0x00100000) / f->dst_w; if (master_width * f->dst_w != f->src_w * 0x00100000) master_width++; reg_2834 = (reg_2834 << 16) | x_cutoff; reg_2838 = (reg_2838 << 16) | x_cutoff; reg_283c = master_width >> 2; reg_2844 = master_width >> 1; reg_2854 = master_width; reg_285c = master_width >> 1; reg_2864 = master_width >> 1; reg_2870 += ((reg_2870_offset << 14) & 0xFFFF0000) | reg_2870_offset >> 1; reg_2870 += (5 - (((f->src_w * 3) - 1) / f->dst_w)) << 16; reg_2874 = 0x00000001; } /* Select the horizontal filter */ if (f->src_w == f->dst_w) { /* An exact size match uses filter 0 */ h_filter = 0; } else { /* Figure out which filter to use */ h_filter = ((f->src_w << 16) / f->dst_w) >> 15; h_filter = (h_filter >> 1) + (h_filter & 1); /* Only an exact size match can use filter 0 */ h_filter += !h_filter; } write_reg(reg_2834, 0x02834); write_reg(reg_2838, 0x02838); IVTV_DEBUG_YUV("Update reg 0x2834 %08x->%08x 0x2838 %08x->%08x\n", yi->reg_2834, reg_2834, yi->reg_2838, reg_2838); write_reg(reg_283c, 0x0283c); write_reg(reg_2844, 0x02844); IVTV_DEBUG_YUV("Update reg 0x283c %08x->%08x 0x2844 %08x->%08x\n", yi->reg_283c, reg_283c, yi->reg_2844, reg_2844); write_reg(0x00080514, 0x02840); write_reg(0x00100514, 0x02848); IVTV_DEBUG_YUV("Update reg 0x2840 %08x->%08x 0x2848 %08x->%08x\n", yi->reg_2840, 0x00080514, yi->reg_2848, 0x00100514); write_reg(reg_2854, 0x02854); IVTV_DEBUG_YUV("Update reg 0x2854 %08x->%08x \n", yi->reg_2854, reg_2854); write_reg(reg_285c, 0x0285c); write_reg(reg_2864, 0x02864); IVTV_DEBUG_YUV("Update reg 0x285c %08x->%08x 0x2864 %08x->%08x\n", yi->reg_285c, reg_285c, yi->reg_2864, reg_2864); write_reg(reg_2874, 0x02874); IVTV_DEBUG_YUV("Update reg 0x2874 %08x->%08x\n", yi->reg_2874, reg_2874); write_reg(reg_2870, 0x02870); IVTV_DEBUG_YUV("Update reg 0x2870 %08x->%08x\n", yi->reg_2870, reg_2870); write_reg(reg_2890, 0x02890); IVTV_DEBUG_YUV("Update reg 0x2890 %08x->%08x\n", yi->reg_2890, reg_2890); /* Only update the filter if we really need to */ if (h_filter != yi->h_filter) { ivtv_yuv_filter(itv, h_filter, -1, -1); yi->h_filter = h_filter; }}static void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *f){ struct yuv_playback_info *yi = &itv->yuv_info; u32 master_height; u32 reg_2918, reg_291c, reg_2920, reg_2928; u32 reg_2930, reg_2934, reg_293c; u32 reg_2940, reg_2944, reg_294c; u32 reg_2950, reg_2954, reg_2958, reg_295c; u32 reg_2960, reg_2964, reg_2968, reg_296c; u32 reg_289c; u32 src_major_y, src_minor_y; u32 src_major_uv, src_minor_uv; u32 reg_2964_base, reg_2968_base; int v_filter_1, v_filter_2; IVTV_DEBUG_WARN ("Adjust to height %d src_h %d dst_h %d src_y %d dst_y %d\n", f->tru_h, f->src_h, f->dst_h, f->src_y, f->dst_y); /* What scaling mode is being used... */ IVTV_DEBUG_YUV("Scaling mode Y: %s\n", f->interlaced_y ? "Interlaced" : "Progressive"); IVTV_DEBUG_YUV("Scaling mode UV: %s\n", f->interlaced_uv ? "Interlaced" : "Progressive"); /* What is the source video being treated as... */ IVTV_DEBUG_WARN("Source video: %s\n", f->interlaced ? "Interlaced" : "Progressive"); /* We offset into the image using two different index methods, so split the y source coord into two parts. */ if (f->src_y < 8) { src_minor_uv = f->src_y; src_major_uv = 0; } else { src_minor_uv = 8; src_major_uv = f->src_y - 8; } src_minor_y = src_minor_uv; src_major_y = src_major_uv; if (f->offset_y) src_minor_y += 16; if (f->interlaced_y) reg_2918 = (f->dst_h << 16) | (f->src_h + src_minor_y); else reg_2918 = (f->dst_h << 16) | ((f->src_h + src_minor_y) << 1); if (f->interlaced_uv) reg_291c = (f->dst_h << 16) | ((f->src_h + src_minor_uv) >> 1); else reg_291c = (f->dst_h << 16) | (f->src_h + src_minor_uv);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -