Path: blob/master/arch/powerpc/sysdev/bestcomm/bestcomm.h
10818 views
/*1* Public header for the MPC52xx processor BestComm driver2*3*4* Copyright (C) 2006 Sylvain Munaut <[email protected]>5* Copyright (C) 2005 Varma Electronics Oy,6* ( by Andrey Volkov <[email protected]> )7* Copyright (C) 2003-2004 MontaVista, Software, Inc.8* ( by Dale Farnsworth <[email protected]> )9*10* This file is licensed under the terms of the GNU General Public License11* version 2. This program is licensed "as is" without any warranty of any12* kind, whether express or implied.13*/1415#ifndef __BESTCOMM_H__16#define __BESTCOMM_H__1718/**19* struct bcom_bd - Structure describing a generic BestComm buffer descriptor20* @status: The current status of this buffer. Exact meaning depends on the21* task type22* @data: An array of u32 extra data. Size of array is task dependent.23*24* Note: Don't dereference a bcom_bd pointer as an array. The size of the25* bcom_bd is variable. Use bcom_get_bd() instead.26*/27struct bcom_bd {28u32 status;29u32 data[0]; /* variable payload size */30};3132/* ======================================================================== */33/* Generic task management */34/* ======================================================================== */3536/**37* struct bcom_task - Structure describing a loaded BestComm task38*39* This structure is never built by the driver it self. It's built and40* filled the intermediate layer of the BestComm API, the task dependent41* support code.42*43* Most likely you don't need to poke around inside this structure. The44* fields are exposed in the header just for the sake of inline functions45*/46struct bcom_task {47unsigned int tasknum;48unsigned int flags;49int irq;5051struct bcom_bd *bd;52phys_addr_t bd_pa;53void **cookie;54unsigned short index;55unsigned short outdex;56unsigned int num_bd;57unsigned int bd_size;5859void* priv;60};6162#define BCOM_FLAGS_NONE 0x00000000ul63#define BCOM_FLAGS_ENABLE_TASK (1ul << 0)6465/**66* bcom_enable - Enable a BestComm task67* @tsk: The BestComm task structure68*69* This function makes sure the given task is enabled and can be run70* by the BestComm engine as needed71*/72extern void bcom_enable(struct bcom_task *tsk);7374/**75* bcom_disable - Disable a BestComm task76* @tsk: The BestComm task structure77*78* This function disable a given task, making sure it's not executed79* by the BestComm engine.80*/81extern void bcom_disable(struct bcom_task *tsk);828384/**85* bcom_get_task_irq - Returns the irq number of a BestComm task86* @tsk: The BestComm task structure87*/88static inline int89bcom_get_task_irq(struct bcom_task *tsk) {90return tsk->irq;91}9293/* ======================================================================== */94/* BD based tasks helpers */95/* ======================================================================== */9697#define BCOM_BD_READY 0x40000000ul9899/** _bcom_next_index - Get next input index.100* @tsk: pointer to task structure101*102* Support function; Device drivers should not call this103*/104static inline int105_bcom_next_index(struct bcom_task *tsk)106{107return ((tsk->index + 1) == tsk->num_bd) ? 0 : tsk->index + 1;108}109110/** _bcom_next_outdex - Get next output index.111* @tsk: pointer to task structure112*113* Support function; Device drivers should not call this114*/115static inline int116_bcom_next_outdex(struct bcom_task *tsk)117{118return ((tsk->outdex + 1) == tsk->num_bd) ? 0 : tsk->outdex + 1;119}120121/**122* bcom_queue_empty - Checks if a BestComm task BD queue is empty123* @tsk: The BestComm task structure124*/125static inline int126bcom_queue_empty(struct bcom_task *tsk)127{128return tsk->index == tsk->outdex;129}130131/**132* bcom_queue_full - Checks if a BestComm task BD queue is full133* @tsk: The BestComm task structure134*/135static inline int136bcom_queue_full(struct bcom_task *tsk)137{138return tsk->outdex == _bcom_next_index(tsk);139}140141/**142* bcom_get_bd - Get a BD from the queue143* @tsk: The BestComm task structure144* index: Index of the BD to fetch145*/146static inline struct bcom_bd147*bcom_get_bd(struct bcom_task *tsk, unsigned int index)148{149/* A cast to (void*) so the address can be incremented by the150* real size instead of by sizeof(struct bcom_bd) */151return ((void *)tsk->bd) + (index * tsk->bd_size);152}153154/**155* bcom_buffer_done - Checks if a BestComm156* @tsk: The BestComm task structure157*/158static inline int159bcom_buffer_done(struct bcom_task *tsk)160{161struct bcom_bd *bd;162if (bcom_queue_empty(tsk))163return 0;164165bd = bcom_get_bd(tsk, tsk->outdex);166return !(bd->status & BCOM_BD_READY);167}168169/**170* bcom_prepare_next_buffer - clear status of next available buffer.171* @tsk: The BestComm task structure172*173* Returns pointer to next buffer descriptor174*/175static inline struct bcom_bd *176bcom_prepare_next_buffer(struct bcom_task *tsk)177{178struct bcom_bd *bd;179180bd = bcom_get_bd(tsk, tsk->index);181bd->status = 0; /* cleanup last status */182return bd;183}184185static inline void186bcom_submit_next_buffer(struct bcom_task *tsk, void *cookie)187{188struct bcom_bd *bd = bcom_get_bd(tsk, tsk->index);189190tsk->cookie[tsk->index] = cookie;191mb(); /* ensure the bd is really up-to-date */192bd->status |= BCOM_BD_READY;193tsk->index = _bcom_next_index(tsk);194if (tsk->flags & BCOM_FLAGS_ENABLE_TASK)195bcom_enable(tsk);196}197198static inline void *199bcom_retrieve_buffer(struct bcom_task *tsk, u32 *p_status, struct bcom_bd **p_bd)200{201void *cookie = tsk->cookie[tsk->outdex];202struct bcom_bd *bd = bcom_get_bd(tsk, tsk->outdex);203204if (p_status)205*p_status = bd->status;206if (p_bd)207*p_bd = bd;208tsk->outdex = _bcom_next_outdex(tsk);209return cookie;210}211212#endif /* __BESTCOMM_H__ */213214215