source: trunk/kernel/fs/sysfs/sysfs.h @ 4

Last change on this file since 4 was 1, checked in by alain, 8 years ago

First import

File size: 4.7 KB
Line 
1/*
2 * sysfs.h - sysfs interface
3 *
4 * Authors   Ghassan Almaless (2008,2009,2010,2011,2012)
5 *           Mohamed Lamine Karaoui (2015)
6 *           Alain Greiner (2016)
7 *
8 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
9 *
10 * This file is part of ALMOS-MKH.
11 *
12 * ALMOS-MKH is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2.0 of the License.
15 *
16 * ALMOS-MKH is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef _SYSFS_H_
27#define _SYSFS_H_
28
29#include <hal_types.h>
30#include <metafs.h>
31
32
33struct sysfs_op_s;
34struct sysfs_entry_s;
35struct sysfs_request_s;
36
37
38/*******************************************************************************************
39 * This structure TODO
40 ******************************************************************************************/
41
42typedef struct sysfs_context_s
43{
44        void * empty;
45}
46sysfs_context_t;
47
48/*******************************************************************************************
49 * Operations definition must be provided by underlying kernel subsystem.
50 ******************************************************************************************/
51
52typedef error_t (sysfs_request_func_t)( struct sysfs_entry_s   * entry, 
53                                        struct sysfs_request_s * rq, 
54                                        uint32_t               * offset );
55
56typedef struct sysfs_op_s
57{
58        sysfs_request_func_t *open;
59        sysfs_request_func_t *read;
60        sysfs_request_func_t *write;
61        sysfs_request_func_t *close;
62}
63sysfs_op_t;
64
65/*******************************************************************************************
66 * This structure TODO 
67 ******************************************************************************************/
68
69typedef struct sysfs_request_s
70{
71        void     * data;
72        uint32_t   count;
73        uint8_t    buffer[CONFIG_SYSFS_BUFFER_SIZE];
74}
75sysfs_request_t;
76
77/*******************************************************************************************
78 * This structure TODO 
79 ******************************************************************************************/
80
81typedef struct sysfs_entry_s
82{
83        sysfs_op_t   op;
84        metafs_t     node;
85}
86sysfs_entry_t;
87
88/*******************************************************************************************
89 *        Extern Variable : sysfs root node.
90 ******************************************************************************************/
91
92extern sysfs_entry_t       sysfs_root_entry;
93
94/*******************************************************************************************
95 * This function initializes the sysfs root.
96 ******************************************************************************************/
97static inline void sysfs_root_init()
98{
99    if( CONFIG_ROOTFS_IS_VFAT ) metafs_init( &sysfs_root_entry.node , "SYS" );
100    else                        metafs_init( &sysfs_root_entry.node , "sys" );
101}
102
103
104/*******************************************************************************************
105 * This function initializes a given sysfs entry.
106 ******************************************************************************************/
107static inline void sysfs_entry_init( sysfs_entry_t * entry,
108                                     sysfs_op_t    * op,
109                                     char          * name )
110{
111        metafs_init( &entry->node , name );
112
113        if(op == NULL) return;
114 
115        entry->op.open  = op->open;
116        entry->op.read  = op->read;
117        entry->op.write = op->write;
118        entry->op.close = op->close;
119}
120
121/*******************************************************************************************
122 * This function registers a given sysfs entry into it's parent list.
123 ******************************************************************************************/
124static inline void sysfs_entry_register( sysfs_entry_t * parent,
125                                         sysfs_entry_t * entry )
126{
127        metafs_register( &parent->node , &entry->node );
128}
129
130/*******************************************************************************************
131 * This function removes a given sysfs entry from it's parent list.
132 ******************************************************************************************/
133static inline void sysfs_entry_unregister( sysfs_entry_t * parent,
134                                           sysfs_entry_t * entry )
135{
136        metafs_unregister( &parent->node , &entry->node );
137}
138
139#endif  /* _SYSFS_H_ */
Note: See TracBrowser for help on using the repository browser.