source: trunk/kernel/devices/dev_mmc.c

Last change on this file was 674, checked in by alain, 14 months ago

1) Introduce up to 4 command lines arguments in the KSH "load" command.
These arguments are transfered to the user process through the
argc/argv mechanism, using the user space "args" vseg.

2) Introduce the named and anonymous "pipes", for inter-process communication
through the pipe() and mkfifo() syscalls.

3) Introduce the "chat" application to validate the two above mechanisms.

4) Improve printk() and assert() fonctions in printk.c.

File size: 7.2 KB
RevLine 
[1]1/*
2 * dev_mmc.c - MMC (Memory Cache Controler) generic device API implementation.
3 *
[657]4 * Author  Alain Greiner    (2016,2017,2018,2019,2020)
[1]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
[457]24#include <hal_kernel_types.h>
[1]25#include <hal_special.h>
[257]26#include <hal_drivers.h>
[1]27#include <printk.h>
[3]28#include <chdev.h>
[1]29#include <thread.h>
[565]30#include <remote_busylock.h>
[1]31#include <dev_mmc.h>
32
33/////////////////////////////////////////////////////////////////////////////////////////
34// Extern global variables
35/////////////////////////////////////////////////////////////////////////////////////////
36
[3]37extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
[1]38
[238]39//////////////////////////////////
40void dev_mmc_init( chdev_t * mmc )
[1]41{
[238]42    // set mmc name
[674]43    snprintk( mmc->name , 16 , "mmc_%x" , local_cxy );
[23]44
[257]45    // call driver init function
[647]46    hal_drivers_mmc_init( mmc );
[14]47
[188]48    // bind IRQ to CP0
[238]49    dev_pic_bind_irq( 0 , mmc );
[188]50   
51    // enable IRQ
[238]52    dev_pic_enable_irq( 0 , XPTR( local_cxy , mmc ) );
[14]53
[1]54}  // end dev_mmc_init()
55
56/////////////////////////////////////////////////////////////////////////////
[440]57// This static function is called by all MMC device access functions.
[23]58// It makes some checking, takes the lock granting exclusive
59// access to MMC peripheral, call the driver to execute the command
[1]60// registered in the calling thread descriptor, and releases the lock.
61/////////////////////////////////////////////////////////////////////////////
[23]62static error_t dev_mmc_access( thread_t * this )
[1]63{
[23]64    // get extended pointer on MMC device descriptor
[279]65    xptr_t  dev_xp = this->mmc_cmd.dev_xp;
[1]66
[674]67    assert( __FUNCTION__, (dev_xp != XPTR_NULL) , "target MMC device undefined" );
[1]68
69    // get MMC device cluster identifier & local pointer
[3]70    cxy_t     dev_cxy = GET_CXY( dev_xp );
[440]71    chdev_t * dev_ptr = GET_PTR( dev_xp );
[1]72
73    // get driver command function pointer from MMC device descriptor
74    dev_cmd_t * cmd = (dev_cmd_t *)hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->cmd ) );
75
[565]76    // get the MMC device remote busylock
77    remote_busylock_acquire( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); 
[1]78
79    // call driver command
80    cmd( XPTR( local_cxy , this ) );
81   
[565]82    // release the MMC device remote busylock
83    remote_busylock_release( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); 
[1]84
[23]85    // return operation status
[279]86    return this->mmc_cmd.error; 
[1]87
88}  // end dev_mmc_access()
89
[23]90/////////////////////////////////////////
91error_t dev_mmc_inval( xptr_t     buf_xp,
[1]92                       uint32_t   buf_size )
93{
[23]94    error_t error;
95
[1]96    // get calling thread local pointer
[440]97    thread_t  * this    = CURRENT_THREAD;
[1]98
[438]99#if DEBUG_DEV_MMC
[437]100uint32_t cycle = (uint32_t)hal_get_cycles();
[438]101if( DEBUG_DEV_MMC < cycle )
[605]102printk("\n[%s] thread[%x,%x] enters / cluster %x / buffer %x\n", 
103__FUNCTION__, this->process->pid, this->trdid, GET_CXY(buf_xp), GET_PTR(buf_xp) );
[437]104#endif
[1]105
[23]106    // get buffer cluster and local pointer
[626]107    cxy_t     buf_cxy = GET_CXY( buf_xp );
108    uint8_t * buf_ptr = GET_PTR( buf_xp );
[23]109   
[626]110    // force buffer align
111    uint32_t  delta = (uint32_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE - 1); 
112    uint8_t * base  = buf_ptr - delta;
113    uint32_t  size  = buf_size + delta;
[1]114
115    // store command arguments in thread descriptor
[279]116    this->mmc_cmd.dev_xp    = chdev_dir.mmc[buf_cxy];
117    this->mmc_cmd.type      = MMC_CC_INVAL;
[626]118    this->mmc_cmd.buf_ptr   = base;
119    this->mmc_cmd.buf_size  = size;
[1]120
[23]121    // call MMC driver
122    error = dev_mmc_access( this );
[1]123
[438]124#if DEBUG_DEV_MMC
[437]125cycle = (uint32_t)hal_get_cycles();
[438]126if( DEBUG_DEV_MMC < cycle )
[605]127printk("\n[%s] thread[%x,%x] exit / cluster %x / buffer %x\n", 
128__FUNCTION__, this->process->pid, this->trdid, GET_CXY(buf_xp), GET_PTR(buf_xp) );
[437]129#endif
[1]130
[23]131    return error;
132}
133
134////////////////////////////////////////
135error_t dev_mmc_sync( xptr_t     buf_xp,
[1]136                      uint32_t   buf_size )
137{
[23]138    error_t error;
139
[440]140    thread_t  * this    = CURRENT_THREAD;
[1]141
[438]142#if DEBUG_DEV_MMC
[437]143uint32_t cycle = (uint32_t)hal_get_cycles();
[438]144if( DEBUG_DEV_MMC < cycle )
[605]145printk("\n[%s] thread[%x,%x] enters / cluster %x / buffer %x\n", 
146__FUNCTION__, this->process->pid, this->trdid, GET_CXY(buf_xp), GET_PTR(buf_xp) );
[437]147#endif
[1]148
[23]149    // get buffer cluster and local pointer
150    cxy_t  buf_cxy = GET_CXY( buf_xp );
151    void * buf_ptr = GET_PTR( buf_xp );
152   
[626]153    // force buffer align
154    uint32_t  delta = (uint32_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE - 1); 
155    uint8_t * base  = buf_ptr - delta;
156    uint32_t  size  = buf_size + delta;
[1]157
158    // store command arguments in thread descriptor
[279]159    this->mmc_cmd.dev_xp    = chdev_dir.mmc[buf_cxy];
160    this->mmc_cmd.type      = MMC_CC_SYNC;
[626]161    this->mmc_cmd.buf_ptr   = base;
162    this->mmc_cmd.buf_size  = size;
[1]163
[23]164    // call MMC driver
165    error = dev_mmc_access( this );
[1]166
[438]167#if DEBUG_DEV_MMC
[437]168cycle = (uint32_t)hal_get_cycles();
[438]169if( DEBUG_DEV_MMC < cycle )
[605]170printk("\n[%s] thread[%x,%x] exit / cluster %x / buffer %x\n", 
171__FUNCTION__, this->process->pid, this->trdid, GET_CXY(buf_xp), GET_PTR(buf_xp) );
[437]172#endif
[1]173
[23]174    return error;
175}
176
[1]177/////////////////////////////////////////
[657]178error_t dev_mmc_error_set( cxy_t     cxy,
[1]179                           uint32_t  index,
180                           uint32_t  wdata )
181{
182    // get calling thread local pointer
183    thread_t * this = CURRENT_THREAD;
184
185    // store command arguments in thread descriptor
[279]186    this->mmc_cmd.dev_xp    = chdev_dir.mmc[cxy];
[657]187    this->mmc_cmd.type      = MMC_ERROR_SET;
[279]188    this->mmc_cmd.reg_index = index;
189    this->mmc_cmd.reg_ptr   = &wdata;
[1]190
191    // execute operation
[23]192    return dev_mmc_access( this ); 
[1]193}
194                       
195//////////////////////////////////////////
[657]196error_t dev_mmc_error_get( cxy_t      cxy,
[1]197                           uint32_t   index,
198                           uint32_t * rdata )
199{
200    // get calling thread local pointer
201    thread_t * this = CURRENT_THREAD;
202
203    // store command arguments in thread descriptor
[279]204    this->mmc_cmd.dev_xp    = chdev_dir.mmc[cxy];
[657]205    this->mmc_cmd.type      = MMC_ERROR_GET;
[279]206    this->mmc_cmd.reg_index = index;
207    this->mmc_cmd.reg_ptr   = rdata;
[1]208
209    // execute operation
[23]210    return dev_mmc_access( this ); 
[1]211}
[657]212
213//////////////////////////////////////////
214error_t dev_mmc_instr_get( cxy_t      cxy,
215                           uint32_t   index,
216                           uint32_t * rdata )
[1]217{
218    // get calling thread local pointer
219    thread_t * this = CURRENT_THREAD;
220
221    // store command arguments in thread descriptor
[279]222    this->mmc_cmd.dev_xp    = chdev_dir.mmc[cxy];
[657]223    this->mmc_cmd.type      = MMC_INSTR_GET;
[279]224    this->mmc_cmd.reg_index = index;
225    this->mmc_cmd.reg_ptr   = rdata;
[1]226
227    // execute operation
[23]228    return dev_mmc_access( this ); 
[1]229}
Note: See TracBrowser for help on using the repository browser.