Home | History | Annotate | Line # | Download | only in rpi
vcprop_subr.c revision 1.2
      1  1.2     skrll /*	$NetBSD: vcprop_subr.c,v 1.2 2014/10/03 17:57:48 skrll Exp $	*/
      2  1.1  macallan 
      3  1.1  macallan /*
      4  1.1  macallan  * Copyright (c) 2014 Michael Lorenz
      5  1.1  macallan  * All rights reserved.
      6  1.1  macallan  *
      7  1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8  1.1  macallan  * modification, are permitted provided that the following conditions
      9  1.1  macallan  * are met:
     10  1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11  1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12  1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15  1.1  macallan  *
     16  1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  macallan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1  macallan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1  macallan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1  macallan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.1  macallan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.1  macallan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.1  macallan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.1  macallan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.1  macallan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.1  macallan  */
     27  1.1  macallan 
     28  1.1  macallan /*
     29  1.1  macallan  * Mailbox property interface wrapper functions
     30  1.1  macallan  */
     31  1.1  macallan 
     32  1.1  macallan #include <sys/param.h>
     33  1.1  macallan #include <sys/device.h>
     34  1.1  macallan #include <sys/bus.h>
     35  1.1  macallan 
     36  1.1  macallan #include <uvm/uvm_extern.h>
     37  1.1  macallan 
     38  1.1  macallan #include <arm/arm32/machdep.h>
     39  1.1  macallan 
     40  1.1  macallan #include <arm/broadcom/bcm2835reg.h>
     41  1.1  macallan #include <arm/broadcom/bcm2835var.h>
     42  1.1  macallan #include <arm/broadcom/bcm2835_pmvar.h>
     43  1.1  macallan #include <arm/broadcom/bcm2835_mbox.h>
     44  1.1  macallan 
     45  1.1  macallan #include <evbarm/rpi/vcio.h>
     46  1.1  macallan #include <evbarm/rpi/vcpm.h>
     47  1.1  macallan #include <evbarm/rpi/vcprop.h>
     48  1.1  macallan 
     49  1.1  macallan #include <evbarm/rpi/rpi.h>
     50  1.1  macallan 
     51  1.1  macallan #include <dev/wscons/wsconsio.h>
     52  1.1  macallan 
     53  1.1  macallan int
     54  1.1  macallan rpi_fb_set_video(int b)
     55  1.1  macallan {
     56  1.1  macallan 	int error;
     57  1.1  macallan 	uint32_t res;
     58  1.1  macallan 
     59  1.1  macallan 	/*
     60  1.1  macallan 	 * might as well put it here since we need to re-init it every time
     61  1.1  macallan 	 * and it's not like this is going to be called very often anyway
     62  1.1  macallan 	 */
     63  1.1  macallan 	struct __aligned(16) {
     64  1.1  macallan 		struct vcprop_buffer_hdr	vb_hdr;
     65  1.1  macallan 		struct vcprop_tag_blankscreen	vbt_blank;
     66  1.1  macallan 		struct vcprop_tag end;
     67  1.1  macallan 	} vb_setblank =
     68  1.1  macallan 	{
     69  1.1  macallan 		.vb_hdr = {
     70  1.1  macallan 			.vpb_len = sizeof(vb_setblank),
     71  1.1  macallan 			.vpb_rcode = VCPROP_PROCESS_REQUEST,
     72  1.1  macallan 		},
     73  1.1  macallan 		.vbt_blank = {
     74  1.1  macallan 			.tag = {
     75  1.1  macallan 				.vpt_tag = VCPROPTAG_BLANK_SCREEN,
     76  1.1  macallan 				.vpt_len = VCPROPTAG_LEN(vb_setblank.vbt_blank),
     77  1.1  macallan 				.vpt_rcode = VCPROPTAG_REQUEST,
     78  1.1  macallan 			},
     79  1.1  macallan 			.state = (b != 0) ? VCPROP_BLANK_OFF : VCPROP_BLANK_ON,
     80  1.1  macallan 		},
     81  1.1  macallan 		.end = {
     82  1.1  macallan 			.vpt_tag = VCPROPTAG_NULL,
     83  1.1  macallan 		},
     84  1.1  macallan 	};
     85  1.1  macallan 
     86  1.1  macallan 	error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_setblank,
     87  1.1  macallan 	    sizeof(vb_setblank), &res);
     88  1.1  macallan #ifdef RPI_IOCTL_DEBUG
     89  1.1  macallan 	printf("%s: %d %d %d %08x %08x\n", __func__, b,
     90  1.1  macallan 	    vb_setblank.vbt_blank.state, error, res,
     91  1.1  macallan 	    vb_setblank.vbt_blank.tag.vpt_rcode);
     92  1.1  macallan #endif
     93  1.2     skrll 	if (error)
     94  1.2     skrll 		return error;
     95  1.2     skrll 
     96  1.2     skrll 	if (!vcprop_buffer_success_p(&vb_setblank.vb_hdr) ||
     97  1.2     skrll 	    !vcprop_tag_success_p(&vb_setblank.vbt_blank.tag)) {
     98  1.2     skrll 		return EIO;
     99  1.2     skrll 	}
    100  1.2     skrll 
    101  1.2     skrll 	return 0;
    102  1.1  macallan }
    103  1.1  macallan 
    104  1.1  macallan uint32_t
    105  1.1  macallan rpi_alloc_mem(uint32_t size, uint32_t align, uint32_t flags)
    106  1.1  macallan {
    107  1.1  macallan 	int error;
    108  1.1  macallan 	uint32_t res;
    109  1.1  macallan 
    110  1.1  macallan 	struct __aligned(16) {
    111  1.1  macallan 		struct vcprop_buffer_hdr	vb_hdr;
    112  1.1  macallan 		struct vcprop_tag_allocmem	vbt_am;
    113  1.1  macallan 		struct vcprop_tag end;
    114  1.1  macallan 	} vb_allocmem =
    115  1.1  macallan 	{
    116  1.1  macallan 		.vb_hdr = {
    117  1.1  macallan 			.vpb_len = sizeof(vb_allocmem),
    118  1.1  macallan 			.vpb_rcode = VCPROP_PROCESS_REQUEST,
    119  1.1  macallan 		},
    120  1.1  macallan 		.vbt_am = {
    121  1.1  macallan 			.tag = {
    122  1.1  macallan 				.vpt_tag = VCPROPTAG_ALLOCMEM,
    123  1.1  macallan 				.vpt_len = VCPROPTAG_LEN(vb_allocmem.vbt_am),
    124  1.1  macallan 				.vpt_rcode = VCPROPTAG_REQUEST,
    125  1.1  macallan 			},
    126  1.1  macallan 			.size = size,
    127  1.1  macallan 			.align = align,
    128  1.1  macallan 			.flags = flags,
    129  1.1  macallan 		},
    130  1.1  macallan 		.end = {
    131  1.1  macallan 			.vpt_tag = VCPROPTAG_NULL,
    132  1.1  macallan 		},
    133  1.1  macallan 	};
    134  1.1  macallan 
    135  1.1  macallan 	error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_allocmem,
    136  1.1  macallan 	    sizeof(vb_allocmem), &res);
    137  1.1  macallan #ifdef RPI_IOCTL_DEBUG
    138  1.1  macallan 	printf("%s: %d %d %08x %08x\n", __func__,
    139  1.1  macallan 	    vb_allocmem.vbt_am.size, error, res,
    140  1.1  macallan 	    vb_allocmem.vbt_am.tag.vpt_rcode);
    141  1.1  macallan #endif
    142  1.2     skrll 	if (error)
    143  1.2     skrll 		return error;
    144  1.2     skrll 
    145  1.2     skrll 	if (!vcprop_buffer_success_p(&vb_allocmem.vb_hdr) ||
    146  1.2     skrll 	    !vcprop_tag_success_p(&vb_allocmem.vbt_am.tag)) {
    147  1.2     skrll 		return EIO;
    148  1.2     skrll 	}
    149  1.2     skrll 
    150  1.2     skrll 	/* Return the handle from the VC */
    151  1.2     skrll 	return vb_allocmem.vbt_am.size;
    152  1.1  macallan }
    153  1.1  macallan 
    154  1.1  macallan bus_addr_t
    155  1.1  macallan rpi_lock_mem(uint32_t handle)
    156  1.1  macallan {
    157  1.1  macallan 	int error;
    158  1.1  macallan 	uint32_t res;
    159  1.1  macallan 
    160  1.1  macallan 	struct __aligned(16) {
    161  1.1  macallan 		struct vcprop_buffer_hdr	vb_hdr;
    162  1.1  macallan 		struct vcprop_tag_lockmem	vbt_lm;
    163  1.1  macallan 		struct vcprop_tag end;
    164  1.1  macallan 	} vb_lockmem =
    165  1.1  macallan 	{
    166  1.1  macallan 		.vb_hdr = {
    167  1.1  macallan 			.vpb_len = sizeof(vb_lockmem),
    168  1.1  macallan 			.vpb_rcode = VCPROP_PROCESS_REQUEST,
    169  1.1  macallan 		},
    170  1.1  macallan 		.vbt_lm = {
    171  1.1  macallan 			.tag = {
    172  1.1  macallan 				.vpt_tag = VCPROPTAG_LOCKMEM,
    173  1.1  macallan 				.vpt_len = VCPROPTAG_LEN(vb_lockmem.vbt_lm),
    174  1.1  macallan 				.vpt_rcode = VCPROPTAG_REQUEST,
    175  1.1  macallan 			},
    176  1.1  macallan 			.handle = handle,
    177  1.1  macallan 		},
    178  1.1  macallan 		.end = {
    179  1.1  macallan 			.vpt_tag = VCPROPTAG_NULL,
    180  1.1  macallan 		},
    181  1.1  macallan 	};
    182  1.1  macallan 
    183  1.1  macallan 	error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_lockmem,
    184  1.1  macallan 	    sizeof(vb_lockmem), &res);
    185  1.1  macallan #ifdef RPI_IOCTL_DEBUG
    186  1.1  macallan 	printf("%s: %d %d %08x %08x\n", __func__,
    187  1.1  macallan 	    vb_lockmem.vbt_lm.handle, error, res,
    188  1.1  macallan 	    vb_lockmem.vbt_lm.tag.vpt_rcode);
    189  1.1  macallan #endif
    190  1.2     skrll 	if (error)
    191  1.2     skrll 		return 0;
    192  1.2     skrll 
    193  1.2     skrll 	if (!vcprop_buffer_success_p(&vb_lockmem.vb_hdr) ||
    194  1.2     skrll 	    !vcprop_tag_success_p(&vb_lockmem.vbt_lm.tag)) {
    195  1.2     skrll 		return 0;
    196  1.2     skrll 	}
    197  1.2     skrll 
    198  1.2     skrll 	return vb_lockmem.vbt_lm.handle;
    199  1.1  macallan }
    200  1.1  macallan 
    201  1.1  macallan int
    202  1.1  macallan rpi_unlock_mem(uint32_t handle)
    203  1.1  macallan {
    204  1.1  macallan 	int error;
    205  1.1  macallan 	uint32_t res;
    206  1.1  macallan 
    207  1.1  macallan 	struct __aligned(16) {
    208  1.1  macallan 		struct vcprop_buffer_hdr	vb_hdr;
    209  1.1  macallan 		struct vcprop_tag_lockmem	vbt_lm;
    210  1.1  macallan 		struct vcprop_tag end;
    211  1.1  macallan 	} vb_unlockmem =
    212  1.1  macallan 	{
    213  1.1  macallan 		.vb_hdr = {
    214  1.1  macallan 			.vpb_len = sizeof(vb_unlockmem),
    215  1.1  macallan 			.vpb_rcode = VCPROP_PROCESS_REQUEST,
    216  1.1  macallan 		},
    217  1.1  macallan 		.vbt_lm = {
    218  1.1  macallan 			.tag = {
    219  1.1  macallan 				.vpt_tag = VCPROPTAG_UNLOCKMEM,
    220  1.1  macallan 				.vpt_len = VCPROPTAG_LEN(vb_unlockmem.vbt_lm),
    221  1.1  macallan 				.vpt_rcode = VCPROPTAG_REQUEST,
    222  1.1  macallan 			},
    223  1.1  macallan 			.handle = handle,
    224  1.1  macallan 		},
    225  1.1  macallan 		.end = {
    226  1.1  macallan 			.vpt_tag = VCPROPTAG_NULL,
    227  1.1  macallan 		},
    228  1.1  macallan 	};
    229  1.1  macallan 
    230  1.1  macallan 	error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_unlockmem,
    231  1.1  macallan 	    sizeof(vb_unlockmem), &res);
    232  1.1  macallan #ifdef RPI_IOCTL_DEBUG
    233  1.1  macallan 	printf("%s: %d %d %08x %08x\n", __func__,
    234  1.1  macallan 	    vb_unlockmem.vbt_lm.handle, error, res,
    235  1.1  macallan 	    vb_unlockmem.vbt_lm.tag.vpt_rcode);
    236  1.1  macallan #endif
    237  1.2     skrll 	if (error)
    238  1.2     skrll 		return error;
    239  1.2     skrll 
    240  1.2     skrll 	if (!vcprop_buffer_success_p(&vb_unlockmem.vb_hdr) ||
    241  1.2     skrll 	    !vcprop_tag_success_p(&vb_unlockmem.vbt_lm.tag)) {
    242  1.2     skrll 		return EIO;
    243  1.2     skrll 	}
    244  1.2     skrll 
    245  1.2     skrll 	return 0;
    246  1.1  macallan }
    247  1.1  macallan 
    248  1.1  macallan int
    249  1.1  macallan rpi_release_mem(uint32_t handle)
    250  1.1  macallan {
    251  1.1  macallan 	int error;
    252  1.1  macallan 	uint32_t res;
    253  1.1  macallan 
    254  1.1  macallan 	struct __aligned(16) {
    255  1.1  macallan 		struct vcprop_buffer_hdr	vb_hdr;
    256  1.1  macallan 		struct vcprop_tag_lockmem	vbt_lm;
    257  1.1  macallan 		struct vcprop_tag end;
    258  1.1  macallan 	} vb_releasemem =
    259  1.1  macallan 	{
    260  1.1  macallan 		.vb_hdr = {
    261  1.1  macallan 			.vpb_len = sizeof(vb_releasemem),
    262  1.1  macallan 			.vpb_rcode = VCPROP_PROCESS_REQUEST,
    263  1.1  macallan 		},
    264  1.1  macallan 		.vbt_lm = {
    265  1.1  macallan 			.tag = {
    266  1.1  macallan 				.vpt_tag = VCPROPTAG_RELEASEMEM,
    267  1.1  macallan 				.vpt_len = VCPROPTAG_LEN(vb_releasemem.vbt_lm),
    268  1.1  macallan 				.vpt_rcode = VCPROPTAG_REQUEST,
    269  1.1  macallan 			},
    270  1.1  macallan 			.handle = handle,
    271  1.1  macallan 		},
    272  1.1  macallan 		.end = {
    273  1.1  macallan 			.vpt_tag = VCPROPTAG_NULL,
    274  1.1  macallan 		},
    275  1.1  macallan 	};
    276  1.1  macallan 
    277  1.1  macallan 	error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_releasemem,
    278  1.1  macallan 	    sizeof(vb_releasemem), &res);
    279  1.1  macallan #ifdef RPI_IOCTL_DEBUG
    280  1.1  macallan 	printf("%s: %d %d %08x %08x\n", __func__,
    281  1.1  macallan 	    vb_releasemem.vbt_lm.handle, error, res,
    282  1.1  macallan 	    vb_releasemem.vbt_lm.tag.vpt_rcode);
    283  1.1  macallan #endif
    284  1.2     skrll 	if (error)
    285  1.2     skrll 		return error;
    286  1.2     skrll 
    287  1.2     skrll 	if (!vcprop_buffer_success_p(&vb_releasemem.vb_hdr) ||
    288  1.2     skrll 	    !vcprop_tag_success_p(&vb_releasemem.vbt_lm.tag)) {
    289  1.2     skrll 		return EIO;
    290  1.2     skrll 	}
    291  1.2     skrll 
    292  1.2     skrll 	return 0;
    293  1.1  macallan }
    294  1.1  macallan 
    295  1.1  macallan int
    296  1.1  macallan rpi_fb_movecursor(int x, int y, int on)
    297  1.1  macallan {
    298  1.1  macallan 	int error;
    299  1.1  macallan 	uint32_t res;
    300  1.1  macallan 
    301  1.1  macallan 	struct __aligned(16) {
    302  1.1  macallan 		struct vcprop_buffer_hdr	vb_hdr;
    303  1.1  macallan 		struct vcprop_tag_cursorstate	vbt_cs;
    304  1.1  macallan 		struct vcprop_tag end;
    305  1.1  macallan 	} vb_cursorstate =
    306  1.1  macallan 	{
    307  1.1  macallan 		.vb_hdr = {
    308  1.1  macallan 			.vpb_len = sizeof(vb_cursorstate),
    309  1.1  macallan 			.vpb_rcode = VCPROP_PROCESS_REQUEST,
    310  1.1  macallan 		},
    311  1.1  macallan 		.vbt_cs = {
    312  1.1  macallan 			.tag = {
    313  1.1  macallan 				.vpt_tag = VCPROPTAG_SET_CURSOR_STATE,
    314  1.1  macallan 				.vpt_len = VCPROPTAG_LEN(vb_cursorstate.vbt_cs),
    315  1.1  macallan 				.vpt_rcode = VCPROPTAG_REQUEST,
    316  1.1  macallan 			},
    317  1.1  macallan 			.enable = (on != 0) ? 1 : 0,
    318  1.1  macallan 			.x = x,
    319  1.1  macallan 			.y = y,
    320  1.1  macallan 			.flags = 1,
    321  1.1  macallan 		},
    322  1.1  macallan 		.end = {
    323  1.1  macallan 			.vpt_tag = VCPROPTAG_NULL,
    324  1.1  macallan 		},
    325  1.1  macallan 	};
    326  1.1  macallan 
    327  1.1  macallan 	error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_cursorstate,
    328  1.1  macallan 	    sizeof(vb_cursorstate), &res);
    329  1.1  macallan #ifdef RPI_IOCTL_DEBUG
    330  1.1  macallan 	printf("%s: %08x %d %08x %08x\n", __func__,
    331  1.1  macallan 	    vb_cursorstate.vbt_cs.enable, error, res,
    332  1.1  macallan 	    vb_cursorstate.vbt_cs.tag.vpt_rcode);
    333  1.1  macallan #endif
    334  1.2     skrll 	if (error)
    335  1.2     skrll 		return error;
    336  1.2     skrll 
    337  1.2     skrll 	if (!vcprop_buffer_success_p(&vb_cursorstate.vb_hdr) ||
    338  1.2     skrll 	    !vcprop_tag_success_p(&vb_cursorstate.vbt_cs.tag)) {
    339  1.2     skrll 		return EIO;
    340  1.2     skrll 	}
    341  1.2     skrll 
    342  1.2     skrll 	return 0;
    343  1.1  macallan }
    344  1.1  macallan 
    345  1.1  macallan int
    346  1.1  macallan rpi_fb_initcursor(bus_addr_t pixels, int hx, int hy)
    347  1.1  macallan {
    348  1.1  macallan 	int error;
    349  1.1  macallan 	uint32_t res;
    350  1.1  macallan 
    351  1.1  macallan 
    352  1.1  macallan 	struct __aligned(16) {
    353  1.1  macallan 		struct vcprop_buffer_hdr	vb_hdr;
    354  1.1  macallan 		struct vcprop_tag_cursorinfo	vbt_ci;
    355  1.1  macallan 		struct vcprop_tag end;
    356  1.1  macallan 	} vb_cursorinfo =
    357  1.1  macallan 	{
    358  1.1  macallan 		.vb_hdr = {
    359  1.1  macallan 			.vpb_len = sizeof(vb_cursorinfo),
    360  1.1  macallan 			.vpb_rcode = VCPROP_PROCESS_REQUEST,
    361  1.1  macallan 		},
    362  1.1  macallan 		.vbt_ci = {
    363  1.1  macallan 			.tag = {
    364  1.1  macallan 				.vpt_tag = VCPROPTAG_SET_CURSOR_INFO,
    365  1.1  macallan 				.vpt_len = VCPROPTAG_LEN(vb_cursorinfo.vbt_ci),
    366  1.1  macallan 				.vpt_rcode = VCPROPTAG_REQUEST,
    367  1.1  macallan 			},
    368  1.1  macallan 			.width = 64,
    369  1.1  macallan 			.height = 64,
    370  1.1  macallan 			.format = 0,
    371  1.1  macallan 			.pixels = pixels,
    372  1.1  macallan 			.hotspot_x = hx,
    373  1.1  macallan 			.hotspot_y = hy,
    374  1.1  macallan 		},
    375  1.1  macallan 		.end = {
    376  1.1  macallan 			.vpt_tag = VCPROPTAG_NULL,
    377  1.1  macallan 		},
    378  1.1  macallan 	};
    379  1.1  macallan 
    380  1.1  macallan 	error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_cursorinfo,
    381  1.1  macallan 	    sizeof(vb_cursorinfo), &res);
    382  1.1  macallan #ifdef RPI_IOCTL_DEBUG
    383  1.1  macallan 	printf("%s: %d %d %08x %08x\n", __func__,
    384  1.1  macallan 	    vb_cursorinfo.vbt_ci.width, error, res,
    385  1.1  macallan 	    vb_cursorinfo.vbt_ci.tag.vpt_rcode);
    386  1.1  macallan #endif
    387  1.2     skrll 	if (error)
    388  1.2     skrll 		return error;
    389  1.2     skrll 
    390  1.2     skrll 	if (!vcprop_buffer_success_p(&vb_cursorinfo.vb_hdr) ||
    391  1.2     skrll 	    !vcprop_tag_success_p(&vb_cursorinfo.vbt_ci.tag)) {
    392  1.2     skrll 		return EIO;
    393  1.2     skrll 	}
    394  1.2     skrll 
    395  1.2     skrll 	return 0;
    396  1.1  macallan }
    397