source: trunk/kernel/devices/dev_fbf.c @ 586

Last change on this file since 586 was 565, checked in by alain, 6 years ago

Complete restructuration of kernel locks.

File size: 6.8 KB
Line 
1/*
2 * dev_fbf.c - FBF (Block Device Controler) generic device API implementation.
3 *
4 * Author  Alain Greiner    (2016,2017,2018)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MK
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-kernel; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <kernel_config.h>
25#include <hal_kernel_types.h>
26#include <hal_gpt.h>
27#include <thread.h>
28#include <printk.h>
29#include <string.h>
30#include <chdev.h>
31#include <dev_fbf.h>
32
33/////////////////////////////////////////////////////////////////////////////////////////
34// Extern global variables
35/////////////////////////////////////////////////////////////////////////////////////////
36
37extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
38
39////////////////////////////////////
40void dev_fbf_init( chdev_t  * chdev )
41{
42    // set FBF chdev extension fields
43    // TODO this should be done in the implementation
44    // TODO specific part, as these parameters must be obtained from the hardware.
45    chdev->ext.fbf.width  = CONFIG_FBF_WIDTH;
46    chdev->ext.fbf.height = CONFIG_FBF_HEIGHT;
47
48    // get implementation
49    uint32_t  impl = chdev->impl;
50
51    // set chdev name
52    strcpy( chdev->name, "fbf" );
53
54    // call driver init function
55    if( impl == IMPL_FBF_SCL )
56    {
57        printk("\n[WARNING] Soclib FBF driver not implemented yet\n");
58    }
59    else
60    {
61        assert( false , "undefined FBF device implementation" );
62    }
63
64}  // end dev_fbf_init()
65
66/////////////////////////////////////////
67void dev_fbf_get_size( uint32_t  * width,
68                       uint32_t  * height )
69{
70    // get extended pointer on FBF chdev descriptor
71    xptr_t  dev_xp = chdev_dir.fbf[0];
72
73    assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
74
75    // get FBF chdev cluster and local pointer
76    cxy_t     dev_cxy = GET_CXY( dev_xp );
77    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
78
79    // return values
80    *width  = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.width ) );
81    *height = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.height ) );
82
83}  // end dev_fbf_get_size()
84
85/////////////////////////////
86error_t dev_fbf_alloc( void )
87{
88    // get extended pointer on FBF chdev descriptor
89    // xptr_t  dev_xp = chdev_dir.fbf[0];
90
91    // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
92
93    // get FBF chdev cluster and local pointer
94    // cxy_t     dev_cxy = GET_CXY( dev_xp );
95    // chdev_t * dev_ptr = GET_PTR( dev_xp );
96
97    // try to get FBF ownership
98
99assert( false , "not implemented yet" );
100
101}  // end dev_fbf_alloc()
102
103/////////////////////////
104void dev_fbf_free( void )
105{
106    // get extended pointer on FBF chdev descriptor
107    // xptr_t  dev_xp = chdev_dir.fbf[0];
108
109    // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
110
111    // get FBF chdev cluster and local pointer
112    // cxy_t     dev_cxy = GET_CXY( dev_xp );
113    // chdev_t * dev_ptr = (GET_PTR( dev_xp );
114
115    // release FBF ownership
116
117assert( false , "not implemented yet" );
118
119}  // end dev_fbf_free()
120
121//////////////////////////////////////////////////////////////////////////////////
122// This static function is called by dev_fbf_read() & dev_fbf_write() functions.
123// It builds and registers the command in the calling thread descriptor.
124// Then, it registers the calling thread in the relevant DMA chdev waiting queue.
125// Finally it blocks on the THREAD_BLOCKED_DEV condition and deschedule.
126////////////////////////////////////i/////////////////////////////////////////////
127static error_t dev_fbf_access( bool_t    to_fbf,
128                               char    * buffer,
129                               uint32_t  length,
130                               uint32_t  offset )
131{
132
133    // get extended pointer on FBF chdev descriptor
134    xptr_t  fbf_xp = chdev_dir.fbf[0];
135
136    assert( (fbf_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
137
138    // get FBF chdev cluster and local pointer
139    cxy_t     fbf_cxy = GET_CXY( fbf_xp );
140    chdev_t * fbf_ptr = (chdev_t *)GET_PTR( fbf_xp );
141
142    // get frame buffer base address, width and height
143    xptr_t   base   = hal_remote_l64( XPTR( fbf_cxy , &fbf_ptr->base ) );
144    uint32_t width  = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.width ) );
145    uint32_t height = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.height ) );
146
147    // check offset and length versus FBF size
148    assert( ((offset + length) <= (width * height)) ,
149    "offset %d / length %d / width %d / height %d\n", offset, length, width, height ); 
150
151    // compute extended pointers on frame buffer and memory buffer
152    xptr_t  mem_buf_xp = XPTR( local_cxy , buffer );
153    xptr_t  fbf_buf_xp = base + offset;
154
155    // register command in DMA chdev
156    if( to_fbf )  dev_dma_remote_memcpy( fbf_buf_xp , mem_buf_xp , length );
157    else          dev_dma_remote_memcpy( mem_buf_xp , fbf_buf_xp , length );
158
159    return 0;
160
161}  // end dev_fbf_access()
162
163////////////////////////////////////////////
164error_t dev_fbf_read( char         * buffer,
165                      uint32_t       length,
166                      uint32_t       offset )
167{
168
169#if DEBUG_DEV_FBF_RX
170uint32_t cycle = (uint32_t)hal_get_cycles();
171if( DEBUG_DEV_FBF_RX < cycle )
172printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / size %x\n", 
173__FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
174#endif
175
176    return dev_fbf_access( false , buffer , length , offset ); 
177
178#if DEBUG_DEV_FBF_RX
179cycle = (uint32_t)hal_get_cycles();
180if( DEBUG_DEV_FBF_RX < cycle )
181printk("\n[DBG] %s : thread %x exit / process %x / vaddr %x / size %x\n", 
182__FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
183#endif
184
185} 
186
187////////////////////////////////////////////
188error_t dev_fbf_write( char         * buffer,
189                       uint32_t       length,
190                       uint32_t       offset )
191{
192
193#if DEBUG_DEV_FBF_TX
194uint32_t cycle = (uint32_t)hal_get_cycles();
195if( DEBUG_DEV_FBF_TX < cycle )
196printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / size %x\n", 
197__FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
198#endif
199
200    return dev_fbf_access( true , buffer , length , offset ); 
201
202#if DEBUG_DEV_FBF_RX
203cycle = (uint32_t)hal_get_cycles();
204if( DEBUG_DEV_FBF_RX < cycle )
205printk("\n[DBG] %s : thread %x exit / process %x / vaddr %x / size %x\n", 
206__FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
207#endif
208
209}
Note: See TracBrowser for help on using the repository browser.