source: trunk/hal/tsar_mips32/drivers/soclib_fbf.c @ 677

Last change on this file since 677 was 657, checked in by alain, 5 years ago

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

File size: 5.6 KB
RevLine 
[75]1/*
2 * soclib_fbf.c - soclib frame-buffer driver implementation.
3 *
[657]4 * Author Alain greiner (2016,2017,2018,2019,2020)
[75]5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH..
9 *
10 * ALMOS-MKH. is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH. is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
[647]24#include <soclib_fbf.h>
25#include <hal_kernel_types.h>
26#include <hal_uspace.h>
27#include <chdev.h>
28#include <dev_fbf.h>
29#include <printk.h>
30#include <thread.h>
31
32///////////////////////////////////////
33void soclib_fbf_init( chdev_t * chdev )
34{
35    // set driver specific fields in FBF chdev
36    chdev->cmd = &soclib_fbf_cmd;
37    chdev->isr = NULL;
38
39    // get extended pointer on SOCLIB_FBF peripheral segment base
40        xptr_t  base_xp = chdev->base;
41
42    // get cluster and local pointer for the SOCLIB_FBF peripheral segment
43    cxy_t      base_cxy  = GET_CXY( base_xp );
44    uint32_t * base_ptr  = GET_PTR( base_xp );
45
46    // get frame buffer width, height, and type 
47        uint32_t width  = hal_remote_l32( XPTR( base_cxy , base_ptr + FBF_WIDTH_REG ) );
48        uint32_t height = hal_remote_l32( XPTR( base_cxy , base_ptr + FBF_HEIGHT_REG ) );
49    uint32_t type   = hal_remote_l32( XPTR( base_cxy , base_ptr + FBF_SUBSAMPLING_REG ) );
50
51    // set FBF chdev extension fields
52    chdev->ext.fbf.width       = width;
53    chdev->ext.fbf.height      = height;
54    chdev->ext.fbf.subsampling = type;
55
56}  // end soclib_fbf_init()
57
58/////////////////////////////////////////////////////////////////
59void __attribute__((noinline)) soclib_fbf_cmd( xptr_t thread_xp )
60{
[657]61    uint32_t   type;        // USER_WRITE / USER_READ / KERNEL_WRITE / KERNEL_READ
62    uint32_t   offset;      // offset in FBF (in pixels)
63    uint32_t   npixels;     // number of pixels to move
64    xptr_t     fbf_xp;      // extended pointer on FBF chdev descriptor
[647]65    uint32_t   status;      // I/0 operation status (from BDV)
[657]66    void     * buffer;      // pointer on kernel or user buffer
[647]67
68    // get client thread cluster and local pointer
69    cxy_t      th_cxy = GET_CXY( thread_xp );
70    thread_t * th_ptr = GET_PTR( thread_xp );
71
72#if (DEBUG_HAL_FBF|| DEBUG_HAL_FBF)
73uint32_t    cycle        = (uint32_t)hal_get_cycles();
74process_t * process      = hal_remote_lpt( XPTR( th_cxy , &th_ptr->process ) );
75pid_t       client_pid   = hal_remote_l32( XPTR( th_cxy , &process->pid ) );
76trdid_t     client_trdid = hal_remote_l32( XPTR( th_cxy , &th_ptr->trdid ) );
77#endif
78
79    // get command arguments
[657]80    type     = hal_remote_l32( XPTR( th_cxy , &th_ptr->fbf_cmd.type    ) );
81    offset   = hal_remote_l32( XPTR( th_cxy , &th_ptr->fbf_cmd.offset  ) );
82    npixels  = hal_remote_l32( XPTR( th_cxy , &th_ptr->fbf_cmd.npixels ) );
83    fbf_xp   = hal_remote_l64( XPTR( th_cxy , &th_ptr->fbf_cmd.dev_xp  ) );
84    buffer   = hal_remote_lpt( XPTR( th_cxy , &th_ptr->fbf_cmd.buffer  ) );
[647]85
86    // get cluster and local pointer on FBF chdev
87    cxy_t     fbf_cxy = GET_CXY( fbf_xp );
88    chdev_t * fbf_ptr = GET_PTR( fbf_xp );
89
90    // get extended pointer on SOCLIB_FBF peripheral segment base
91        xptr_t  base_xp = (xptr_t)hal_remote_l64( XPTR( fbf_cxy , &fbf_ptr->base ) );
92
93    // execute command
[657]94    if( type == FBF_DRIVER_USER_WRITE )     // user_buffer => FBF
[647]95    {
96
97#if DEBUG_HAL_FBF
98if( DEBUG_HAL_FBF < cycle )
[657]99printk("\n[%s] client thread[%x,%x] / USER_WRITE / offset %d / npixels %d / buf %x\n",
100__FUNCTION__ , client_pid, client_trdid, offset, npixels, buffer );
[647]101#endif
[657]102        hal_copy_from_uspace( base_xp + offset,
103                              buffer,
104                              npixels );
105    }
106    else if( type == FBF_DRIVER_USER_READ )  // FBF => user_buffer
107    {
108
[654]109#if DEBUG_HAL_FBF
110if( DEBUG_HAL_FBF < cycle )
[657]111printk("\n[%s] client thread[%x,%x] / USER_READ / offset %d / npixels %d / buf %x\n",
112__FUNCTION__ , client_pid, client_trdid, offset, npixels, buffer );
[654]113#endif
[657]114        hal_copy_to_uspace( buffer,
115                            base_xp + offset,
116                            npixels );
[647]117    }
[657]118    else if( type == FBF_DRIVER_KERNEL_WRITE )  // kernel_buffer => FBF
[647]119    {
120
121#if DEBUG_HAL_FBF
122if( DEBUG_HAL_FBF < cycle )
[657]123printk("\n[%s] client thread[%x,%x] / KERNEL_WRITE / offset %d / npixels %d / buf %x\n",
124__FUNCTION__ , client_pid, client_trdid, offset, npixels, buffer );
[647]125#endif
[657]126        hal_remote_memcpy( base_xp + offset,
127                           XPTR( local_cxy , buffer ),
128                           npixels );
129    }
130    else if( type == FBF_DRIVER_KERNEL_READ )  // FBF => kernel_buffer
131    {
132
[654]133#if DEBUG_HAL_FBF
134if( DEBUG_HAL_FBF < cycle )
[657]135printk("\n[%s] client thread[%x,%x] / KERNEL_READ / offset %d / npixels %d / buf %x\n",
136__FUNCTION__ , client_pid, client_trdid, offset, npixels, buffer );
[654]137#endif
[657]138        hal_remote_memcpy( XPTR( local_cxy , buffer ),
139                           base_xp + offset,
140                           npixels );
[647]141    }
142
143    // set success in command
144    hal_remote_s32( XPTR( th_cxy , &th_ptr->fbf_cmd.error ) , 0 );
[657]145
146#if DEBUG_HAL_FBF
147if( DEBUG_HAL_FBF < cycle )
148printk("\n[%s] client thread[%x,%x] / successful move / cycle %d\n",
149__FUNCTION__ , client_pid, client_trdid , cycle );
150#endif
[647]151           
152}  // end soclib_fbf_cmd()
153
Note: See TracBrowser for help on using the repository browser.