18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  linux/drivers/acorn/scsi/msgqueue.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 1997 Russell King
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  message queue handling
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef MSGQUEUE_H
108c2ecf20Sopenharmony_ci#define MSGQUEUE_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistruct message {
138c2ecf20Sopenharmony_ci    char msg[8];
148c2ecf20Sopenharmony_ci    int length;
158c2ecf20Sopenharmony_ci    int fifo;
168c2ecf20Sopenharmony_ci};
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct msgqueue_entry {
198c2ecf20Sopenharmony_ci    struct message msg;
208c2ecf20Sopenharmony_ci    struct msgqueue_entry *next;
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define NR_MESSAGES 4
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_citypedef struct {
268c2ecf20Sopenharmony_ci    struct msgqueue_entry *qe;
278c2ecf20Sopenharmony_ci    struct msgqueue_entry *free;
288c2ecf20Sopenharmony_ci    struct msgqueue_entry entries[NR_MESSAGES];
298c2ecf20Sopenharmony_ci} MsgQueue_t;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/*
328c2ecf20Sopenharmony_ci * Function: void msgqueue_initialise(MsgQueue_t *msgq)
338c2ecf20Sopenharmony_ci * Purpose : initialise a message queue
348c2ecf20Sopenharmony_ci * Params  : msgq - queue to initialise
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_ciextern void msgqueue_initialise(MsgQueue_t *msgq);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*
398c2ecf20Sopenharmony_ci * Function: void msgqueue_free(MsgQueue_t *msgq)
408c2ecf20Sopenharmony_ci * Purpose : free a queue
418c2ecf20Sopenharmony_ci * Params  : msgq - queue to free
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_ciextern void msgqueue_free(MsgQueue_t *msgq);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/*
468c2ecf20Sopenharmony_ci * Function: int msgqueue_msglength(MsgQueue_t *msgq)
478c2ecf20Sopenharmony_ci * Purpose : calculate the total length of all messages on the message queue
488c2ecf20Sopenharmony_ci * Params  : msgq - queue to examine
498c2ecf20Sopenharmony_ci * Returns : number of bytes of messages in queue
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_ciextern int msgqueue_msglength(MsgQueue_t *msgq);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/*
548c2ecf20Sopenharmony_ci * Function: struct message *msgqueue_getmsg(MsgQueue_t *msgq, int msgno)
558c2ecf20Sopenharmony_ci * Purpose : return a message & its length
568c2ecf20Sopenharmony_ci * Params  : msgq   - queue to obtain message from
578c2ecf20Sopenharmony_ci *         : msgno  - message number
588c2ecf20Sopenharmony_ci * Returns : pointer to message string, or NULL
598c2ecf20Sopenharmony_ci */
608c2ecf20Sopenharmony_ciextern struct message *msgqueue_getmsg(MsgQueue_t *msgq, int msgno);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci/*
638c2ecf20Sopenharmony_ci * Function: int msgqueue_addmsg(MsgQueue_t *msgq, int length, ...)
648c2ecf20Sopenharmony_ci * Purpose : add a message onto a message queue
658c2ecf20Sopenharmony_ci * Params  : msgq   - queue to add message on
668c2ecf20Sopenharmony_ci *	     length - length of message
678c2ecf20Sopenharmony_ci *	     ...    - message bytes
688c2ecf20Sopenharmony_ci * Returns : != 0 if successful
698c2ecf20Sopenharmony_ci */
708c2ecf20Sopenharmony_ciextern int msgqueue_addmsg(MsgQueue_t *msgq, int length, ...);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/*
738c2ecf20Sopenharmony_ci * Function: void msgqueue_flush(MsgQueue_t *msgq)
748c2ecf20Sopenharmony_ci * Purpose : flush all messages from message queue
758c2ecf20Sopenharmony_ci * Params  : msgq - queue to flush
768c2ecf20Sopenharmony_ci */
778c2ecf20Sopenharmony_ciextern void msgqueue_flush(MsgQueue_t *msgq);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#endif
80