Files
Nathan Chancellor 53fa127964 Merge 4.4.128 into android-msm-wahoo-4.4-oreo-m2
Changes in 4.4.128: (192 commits)
        cfg80211: make RATE_INFO_BW_20 the default
        md/raid5: make use of spin_lock_irq over local_irq_disable + spin_lock
        rtc: snvs: fix an incorrect check of return value
        x86/asm: Don't use RBP as a temporary register in csum_partial_copy_generic()
        NFSv4.1: RECLAIM_COMPLETE must handle NFS4ERR_CONN_NOT_BOUND_TO_SESSION
        IB/srpt: Fix abort handling
        af_key: Fix slab-out-of-bounds in pfkey_compile_policy.
        mac80211: bail out from prep_connection() if a reconfig is ongoing
        bna: Avoid reading past end of buffer
        qlge: Avoid reading past end of buffer
        ipmi_ssif: unlock on allocation failure
        net: cdc_ncm: Fix TX zero padding
        net: ethernet: ti: cpsw: adjust cpsw fifos depth for fullduplex flow control
        lockd: fix lockd shutdown race
        drivers/misc/vmw_vmci/vmci_queue_pair.c: fix a couple integer overflow tests
        pidns: disable pid allocation if pid_ns_prepare_proc() is failed in alloc_pid()
        s390: move _text symbol to address higher than zero
        net/mlx4_en: Avoid adding steering rules with invalid ring
        NFSv4.1: Work around a Linux server bug...
        CIFS: silence lockdep splat in cifs_relock_file()
        blk-mq: NVMe 512B/4K+T10 DIF/DIX format returns I/O error on dd with split op
        net: qca_spi: Fix alignment issues in rx path
        netxen_nic: set rcode to the return status from the call to netxen_issue_cmd
        Input: elan_i2c - check if device is there before really probing
        Input: elantech - force relative mode on a certain module
        KVM: PPC: Book3S PR: Check copy_to/from_user return values
        vmxnet3: ensure that adapter is in proper state during force_close
        SMB2: Fix share type handling
        bus: brcmstb_gisb: Use register offsets with writes too
        bus: brcmstb_gisb: correct support for 64-bit address output
        PowerCap: Fix an error code in powercap_register_zone()
        ARM: dts: imx53-qsrb: Pulldown PMIC IRQ pin
        staging: wlan-ng: prism2mgmt.c: fixed a double endian conversion before calling hfa384x_drvr_setconfig16, also fixes relative sparse warning
        x86/tsc: Provide 'tsc=unstable' boot parameter
        ARM: dts: imx6qdl-wandboard: Fix audio channel swap
        ipv6: avoid dad-failures for addresses with NODAD
        async_tx: Fix DMA_PREP_FENCE usage in do_async_gen_syndrome()
        usb: dwc3: keystone: check return value
        btrfs: fix incorrect error return ret being passed to mapping_set_error
        ata: libahci: properly propagate return value of platform_get_irq()
        neighbour: update neigh timestamps iff update is effective
        arp: honour gratuitous ARP _replies_
        usb: chipidea: properly handle host or gadget initialization failure
        USB: ene_usb6250: fix first command execution
        net: x25: fix one potential use-after-free issue
        USB: ene_usb6250: fix SCSI residue overwriting
        serial: 8250: omap: Disable DMA for console UART
        serial: sh-sci: Fix race condition causing garbage during shutdown
        sh_eth: Use platform device for printing before register_netdev()
        scsi: csiostor: fix use after free in csio_hw_use_fwconfig()
        powerpc/mm: Fix virt_addr_valid() etc. on 64-bit hash
        ath5k: fix memory leak on buf on failed eeprom read
        selftests/powerpc: Fix TM resched DSCR test with some compilers
        xfrm: fix state migration copy replay sequence numbers
        iio: hi8435: avoid garbage event at first enable
        iio: hi8435: cleanup reset gpio
        ext4: handle the rest of ext4_mb_load_buddy() ENOMEM errors
        md-cluster: fix potential lock issue in add_new_disk
        ARM: davinci: da8xx: Create DSP device only when assigned memory
        ray_cs: Avoid reading past end of buffer
        leds: pca955x: Correct I2C Functionality
        sched/numa: Use down_read_trylock() for the mmap_sem
        net/mlx5: Tolerate irq_set_affinity_hint() failures
        selinux: do not check open permission on sockets
        block: fix an error code in add_partition()
        mlx5: fix bug reading rss_hash_type from CQE
        net: ieee802154: fix net_device reference release too early
        libceph: NULL deref on crush_decode() error path
        netfilter: ctnetlink: fix incorrect nf_ct_put during hash resize
        pNFS/flexfiles: missing error code in ff_layout_alloc_lseg()
        ASoC: rsnd: SSI PIO adjust to 24bit mode
        scsi: bnx2fc: fix race condition in bnx2fc_get_host_stats()
        fix race in drivers/char/random.c:get_reg()
        ext4: fix off-by-one on max nr_pages in ext4_find_unwritten_pgoff()
        tcp: better validation of received ack sequences
        net: move somaxconn init from sysctl code
        Input: elan_i2c - clear INT before resetting controller
        bonding: Don't update slave->link until ready to commit
        KVM: nVMX: Fix handling of lmsw instruction
        net: llc: add lock_sock in llc_ui_bind to avoid a race condition
        ARM: dts: ls1021a: add "fsl,ls1021a-esdhc" compatible string to esdhc node
        thermal: power_allocator: fix one race condition issue for thermal_instances list
        perf probe: Add warning message if there is unexpected event name
        l2tp: fix missing print session offset info
        rds; Reset rs->rs_bound_addr in rds_add_bound() failure path
        hwmon: (ina2xx) Make calibration register value fixed
        media: videobuf2-core: don't go out of the buffer range
        ASoC: Intel: cht_bsw_rt5645: Analog Mic support
        scsi: libiscsi: Allow sd_shutdown on bad transport
        scsi: mpt3sas: Proper handling of set/clear of "ATA command pending" flag.
        vfb: fix video mode and line_length being set when loaded
        gpio: label descriptors using the device name
        ASoC: Intel: sst: Fix the return value of 'sst_send_byte_stream_mrfld()'
        wl1251: check return from call to wl1251_acx_arp_ip_filter
        hdlcdrv: Fix divide by zero in hdlcdrv_ioctl
        ovl: filter trusted xattr for non-admin
        powerpc/[booke|4xx]: Don't clobber TCR[WP] when setting TCR[DIE]
        dmaengine: imx-sdma: Handle return value of clk_prepare_enable
        arm64: futex: Fix undefined behaviour with FUTEX_OP_OPARG_SHIFT usage
        net/mlx5: avoid build warning for uniprocessor
        cxgb4: FW upgrade fixes
        rtc: opal: Handle disabled TPO in opal_get_tpo_time()
        rtc: interface: Validate alarm-time before handling rollover
        SUNRPC: ensure correct error is reported by xs_tcp_setup_socket()
        net: freescale: fix potential null pointer dereference
        KVM: SVM: do not zero out segment attributes if segment is unusable or not present
        clk: scpi: fix return type of __scpi_dvfs_round_rate
        clk: Fix __set_clk_rates error print-string
        powerpc/spufs: Fix coredump of SPU contexts
        perf trace: Add mmap alias for s390
        qlcnic: Fix a sleep-in-atomic bug in qlcnic_82xx_hw_write_wx_2M and qlcnic_82xx_hw_read_wx_2M
        mISDN: Fix a sleep-in-atomic bug
        drm/omap: fix tiled buffer stride calculations
        cxgb4: fix incorrect cim_la output for T6
        Fix serial console on SNI RM400 machines
        bio-integrity: Do not allocate integrity context for bio w/o data
        skbuff: return -EMSGSIZE in skb_to_sgvec to prevent overflow
        sit: reload iphdr in ipip6_rcv
        net/mlx4: Fix the check in attaching steering rules
        net/mlx4: Check if Granular QoS per VF has been enabled before updating QP qos_vport
        perf header: Set proper module name when build-id event found
        perf report: Ensure the perf DSO mapping matches what libdw sees
        tags: honor COMPILED_SOURCE with apart output directory
        e1000e: fix race condition around skb_tstamp_tx()
        cx25840: fix unchecked return values
        mceusb: sporadic RX truncation corruption fix
        net: phy: avoid genphy_aneg_done() for PHYs without clause 22 support
        ARM: imx: Add MXC_CPU_IMX6ULL and cpu_is_imx6ull
        e1000e: Undo e1000e_pm_freeze if __e1000_shutdown fails
        perf/core: Correct event creation with PERF_FORMAT_GROUP
        MIPS: mm: fixed mappings: correct initialisation
        MIPS: mm: adjust PKMAP location
        MIPS: kprobes: flush_insn_slot should flush only if probe initialised
        Fix loop device flush before configure v3
        net: emac: fix reset timeout with AR8035 phy
        perf tests: Decompress kernel module before objdump
        skbuff: only inherit relevant tx_flags
        xen: avoid type warning in xchg_xen_ulong
        bnx2x: Allow vfs to disable txvlan offload
        sctp: fix recursive locking warning in sctp_do_peeloff
        sparc64: ldc abort during vds iso boot
        iio: magnetometer: st_magn_spi: fix spi_device_id table
        Bluetooth: Send HCI Set Event Mask Page 2 command only when needed
        cpuidle: dt: Add missing 'of_node_put()'
        ACPICA: Events: Add runtime stub support for event APIs
        ACPICA: Disassembler: Abort on an invalid/unknown AML opcode
        s390/dasd: fix hanging safe offline
        vxlan: dont migrate permanent fdb entries during learn
        bcache: stop writeback thread after detaching
        bcache: segregate flash only volume write streams
        scsi: libsas: fix memory leak in sas_smp_get_phy_events()
        scsi: libsas: fix error when getting phy events
        scsi: libsas: initialize sas_phy status according to response of DISCOVER
        blk-mq: fix kernel oops in blk_mq_tag_idle()
        tty: n_gsm: Allow ADM response in addition to UA for control dlci
        EDAC, mv64x60: Fix an error handling path
        cxgb4vf: Fix SGE FL buffer initialization logic for 64K pages
        perf tools: Fix copyfile_offset update of output offset
        ipsec: check return value of skb_to_sgvec always
        rxrpc: check return value of skb_to_sgvec always
        virtio_net: check return value of skb_to_sgvec always
        virtio_net: check return value of skb_to_sgvec in one more location
        random: use lockless method of accessing and updating f->reg_idx
        futex: Remove requirement for lock_page() in get_futex_key()
        Kbuild: provide a __UNIQUE_ID for clang
        arp: fix arp_filter on l3slave devices
        net: fix possible out-of-bound read in skb_network_protocol()
        net/ipv6: Fix route leaking between VRFs
        netlink: make sure nladdr has correct size in netlink_connect()
        net/sched: fix NULL dereference in the error path of tcf_bpf_init()
        pptp: remove a buggy dst release in pptp_connect()
        sctp: do not leak kernel memory to user space
        sctp: sctp_sockaddr_af must check minimal addr length for AF_INET6
        sky2: Increase D3 delay to sky2 stops working after suspend
        vhost: correctly remove wait queue during poll failure
        vlan: also check phy_driver ts_info for vlan's real device
        bonding: fix the err path for dev hwaddr sync in bond_enslave
        bonding: move dev_mc_sync after master_upper_dev_link in bond_enslave
        bonding: process the err returned by dev_set_allmulti properly in bond_enslave
        net: fool proof dev_valid_name()
        ip_tunnel: better validate user provided tunnel names
        ipv6: sit: better validate user provided tunnel names
        ip6_gre: better validate user provided tunnel names
        ip6_tunnel: better validate user provided tunnel names
        vti6: better validate user provided tunnel names
        r8169: fix setting driver_data after register_netdev
        net sched actions: fix dumping which requires several messages to user space
        net/ipv6: Increment OUTxxx counters after netfilter hook
        ipv6: the entire IPv6 header chain must fit the first fragment
        vrf: Fix use after free and double free in vrf_finish_output
        Revert "xhci: plat: Register shutdown for xhci_plat"
        Linux 4.4.128

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Conflicts:
	include/linux/compiler-clang.h
2018-04-13 13:26:09 -07:00

642 lines
15 KiB
C

/*
* linux/drivers/video/vfb.c -- Virtual frame buffer device
*
* Copyright (C) 2002 James Simmons
*
* Copyright (C) 1997 Geert Uytterhoeven
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/fb.h>
#include <linux/init.h>
/*
* RAM we reserve for the frame buffer. This defines the maximum screen
* size
*
* The default can be overridden if the driver is compiled as a module
*/
#define VIDEOMEMSIZE (1*1024*1024) /* 1 MB */
static void *videomemory;
static u_long videomemorysize = VIDEOMEMSIZE;
module_param(videomemorysize, ulong, 0);
static char *mode_option;
static int bpp = 8;
module_param(mode_option, charp, 0);
MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
module_param(bpp, int, 0);
/**********************************************************************
*
* Memory management
*
**********************************************************************/
static void *rvmalloc(unsigned long size)
{
void *mem;
unsigned long adr;
size = PAGE_ALIGN(size);
mem = vmalloc_32(size);
if (!mem)
return NULL;
/*
* VFB must clear memory to prevent kernel info
* leakage into userspace
* VGA-based drivers MUST NOT clear memory if
* they want to be able to take over vgacon
*/
memset(mem, 0, size);
adr = (unsigned long) mem;
while (size > 0) {
SetPageReserved(vmalloc_to_page((void *)adr));
adr += PAGE_SIZE;
size -= PAGE_SIZE;
}
return mem;
}
static void rvfree(void *mem, unsigned long size)
{
unsigned long adr;
if (!mem)
return;
adr = (unsigned long) mem;
while ((long) size > 0) {
ClearPageReserved(vmalloc_to_page((void *)adr));
adr += PAGE_SIZE;
size -= PAGE_SIZE;
}
vfree(mem);
}
static struct fb_var_screeninfo vfb_default = {
.xres = 640,
.yres = 480,
.xres_virtual = 640,
.yres_virtual = 480,
.bits_per_pixel = 8,
.red = { 0, 8, 0 },
.green = { 0, 8, 0 },
.blue = { 0, 8, 0 },
.activate = FB_ACTIVATE_TEST,
.height = -1,
.width = -1,
.pixclock = 20000,
.left_margin = 64,
.right_margin = 64,
.upper_margin = 32,
.lower_margin = 32,
.hsync_len = 64,
.vsync_len = 2,
.vmode = FB_VMODE_NONINTERLACED,
};
static struct fb_fix_screeninfo vfb_fix = {
.id = "Virtual FB",
.type = FB_TYPE_PACKED_PIXELS,
.visual = FB_VISUAL_PSEUDOCOLOR,
.xpanstep = 1,
.ypanstep = 1,
.ywrapstep = 1,
.accel = FB_ACCEL_NONE,
};
static bool vfb_enable __initdata = 0; /* disabled by default */
module_param(vfb_enable, bool, 0);
static int vfb_check_var(struct fb_var_screeninfo *var,
struct fb_info *info);
static int vfb_set_par(struct fb_info *info);
static int vfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
u_int transp, struct fb_info *info);
static int vfb_pan_display(struct fb_var_screeninfo *var,
struct fb_info *info);
static int vfb_mmap(struct fb_info *info,
struct vm_area_struct *vma);
static struct fb_ops vfb_ops = {
.fb_read = fb_sys_read,
.fb_write = fb_sys_write,
.fb_check_var = vfb_check_var,
.fb_set_par = vfb_set_par,
.fb_setcolreg = vfb_setcolreg,
.fb_pan_display = vfb_pan_display,
.fb_fillrect = sys_fillrect,
.fb_copyarea = sys_copyarea,
.fb_imageblit = sys_imageblit,
.fb_mmap = vfb_mmap,
};
/*
* Internal routines
*/
static u_long get_line_length(int xres_virtual, int bpp)
{
u_long length;
length = xres_virtual * bpp;
length = (length + 31) & ~31;
length >>= 3;
return (length);
}
/*
* Setting the video mode has been split into two parts.
* First part, xxxfb_check_var, must not write anything
* to hardware, it should only verify and adjust var.
* This means it doesn't alter par but it does use hardware
* data from it to check this var.
*/
static int vfb_check_var(struct fb_var_screeninfo *var,
struct fb_info *info)
{
u_long line_length;
/*
* FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
* as FB_VMODE_SMOOTH_XPAN is only used internally
*/
if (var->vmode & FB_VMODE_CONUPDATE) {
var->vmode |= FB_VMODE_YWRAP;
var->xoffset = info->var.xoffset;
var->yoffset = info->var.yoffset;
}
/*
* Some very basic checks
*/
if (!var->xres)
var->xres = 1;
if (!var->yres)
var->yres = 1;
if (var->xres > var->xres_virtual)
var->xres_virtual = var->xres;
if (var->yres > var->yres_virtual)
var->yres_virtual = var->yres;
if (var->bits_per_pixel <= 1)
var->bits_per_pixel = 1;
else if (var->bits_per_pixel <= 8)
var->bits_per_pixel = 8;
else if (var->bits_per_pixel <= 16)
var->bits_per_pixel = 16;
else if (var->bits_per_pixel <= 24)
var->bits_per_pixel = 24;
else if (var->bits_per_pixel <= 32)
var->bits_per_pixel = 32;
else
return -EINVAL;
if (var->xres_virtual < var->xoffset + var->xres)
var->xres_virtual = var->xoffset + var->xres;
if (var->yres_virtual < var->yoffset + var->yres)
var->yres_virtual = var->yoffset + var->yres;
/*
* Memory limit
*/
line_length =
get_line_length(var->xres_virtual, var->bits_per_pixel);
if (line_length * var->yres_virtual > videomemorysize)
return -ENOMEM;
/*
* Now that we checked it we alter var. The reason being is that the video
* mode passed in might not work but slight changes to it might make it
* work. This way we let the user know what is acceptable.
*/
switch (var->bits_per_pixel) {
case 1:
case 8:
var->red.offset = 0;
var->red.length = 8;
var->green.offset = 0;
var->green.length = 8;
var->blue.offset = 0;
var->blue.length = 8;
var->transp.offset = 0;
var->transp.length = 0;
break;
case 16: /* RGBA 5551 */
if (var->transp.length) {
var->red.offset = 0;
var->red.length = 5;
var->green.offset = 5;
var->green.length = 5;
var->blue.offset = 10;
var->blue.length = 5;
var->transp.offset = 15;
var->transp.length = 1;
} else { /* RGB 565 */
var->red.offset = 0;
var->red.length = 5;
var->green.offset = 5;
var->green.length = 6;
var->blue.offset = 11;
var->blue.length = 5;
var->transp.offset = 0;
var->transp.length = 0;
}
break;
case 24: /* RGB 888 */
var->red.offset = 0;
var->red.length = 8;
var->green.offset = 8;
var->green.length = 8;
var->blue.offset = 16;
var->blue.length = 8;
var->transp.offset = 0;
var->transp.length = 0;
break;
case 32: /* RGBA 8888 */
var->red.offset = 0;
var->red.length = 8;
var->green.offset = 8;
var->green.length = 8;
var->blue.offset = 16;
var->blue.length = 8;
var->transp.offset = 24;
var->transp.length = 8;
break;
}
var->red.msb_right = 0;
var->green.msb_right = 0;
var->blue.msb_right = 0;
var->transp.msb_right = 0;
return 0;
}
/* This routine actually sets the video mode. It's in here where we
* the hardware state info->par and fix which can be affected by the
* change in par. For this driver it doesn't do much.
*/
static int vfb_set_par(struct fb_info *info)
{
switch (info->var.bits_per_pixel) {
case 1:
info->fix.visual = FB_VISUAL_MONO01;
break;
case 8:
info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
break;
case 16:
case 24:
case 32:
info->fix.visual = FB_VISUAL_TRUECOLOR;
break;
}
info->fix.line_length = get_line_length(info->var.xres_virtual,
info->var.bits_per_pixel);
return 0;
}
/*
* Set a single color register. The values supplied are already
* rounded down to the hardware's capabilities (according to the
* entries in the var structure). Return != 0 for invalid regno.
*/
static int vfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
u_int transp, struct fb_info *info)
{
if (regno >= 256) /* no. of hw registers */
return 1;
/*
* Program hardware... do anything you want with transp
*/
/* grayscale works only partially under directcolor */
if (info->var.grayscale) {
/* grayscale = 0.30*R + 0.59*G + 0.11*B */
red = green = blue =
(red * 77 + green * 151 + blue * 28) >> 8;
}
/* Directcolor:
* var->{color}.offset contains start of bitfield
* var->{color}.length contains length of bitfield
* {hardwarespecific} contains width of RAMDAC
* cmap[X] is programmed to (X << red.offset) | (X << green.offset) | (X << blue.offset)
* RAMDAC[X] is programmed to (red, green, blue)
*
* Pseudocolor:
* var->{color}.offset is 0 unless the palette index takes less than
* bits_per_pixel bits and is stored in the upper
* bits of the pixel value
* var->{color}.length is set so that 1 << length is the number of available
* palette entries
* cmap is not used
* RAMDAC[X] is programmed to (red, green, blue)
*
* Truecolor:
* does not use DAC. Usually 3 are present.
* var->{color}.offset contains start of bitfield
* var->{color}.length contains length of bitfield
* cmap is programmed to (red << red.offset) | (green << green.offset) |
* (blue << blue.offset) | (transp << transp.offset)
* RAMDAC does not exist
*/
#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
switch (info->fix.visual) {
case FB_VISUAL_TRUECOLOR:
case FB_VISUAL_PSEUDOCOLOR:
red = CNVT_TOHW(red, info->var.red.length);
green = CNVT_TOHW(green, info->var.green.length);
blue = CNVT_TOHW(blue, info->var.blue.length);
transp = CNVT_TOHW(transp, info->var.transp.length);
break;
case FB_VISUAL_DIRECTCOLOR:
red = CNVT_TOHW(red, 8); /* expect 8 bit DAC */
green = CNVT_TOHW(green, 8);
blue = CNVT_TOHW(blue, 8);
/* hey, there is bug in transp handling... */
transp = CNVT_TOHW(transp, 8);
break;
}
#undef CNVT_TOHW
/* Truecolor has hardware independent palette */
if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
u32 v;
if (regno >= 16)
return 1;
v = (red << info->var.red.offset) |
(green << info->var.green.offset) |
(blue << info->var.blue.offset) |
(transp << info->var.transp.offset);
switch (info->var.bits_per_pixel) {
case 8:
break;
case 16:
((u32 *) (info->pseudo_palette))[regno] = v;
break;
case 24:
case 32:
((u32 *) (info->pseudo_palette))[regno] = v;
break;
}
return 0;
}
return 0;
}
/*
* Pan or Wrap the Display
*
* This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
*/
static int vfb_pan_display(struct fb_var_screeninfo *var,
struct fb_info *info)
{
if (var->vmode & FB_VMODE_YWRAP) {
if (var->yoffset >= info->var.yres_virtual ||
var->xoffset)
return -EINVAL;
} else {
if (var->xoffset + info->var.xres > info->var.xres_virtual ||
var->yoffset + info->var.yres > info->var.yres_virtual)
return -EINVAL;
}
info->var.xoffset = var->xoffset;
info->var.yoffset = var->yoffset;
if (var->vmode & FB_VMODE_YWRAP)
info->var.vmode |= FB_VMODE_YWRAP;
else
info->var.vmode &= ~FB_VMODE_YWRAP;
return 0;
}
/*
* Most drivers don't need their own mmap function
*/
static int vfb_mmap(struct fb_info *info,
struct vm_area_struct *vma)
{
unsigned long start = vma->vm_start;
unsigned long size = vma->vm_end - vma->vm_start;
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
unsigned long page, pos;
if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
return -EINVAL;
if (size > info->fix.smem_len)
return -EINVAL;
if (offset > info->fix.smem_len - size)
return -EINVAL;
pos = (unsigned long)info->fix.smem_start + offset;
while (size > 0) {
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
return -EAGAIN;
}
start += PAGE_SIZE;
pos += PAGE_SIZE;
if (size > PAGE_SIZE)
size -= PAGE_SIZE;
else
size = 0;
}
return 0;
}
#ifndef MODULE
/*
* The virtual framebuffer driver is only enabled if explicitly
* requested by passing 'video=vfb:' (or any actual options).
*/
static int __init vfb_setup(char *options)
{
char *this_opt;
vfb_enable = 0;
if (!options)
return 1;
vfb_enable = 1;
if (!*options)
return 1;
while ((this_opt = strsep(&options, ",")) != NULL) {
if (!*this_opt)
continue;
/* Test disable for backwards compatibility */
if (!strcmp(this_opt, "disable"))
vfb_enable = 0;
else if (!strncmp(this_opt, "bpp=", 4)) {
if (kstrtoint(this_opt + 4, 0, &bpp) < 0)
bpp = 8;
} else if (!strncmp(this_opt, "memsize=", 8)) {
if (kstrtoul(this_opt + 8, 0, &videomemorysize) < 0)
videomemorysize = VIDEOMEMSIZE;
} else
mode_option = this_opt;
}
return 1;
}
#endif /* MODULE */
/*
* Initialisation
*/
static int vfb_probe(struct platform_device *dev)
{
struct fb_info *info;
int retval = -ENOMEM;
/*
* For real video cards we use ioremap.
*/
if (!(videomemory = rvmalloc(videomemorysize)))
return retval;
info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev);
if (!info)
goto err;
info->screen_base = (char __iomem *)videomemory;
info->fbops = &vfb_ops;
retval = fb_find_mode(&info->var, info, mode_option,
NULL, 0, NULL, bpp);
if (!retval || (retval == 4))
info->var = vfb_default;
vfb_fix.smem_start = (unsigned long) videomemory;
vfb_fix.smem_len = videomemorysize;
info->fix = vfb_fix;
info->pseudo_palette = info->par;
info->par = NULL;
info->flags = FBINFO_FLAG_DEFAULT;
retval = fb_alloc_cmap(&info->cmap, 256, 0);
if (retval < 0)
goto err1;
retval = register_framebuffer(info);
if (retval < 0)
goto err2;
platform_set_drvdata(dev, info);
vfb_set_par(info);
fb_info(info, "Virtual frame buffer device, using %ldK of video memory\n",
videomemorysize >> 10);
return 0;
err2:
fb_dealloc_cmap(&info->cmap);
err1:
framebuffer_release(info);
err:
rvfree(videomemory, videomemorysize);
return retval;
}
static int vfb_remove(struct platform_device *dev)
{
struct fb_info *info = platform_get_drvdata(dev);
if (info) {
unregister_framebuffer(info);
rvfree(videomemory, videomemorysize);
fb_dealloc_cmap(&info->cmap);
framebuffer_release(info);
}
return 0;
}
static struct platform_driver vfb_driver = {
.probe = vfb_probe,
.remove = vfb_remove,
.driver = {
.name = "vfb",
},
};
static struct platform_device *vfb_device;
static int __init vfb_init(void)
{
int ret = 0;
#ifndef MODULE
char *option = NULL;
if (fb_get_options("vfb", &option))
return -ENODEV;
vfb_setup(option);
#endif
if (!vfb_enable)
return -ENXIO;
ret = platform_driver_register(&vfb_driver);
if (!ret) {
vfb_device = platform_device_alloc("vfb", 0);
if (vfb_device)
ret = platform_device_add(vfb_device);
else
ret = -ENOMEM;
if (ret) {
platform_device_put(vfb_device);
platform_driver_unregister(&vfb_driver);
}
}
return ret;
}
module_init(vfb_init);
#ifdef MODULE
static void __exit vfb_exit(void)
{
platform_device_unregister(vfb_device);
platform_driver_unregister(&vfb_driver);
}
module_exit(vfb_exit);
MODULE_LICENSE("GPL");
#endif /* MODULE */