mirror of https://github.com/dzavalishin/openpod
moved code to libs
This commit is contained in:
parent
2065809056
commit
7272adc3c9
|
@ -3,4 +3,4 @@ OpenPOD portable driver specification sources an examples
|
|||
|
||||
NB!
|
||||
|
||||
Current state of these sources: raw drafts, not even compiled.
|
||||
Current state of these sources: raw drafts, just compiled, no real working code.
|
||||
|
|
|
@ -19,7 +19,8 @@ errno_t simple_driver_sense( struct pod_driver *drv )
|
|||
POD_DEV_STATE_SET( dev, POD_DEV_STATE_INIT );
|
||||
|
||||
#if 0
|
||||
// TODO detect hardware here
|
||||
// Your code to detect hardware here
|
||||
|
||||
if( not_detected )
|
||||
{
|
||||
return ENOENT;
|
||||
|
@ -45,15 +46,13 @@ static errno_t simple_driver_enqueue( pod_device *dev, pod_request *rq )
|
|||
|
||||
//printf( "rq->request_class = %d, dev->class_id = %d\n", rq->request_class, dev->class_id );
|
||||
|
||||
// if( rq->request_class != dev->class_id ) goto einval;
|
||||
|
||||
switch( rq->operation )
|
||||
{
|
||||
case pod_video_getmode:
|
||||
{
|
||||
struct pod_video_rq_mode *rq_arg = rq->op_arg;
|
||||
|
||||
// TODO do actual non-blocking io here
|
||||
// Your code to do actual non-blocking io here
|
||||
|
||||
rq_arg->x_size = 1024;
|
||||
rq_arg->y_size = 768;
|
||||
|
@ -62,10 +61,9 @@ static errno_t simple_driver_enqueue( pod_device *dev, pod_request *rq )
|
|||
}
|
||||
break;
|
||||
|
||||
// TODO add and implement other class ops here
|
||||
// Implement other class ops here
|
||||
|
||||
default:
|
||||
einval:
|
||||
rq->err = pod_rq_status_param;
|
||||
if( rq->done ) rq->done( rq );
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
include ../config.mk
|
||||
|
||||
all::
|
||||
# TODO
|
||||
$(MAKE) -C openpod_helpers all
|
||||
# $(MAKE) -C openpod_rq all
|
||||
# $(MAKE) test
|
||||
|
||||
|
@ -9,4 +9,6 @@ install::
|
|||
# TODO
|
||||
|
||||
clean::
|
||||
$(MAKE) -C openpod_helpers clean
|
||||
# $(MAKE) -C openpod_rq clean
|
||||
-rm *.a
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
include ../../config.mk
|
||||
|
||||
# TODO move pod_local_types.h from here and tests to some common place
|
||||
CFLAGS += -I../../openpod -I.
|
||||
|
||||
all: libopenpod_helpers.a
|
||||
|
||||
install::
|
||||
# TODO
|
||||
|
||||
clean::
|
||||
-rm *.o
|
||||
-rm *.a
|
||||
-rm *.~c
|
||||
-rm *.~h
|
||||
|
||||
|
||||
libopenpod_helpers.a: pod_dev_event.o request.o driver.o
|
||||
ar crsv $@ *.o
|
||||
cp $@ ..
|
|
@ -0,0 +1,61 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include <openpod.h>
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//
|
||||
// Driver methods
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
errno_t pod_construct( pod_driver *drv )
|
||||
{
|
||||
if( (drv == 0) || (drv->calls.pod_construct == 0) )
|
||||
return EFAULT;
|
||||
|
||||
return drv->calls.pod_construct( drv );
|
||||
}
|
||||
|
||||
|
||||
errno_t pod_destruct( pod_driver *drv )
|
||||
{
|
||||
if( (drv == 0) || (drv->calls.pod_destruct == 0) )
|
||||
return EFAULT;
|
||||
|
||||
return drv->calls.pod_destruct( drv );
|
||||
}
|
||||
|
||||
|
||||
errno_t pod_activate( pod_driver *drv )
|
||||
{
|
||||
if( (drv == 0) || (drv->calls.pod_activate== 0) )
|
||||
return EFAULT;
|
||||
|
||||
return drv->calls.pod_activate( drv );
|
||||
}
|
||||
|
||||
|
||||
errno_t pod_deactivate( pod_driver *drv )
|
||||
{
|
||||
if( (drv == 0) || (drv->calls.pod_deactivate== 0) )
|
||||
return EFAULT;
|
||||
|
||||
return drv->calls.pod_deactivate( drv );
|
||||
}
|
||||
|
||||
|
||||
errno_t pod_sense( pod_driver *drv )
|
||||
{
|
||||
if( (drv == 0) || (drv->calls.pod_sense== 0) )
|
||||
return EFAULT;
|
||||
|
||||
return drv->calls.pod_sense( drv );
|
||||
}
|
||||
|
||||
|
||||
//errno_t pod_probe( pod_driver *drv, bus?, dev? )
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#include <openpod.h>
|
||||
#include <pod_kernel_api.h>
|
||||
|
||||
|
||||
// Default implementation, supports just logging
|
||||
|
||||
// __attribute__((weak))
|
||||
|
||||
errno_t
|
||||
pod_dev_event( struct pod_driver *drv, struct pod_device *dev, int event_id, void *event_info )
|
||||
{
|
||||
(void)dev;
|
||||
|
||||
if( POD_EVENT_LOG != event_id ) return 0;
|
||||
|
||||
// TODO dev name
|
||||
// TODO loglevel
|
||||
return pod_log_print( 0, "Driver '%s' device state: '%s'\n", drv->name, (const char*)event_info );
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// Empty, to satisfy include from pod_types.h
|
|
@ -0,0 +1,77 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include <openpod.h>
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//
|
||||
// Request methods
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
errno_t pod_rq_enqueue( pod_device *dev, pod_request *rq )
|
||||
{
|
||||
if( (dev == 0) || (dev->calls == 0) || (dev->calls->enqueue == 0 ) )
|
||||
return EFAULT;
|
||||
|
||||
if( rq->request_class != dev->class_id )
|
||||
{
|
||||
rq->err = pod_rq_status_param;
|
||||
if( rq->done ) rq->done( rq );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( !POD_DEV_STATE_CHECK( dev, POD_DEV_STATE_INIT ) )
|
||||
return ENXIO;
|
||||
|
||||
if( !POD_DEV_STATE_CHECK( dev, POD_DEV_STATE_FOUND ) )
|
||||
return ENODEV;
|
||||
|
||||
rq->err = pod_rq_status_unprocessed;
|
||||
|
||||
return dev->calls->enqueue( dev, rq );
|
||||
}
|
||||
|
||||
|
||||
errno_t pod_rq_dequeue( pod_device *dev, pod_request *rq )
|
||||
{
|
||||
if( (dev == 0) || (dev->calls == 0) || (dev->calls->dequeue == 0 ) )
|
||||
return EFAULT;
|
||||
|
||||
if( !POD_DEV_STATE_CHECK( dev, POD_DEV_STATE_INIT ) )
|
||||
return ENXIO;
|
||||
|
||||
if( !POD_DEV_STATE_CHECK( dev, POD_DEV_STATE_FOUND ) )
|
||||
return ENODEV;
|
||||
|
||||
return dev->calls->dequeue( dev, rq );
|
||||
}
|
||||
|
||||
errno_t pod_rq_fence( pod_device *dev, pod_request *rq )
|
||||
{
|
||||
if( (dev == 0) || (dev->calls == 0) || (dev->calls->fence == 0 ) )
|
||||
return EFAULT;
|
||||
|
||||
if( !POD_DEV_STATE_CHECK( dev, POD_DEV_STATE_INIT ) )
|
||||
return ENXIO;
|
||||
|
||||
if( !POD_DEV_STATE_CHECK( dev, POD_DEV_STATE_FOUND ) )
|
||||
return ENODEV;
|
||||
|
||||
return dev->calls->fence( dev, rq );
|
||||
}
|
||||
|
||||
errno_t pod_rq_raise( pod_device *dev, pod_request *rq, uint32_t io_prio )
|
||||
{
|
||||
if( (dev == 0) || (dev->calls == 0) || (dev->calls->raise_prio == 0 ) )
|
||||
return EFAULT;
|
||||
|
||||
if( !POD_DEV_STATE_CHECK( dev, POD_DEV_STATE_INIT ) )
|
||||
return ENXIO;
|
||||
|
||||
if( !POD_DEV_STATE_CHECK( dev, POD_DEV_STATE_FOUND ) )
|
||||
return ENODEV;
|
||||
|
||||
return dev->calls->raise_prio( dev, rq, io_prio );
|
||||
}
|
|
@ -26,7 +26,6 @@ typedef struct pod_dev_f
|
|||
|
||||
#define POD_DEVICE_MAGIC 0xDEFF00A3
|
||||
|
||||
// TODO describe state flags in spec
|
||||
|
||||
// Device is initialized (constructed)
|
||||
#define POD_DEV_STATE_INIT (1<<0)
|
||||
|
@ -86,7 +85,7 @@ typedef struct pod_device
|
|||
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//
|
||||
|
@ -162,7 +161,7 @@ inline errno_t pod_rq_raise( pod_device *dev, pod_request *rq, uint32_t io_prio
|
|||
return dev->calls->raise_prio( dev, rq, io_prio );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ typedef struct pod_driver
|
|||
uint8_t class_id;
|
||||
uint8_t pad0;
|
||||
uint8_t pad1;
|
||||
uint8_t pad2;
|
||||
uint8_t state_flags; // Driver state - TODO
|
||||
|
||||
//uint32_t capabilities; // tbd.
|
||||
|
||||
|
@ -123,9 +123,23 @@ typedef struct pod_driver
|
|||
} pod_driver;
|
||||
|
||||
|
||||
// Drivar is initialized (constructed)
|
||||
#define POD_DRV_STATE_INIT (1<<0)
|
||||
// Driver hardware search done (pod_sense called)
|
||||
#define POD_DRV_STATE_FOUND (1<<1)
|
||||
|
||||
|
||||
|
||||
errno_t pod_construct( pod_driver *drv );
|
||||
errno_t pod_destruct( pod_driver *drv );
|
||||
|
||||
errno_t pod_activate( pod_driver *drv );
|
||||
errno_t pod_deactivate( pod_driver *drv );
|
||||
|
||||
errno_t pod_sense( pod_driver *drv );
|
||||
|
||||
#if 0
|
||||
|
||||
inline errno_t pod_construct( pod_driver *drv )
|
||||
{
|
||||
if( (drv == 0) || (drv->calls.pod_construct == 0) )
|
||||
|
@ -173,7 +187,7 @@ inline errno_t pod_sense( pod_driver *drv )
|
|||
|
||||
//inline errno_t pod_probe( pod_driver *drv, bus?, dev? )
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
// çíà÷åíèå ïîëÿ operation èëè èíäåêñ â òàáëèöó ìåòîäîâ class_interface
|
||||
enum pod_block_operartions
|
||||
{
|
||||
nop,
|
||||
read, write,
|
||||
trim // SSD specific
|
||||
pod_block_nop,
|
||||
pod_block_read, pod_block_write,
|
||||
pod_block_trim // SSD specific
|
||||
};
|
||||
|
||||
// trim
|
||||
|
|
|
@ -65,20 +65,6 @@ typedef enum pod_v_flags {
|
|||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
// TODO move defines to rq hdr - BUG, must return rq
|
||||
#define create_op_rq( __type, __class, __op ) \
|
||||
do { \
|
||||
pod_request *rq = pod_malloc( sizeof(pod_request) + sizeof(__type) ); \
|
||||
rq->class_specific = ((void*)rq) + sizeof(pod_request); \
|
||||
rq->requset_class = (__class); \
|
||||
rq->operation = (__op); \
|
||||
rq->io_prio = 0x1000; \
|
||||
rq->err = not_started;\
|
||||
rq->done = 0; \
|
||||
} while(0)
|
||||
|
||||
#define rq_specific( __rq, __type ) \
|
||||
( (__type *) ((__rq)->class_specific) )
|
||||
|
||||
// clear
|
||||
struct pod_video_rq_sqare
|
||||
|
|
|
@ -34,6 +34,8 @@ typedef struct pod_thread
|
|||
//
|
||||
// Device registration
|
||||
//
|
||||
// Required.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -71,6 +73,8 @@ errno_t pod_dev_event( struct pod_driver *drv, struct pod_device *dev, int even
|
|||
//
|
||||
// Threads
|
||||
//
|
||||
// Optional.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
errno_t pod_kernel_thread_start( pod_thread *tid, void (*thread_func)(void *), void *thread_func_arg );
|
||||
|
@ -78,12 +82,31 @@ errno_t pod_kernel_thread_kill( pod_thread tid );
|
|||
|
||||
// TODO threadlets/dpc?
|
||||
|
||||
// TODO timers?
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Timers
|
||||
//
|
||||
// Required.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
#define POD_TIMER_PERIODIC (1<<0)
|
||||
// Call will be postponed as long as spinlock is still taken
|
||||
//#define POD_TIMER_CHECKLOCK (1<<2)
|
||||
|
||||
// Request timer_func to be called in msec milliseconds
|
||||
errno_t pod_kernel_timer_start( int *timer_id, int msec, int timer_flags, void (*timer_func)(void *), void *timer_func_arg );
|
||||
// Reset timer. Returns ENOENT if timer does not exist (one-shot timer kills itself automatically).
|
||||
errno_t pod_kernel_timer_stop( int timer_id );
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Sync
|
||||
//
|
||||
// Optional, must be implemented if threads exist.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -106,18 +129,38 @@ errno_t pod_kernel_signal_cond( pod_cond *cond );
|
|||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Logging and panic
|
||||
// Spinlocks
|
||||
//
|
||||
// Required.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
errno_t pod_log_print( int loglevel, const char **format, ... );
|
||||
void pod_panic(const char *fmt, ...);
|
||||
struct pod_spinlock;
|
||||
|
||||
// Push interrupt mask, disable interrupts, if SMP - check/take spin lock
|
||||
errno_t pod_kernel_spin_lock( struct pod_spinlock *l );
|
||||
// Pop interrupt mask, if SMP - release spin lock
|
||||
errno_t pod_kernel_spin_unlock( struct pod_spinlock *l );
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Logging and panic
|
||||
//
|
||||
// Required.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
errno_t pod_log_print( int loglevel, const char *format, ... );
|
||||
void pod_panic(const char *format, ...);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Memory and address space
|
||||
//
|
||||
// Required. TODO do we need map/unmap/vadd allocation? What to do with MMU-less systems?
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
// TODO size_t
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef POD_PROPERTIES_H
|
||||
#define POD_PROPERTIES_H
|
||||
|
||||
#include <pod_types.h>
|
||||
|
||||
//*******************************************************************
|
||||
//
|
||||
|
|
|
@ -59,9 +59,29 @@ typedef struct pod_request
|
|||
|
||||
|
||||
|
||||
// Create request
|
||||
#define create_op_rq( __rqpp, __type, __class, __op ) \
|
||||
do { \
|
||||
pod_request *rq = pod_malloc( sizeof(pod_request) + sizeof(__type) ); \
|
||||
rq->class_specific = ((void*)rq) + sizeof(pod_request); \
|
||||
rq->requset_class = (__class); \
|
||||
rq->operation = (__op); \
|
||||
rq->io_prio = 0x1000; \
|
||||
rq->err = not_started;\
|
||||
rq->done = 0; \
|
||||
*(__rqpp) = rq; \
|
||||
} while(0)
|
||||
|
||||
// Access class_specific field
|
||||
#define rq_specific( __rq, __type ) \
|
||||
( (__type *) ((__rq)->class_specific) )
|
||||
|
||||
|
||||
|
||||
errno_t pod_rq_enqueue( struct pod_device *dev, pod_request *rq );
|
||||
errno_t pod_rq_dequeue( struct pod_device *dev, pod_request *rq );
|
||||
errno_t pod_rq_fence( struct pod_device *dev, pod_request *rq );
|
||||
errno_t pod_rq_raise( struct pod_device *dev, pod_request *rq, uint32_t io_prio );
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
#include "pod_local_types.h"
|
||||
|
||||
|
||||
// Get just one type definition
|
||||
#define __need_size_t
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
#ifndef POD_ERRNO_T_DEFINED
|
||||
|
|
|
@ -10,7 +10,7 @@ SET(CMAKE_C_FLAGS " -std=c99 -O3 -Wall -Wextra -Wimplicit -L../../libs/ -I../../
|
|||
INCLUDE_DIRECTORIES ( "/usr/include" )
|
||||
ADD_EXECUTABLE(runtests main.c utils.c panic.c kern.c)
|
||||
#TARGET_LINK_LIBRARIES(runtests kern )
|
||||
TARGET_LINK_LIBRARIES(runtests cunit dl )
|
||||
TARGET_LINK_LIBRARIES(runtests cunit dl openpod_helpers )
|
||||
|
||||
ADD_CUSTOM_TARGET(test "./runtests" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" VERBATIM)
|
||||
ADD_SUBDIRECTORY(suites)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
MACRO(ADD_MODULE file)
|
||||
ADD_LIBRARY( ${file} MODULE ${file}.c ../utils.c ../panic.c ../kern.c )
|
||||
# TARGET_LINK_LIBRARIES( ${file} cunit kern phantom win )
|
||||
TARGET_LINK_LIBRARIES( ${file} cunit )
|
||||
TARGET_LINK_LIBRARIES( ${file} cunit openpod_helpers )
|
||||
SET_TARGET_PROPERTIES( ${file} PROPERTIES
|
||||
PREFIX ""
|
||||
LIBRARY_OUTPUT_DIRECTORY "."
|
||||
|
@ -14,7 +14,7 @@ INCLUDE_DIRECTORIES ( "${CMAKE_SOURCE_DIR}" )
|
|||
INCLUDE_DIRECTORIES ( "../../../openpod" ".." )
|
||||
|
||||
|
||||
SET(CMAKE_C_FLAGS " -std=c99 -O3 -Wall -Wextra -Wimplicit -I ../../openpod -L../../libs/")
|
||||
SET(CMAKE_C_FLAGS " -std=c99 -O3 -Wall -Wextra -Wimplicit -I ../../../openpod -L../../../libs/")
|
||||
|
||||
|
||||
FOREACH ( module ${C_FILES} )
|
||||
|
|
Loading…
Reference in New Issue