License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2007-07-18 08:37:04 +07:00
|
|
|
/******************************************************************************
|
|
|
|
* ring.h
|
|
|
|
*
|
|
|
|
* Shared producer-consumer ring macros.
|
|
|
|
*
|
|
|
|
* Tim Deegan and Andrew Warfield November 2004.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __XEN_PUBLIC_IO_RING_H__
|
|
|
|
#define __XEN_PUBLIC_IO_RING_H__
|
|
|
|
|
2017-07-06 03:08:30 +07:00
|
|
|
#include <xen/interface/grant_table.h>
|
|
|
|
|
2007-07-18 08:37:04 +07:00
|
|
|
typedef unsigned int RING_IDX;
|
|
|
|
|
|
|
|
/* Round a 32-bit unsigned constant down to the nearest power of two. */
|
|
|
|
#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1))
|
|
|
|
#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x))
|
|
|
|
#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x))
|
|
|
|
#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x))
|
|
|
|
#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate size of a shared ring, given the total available space for the
|
|
|
|
* ring and indexes (_sz), and the name tag of the request/response structure.
|
|
|
|
* A ring contains as many entries as will fit, rounded down to the nearest
|
|
|
|
* power of two (so we can mask with (size-1) to loop around).
|
|
|
|
*/
|
2010-12-09 03:39:12 +07:00
|
|
|
#define __CONST_RING_SIZE(_s, _sz) \
|
|
|
|
(__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
|
|
|
|
sizeof(((struct _s##_sring *)0)->ring[0])))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The same for passing in an actual pointer instead of a name tag.
|
|
|
|
*/
|
|
|
|
#define __RING_SIZE(_s, _sz) \
|
|
|
|
(__RD32(((_sz) - (long)&(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
|
2007-07-18 08:37:04 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros to make the correct C datatypes for a new kind of ring.
|
|
|
|
*
|
|
|
|
* To make a new ring datatype, you need to have two message structures,
|
|
|
|
* let's say struct request, and struct response already defined.
|
|
|
|
*
|
|
|
|
* In a header where you want the ring datatype declared, you then do:
|
|
|
|
*
|
|
|
|
* DEFINE_RING_TYPES(mytag, struct request, struct response);
|
|
|
|
*
|
|
|
|
* These expand out to give you a set of types, as you can see below.
|
|
|
|
* The most important of these are:
|
|
|
|
*
|
|
|
|
* struct mytag_sring - The shared ring.
|
|
|
|
* struct mytag_front_ring - The 'front' half of the ring.
|
|
|
|
* struct mytag_back_ring - The 'back' half of the ring.
|
|
|
|
*
|
|
|
|
* To initialize a ring in your code you need to know the location and size
|
|
|
|
* of the shared memory area (PAGE_SIZE, for instance). To initialise
|
|
|
|
* the front half:
|
|
|
|
*
|
|
|
|
* struct mytag_front_ring front_ring;
|
|
|
|
* SHARED_RING_INIT((struct mytag_sring *)shared_page);
|
|
|
|
* FRONT_RING_INIT(&front_ring, (struct mytag_sring *)shared_page,
|
|
|
|
* PAGE_SIZE);
|
|
|
|
*
|
|
|
|
* Initializing the back follows similarly (note that only the front
|
|
|
|
* initializes the shared ring):
|
|
|
|
*
|
|
|
|
* struct mytag_back_ring back_ring;
|
|
|
|
* BACK_RING_INIT(&back_ring, (struct mytag_sring *)shared_page,
|
|
|
|
* PAGE_SIZE);
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFINE_RING_TYPES(__name, __req_t, __rsp_t) \
|
|
|
|
\
|
|
|
|
/* Shared ring entry */ \
|
|
|
|
union __name##_sring_entry { \
|
|
|
|
__req_t req; \
|
|
|
|
__rsp_t rsp; \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
/* Shared ring page */ \
|
|
|
|
struct __name##_sring { \
|
|
|
|
RING_IDX req_prod, req_event; \
|
|
|
|
RING_IDX rsp_prod, rsp_event; \
|
|
|
|
uint8_t pad[48]; \
|
|
|
|
union __name##_sring_entry ring[1]; /* variable-length */ \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
/* "Front" end's private variables */ \
|
|
|
|
struct __name##_front_ring { \
|
|
|
|
RING_IDX req_prod_pvt; \
|
|
|
|
RING_IDX rsp_cons; \
|
|
|
|
unsigned int nr_ents; \
|
|
|
|
struct __name##_sring *sring; \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
/* "Back" end's private variables */ \
|
|
|
|
struct __name##_back_ring { \
|
|
|
|
RING_IDX rsp_prod_pvt; \
|
|
|
|
RING_IDX req_cons; \
|
|
|
|
unsigned int nr_ents; \
|
|
|
|
struct __name##_sring *sring; \
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros for manipulating rings.
|
|
|
|
*
|
|
|
|
* FRONT_RING_whatever works on the "front end" of a ring: here
|
|
|
|
* requests are pushed on to the ring and responses taken off it.
|
|
|
|
*
|
|
|
|
* BACK_RING_whatever works on the "back end" of a ring: here
|
|
|
|
* requests are taken off the ring and responses put on.
|
|
|
|
*
|
|
|
|
* N.B. these macros do NO INTERLOCKS OR FLOW CONTROL.
|
|
|
|
* This is OK in 1-for-1 request-response situations where the
|
|
|
|
* requestor (front end) never has more than RING_SIZE()-1
|
|
|
|
* outstanding requests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Initialising empty rings */
|
|
|
|
#define SHARED_RING_INIT(_s) do { \
|
|
|
|
(_s)->req_prod = (_s)->rsp_prod = 0; \
|
|
|
|
(_s)->req_event = (_s)->rsp_event = 1; \
|
|
|
|
memset((_s)->pad, 0, sizeof((_s)->pad)); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define FRONT_RING_INIT(_r, _s, __size) do { \
|
|
|
|
(_r)->req_prod_pvt = 0; \
|
|
|
|
(_r)->rsp_cons = 0; \
|
|
|
|
(_r)->nr_ents = __RING_SIZE(_s, __size); \
|
|
|
|
(_r)->sring = (_s); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define BACK_RING_INIT(_r, _s, __size) do { \
|
|
|
|
(_r)->rsp_prod_pvt = 0; \
|
|
|
|
(_r)->req_cons = 0; \
|
|
|
|
(_r)->nr_ents = __RING_SIZE(_s, __size); \
|
|
|
|
(_r)->sring = (_s); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* Initialize to existing shared indexes -- for recovery */
|
|
|
|
#define FRONT_RING_ATTACH(_r, _s, __size) do { \
|
|
|
|
(_r)->sring = (_s); \
|
|
|
|
(_r)->req_prod_pvt = (_s)->req_prod; \
|
|
|
|
(_r)->rsp_cons = (_s)->rsp_prod; \
|
|
|
|
(_r)->nr_ents = __RING_SIZE(_s, __size); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define BACK_RING_ATTACH(_r, _s, __size) do { \
|
|
|
|
(_r)->sring = (_s); \
|
|
|
|
(_r)->rsp_prod_pvt = (_s)->rsp_prod; \
|
|
|
|
(_r)->req_cons = (_s)->req_prod; \
|
|
|
|
(_r)->nr_ents = __RING_SIZE(_s, __size); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* How big is this ring? */
|
|
|
|
#define RING_SIZE(_r) \
|
|
|
|
((_r)->nr_ents)
|
|
|
|
|
|
|
|
/* Number of free requests (for use on front side only). */
|
|
|
|
#define RING_FREE_REQUESTS(_r) \
|
|
|
|
(RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
|
|
|
|
|
|
|
|
/* Test if there is an empty slot available on the front ring.
|
|
|
|
* (This is only meaningful from the front. )
|
|
|
|
*/
|
|
|
|
#define RING_FULL(_r) \
|
|
|
|
(RING_FREE_REQUESTS(_r) == 0)
|
|
|
|
|
|
|
|
/* Test if there are outstanding messages to be processed on a ring. */
|
|
|
|
#define RING_HAS_UNCONSUMED_RESPONSES(_r) \
|
|
|
|
((_r)->sring->rsp_prod - (_r)->rsp_cons)
|
|
|
|
|
|
|
|
#define RING_HAS_UNCONSUMED_REQUESTS(_r) \
|
|
|
|
({ \
|
|
|
|
unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \
|
|
|
|
unsigned int rsp = RING_SIZE(_r) - \
|
|
|
|
((_r)->req_cons - (_r)->rsp_prod_pvt); \
|
|
|
|
req < rsp ? req : rsp; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/* Direct access to individual ring elements, by index. */
|
|
|
|
#define RING_GET_REQUEST(_r, _idx) \
|
|
|
|
(&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))
|
|
|
|
|
2015-10-30 21:58:08 +07:00
|
|
|
/*
|
|
|
|
* Get a local copy of a request.
|
|
|
|
*
|
|
|
|
* Use this in preference to RING_GET_REQUEST() so all processing is
|
|
|
|
* done on a local copy that cannot be modified by the other end.
|
|
|
|
*
|
|
|
|
* Note that https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 may cause this
|
|
|
|
* to be ineffective where _req is a struct which consists of only bitfields.
|
|
|
|
*/
|
|
|
|
#define RING_COPY_REQUEST(_r, _idx, _req) do { \
|
|
|
|
/* Use volatile to force the copy into _req. */ \
|
|
|
|
*(_req) = *(volatile typeof(_req))RING_GET_REQUEST(_r, _idx); \
|
|
|
|
} while (0)
|
|
|
|
|
2007-07-18 08:37:04 +07:00
|
|
|
#define RING_GET_RESPONSE(_r, _idx) \
|
|
|
|
(&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
|
|
|
|
|
|
|
|
/* Loop termination condition: Would the specified index overflow the ring? */
|
|
|
|
#define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \
|
|
|
|
(((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
|
|
|
|
|
2013-06-18 02:16:33 +07:00
|
|
|
/* Ill-behaved frontend determination: Can there be this many requests? */
|
|
|
|
#define RING_REQUEST_PROD_OVERFLOW(_r, _prod) \
|
|
|
|
(((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))
|
|
|
|
|
|
|
|
|
2007-07-18 08:37:04 +07:00
|
|
|
#define RING_PUSH_REQUESTS(_r) do { \
|
2015-12-27 23:02:16 +07:00
|
|
|
virt_wmb(); /* back sees requests /before/ updated producer index */ \
|
2007-07-18 08:37:04 +07:00
|
|
|
(_r)->sring->req_prod = (_r)->req_prod_pvt; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define RING_PUSH_RESPONSES(_r) do { \
|
2015-12-27 23:02:16 +07:00
|
|
|
virt_wmb(); /* front sees responses /before/ updated producer index */ \
|
2007-07-18 08:37:04 +07:00
|
|
|
(_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notification hold-off (req_event and rsp_event):
|
|
|
|
*
|
|
|
|
* When queueing requests or responses on a shared ring, it may not always be
|
|
|
|
* necessary to notify the remote end. For example, if requests are in flight
|
|
|
|
* in a backend, the front may be able to queue further requests without
|
|
|
|
* notifying the back (if the back checks for new requests when it queues
|
|
|
|
* responses).
|
|
|
|
*
|
|
|
|
* When enqueuing requests or responses:
|
|
|
|
*
|
|
|
|
* Use RING_PUSH_{REQUESTS,RESPONSES}_AND_CHECK_NOTIFY(). The second argument
|
|
|
|
* is a boolean return value. True indicates that the receiver requires an
|
|
|
|
* asynchronous notification.
|
|
|
|
*
|
|
|
|
* After dequeuing requests or responses (before sleeping the connection):
|
|
|
|
*
|
|
|
|
* Use RING_FINAL_CHECK_FOR_REQUESTS() or RING_FINAL_CHECK_FOR_RESPONSES().
|
|
|
|
* The second argument is a boolean return value. True indicates that there
|
|
|
|
* are pending messages on the ring (i.e., the connection should not be put
|
|
|
|
* to sleep).
|
|
|
|
*
|
|
|
|
* These macros will set the req_event/rsp_event field to trigger a
|
|
|
|
* notification on the very next message that is enqueued. If you want to
|
|
|
|
* create batches of work (i.e., only receive a notification after several
|
|
|
|
* messages have been enqueued) then you will need to create a customised
|
|
|
|
* version of the FINAL_CHECK macro in your own code, which sets the event
|
|
|
|
* field appropriately.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \
|
|
|
|
RING_IDX __old = (_r)->sring->req_prod; \
|
|
|
|
RING_IDX __new = (_r)->req_prod_pvt; \
|
2015-12-27 23:02:16 +07:00
|
|
|
virt_wmb(); /* back sees requests /before/ updated producer index */ \
|
2007-07-18 08:37:04 +07:00
|
|
|
(_r)->sring->req_prod = __new; \
|
2015-12-27 23:02:16 +07:00
|
|
|
virt_mb(); /* back sees new requests /before/ we check req_event */ \
|
2007-07-18 08:37:04 +07:00
|
|
|
(_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \
|
|
|
|
(RING_IDX)(__new - __old)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \
|
|
|
|
RING_IDX __old = (_r)->sring->rsp_prod; \
|
|
|
|
RING_IDX __new = (_r)->rsp_prod_pvt; \
|
2015-12-27 23:02:16 +07:00
|
|
|
virt_wmb(); /* front sees responses /before/ updated producer index */ \
|
2007-07-18 08:37:04 +07:00
|
|
|
(_r)->sring->rsp_prod = __new; \
|
2015-12-27 23:02:16 +07:00
|
|
|
virt_mb(); /* front sees new responses /before/ we check rsp_event */ \
|
2007-07-18 08:37:04 +07:00
|
|
|
(_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \
|
|
|
|
(RING_IDX)(__new - __old)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do { \
|
|
|
|
(_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
|
|
|
|
if (_work_to_do) break; \
|
|
|
|
(_r)->sring->req_event = (_r)->req_cons + 1; \
|
2015-12-27 23:02:16 +07:00
|
|
|
virt_mb(); \
|
2007-07-18 08:37:04 +07:00
|
|
|
(_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do { \
|
|
|
|
(_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
|
|
|
|
if (_work_to_do) break; \
|
|
|
|
(_r)->sring->rsp_event = (_r)->rsp_cons + 1; \
|
2015-12-27 23:02:16 +07:00
|
|
|
virt_mb(); \
|
2007-07-18 08:37:04 +07:00
|
|
|
(_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
|
|
|
|
} while (0)
|
|
|
|
|
2017-04-06 02:03:55 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DEFINE_XEN_FLEX_RING_AND_INTF defines two monodirectional rings and
|
|
|
|
* functions to check if there is data on the ring, and to read and
|
|
|
|
* write to them.
|
|
|
|
*
|
|
|
|
* DEFINE_XEN_FLEX_RING is similar to DEFINE_XEN_FLEX_RING_AND_INTF, but
|
|
|
|
* does not define the indexes page. As different protocols can have
|
|
|
|
* extensions to the basic format, this macro allow them to define their
|
|
|
|
* own struct.
|
|
|
|
*
|
|
|
|
* XEN_FLEX_RING_SIZE
|
|
|
|
* Convenience macro to calculate the size of one of the two rings
|
|
|
|
* from the overall order.
|
|
|
|
*
|
|
|
|
* $NAME_mask
|
|
|
|
* Function to apply the size mask to an index, to reduce the index
|
|
|
|
* within the range [0-size].
|
|
|
|
*
|
|
|
|
* $NAME_read_packet
|
|
|
|
* Function to read data from the ring. The amount of data to read is
|
|
|
|
* specified by the "size" argument.
|
|
|
|
*
|
|
|
|
* $NAME_write_packet
|
|
|
|
* Function to write data to the ring. The amount of data to write is
|
|
|
|
* specified by the "size" argument.
|
|
|
|
*
|
|
|
|
* $NAME_get_ring_ptr
|
|
|
|
* Convenience function that returns a pointer to read/write to the
|
|
|
|
* ring at the right location.
|
|
|
|
*
|
|
|
|
* $NAME_data_intf
|
|
|
|
* Indexes page, shared between frontend and backend. It also
|
|
|
|
* contains the array of grant refs.
|
|
|
|
*
|
|
|
|
* $NAME_queued
|
|
|
|
* Function to calculate how many bytes are currently on the ring,
|
|
|
|
* ready to be read. It can also be used to calculate how much free
|
|
|
|
* space is currently on the ring (XEN_FLEX_RING_SIZE() -
|
|
|
|
* $NAME_queued()).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef XEN_PAGE_SHIFT
|
|
|
|
/* The PAGE_SIZE for ring protocols and hypercall interfaces is always
|
|
|
|
* 4K, regardless of the architecture, and page granularity chosen by
|
|
|
|
* operating systems.
|
|
|
|
*/
|
|
|
|
#define XEN_PAGE_SHIFT 12
|
|
|
|
#endif
|
|
|
|
#define XEN_FLEX_RING_SIZE(order) \
|
|
|
|
(1UL << ((order) + XEN_PAGE_SHIFT - 1))
|
|
|
|
|
|
|
|
#define DEFINE_XEN_FLEX_RING(name) \
|
|
|
|
static inline RING_IDX name##_mask(RING_IDX idx, RING_IDX ring_size) \
|
|
|
|
{ \
|
|
|
|
return idx & (ring_size - 1); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static inline unsigned char *name##_get_ring_ptr(unsigned char *buf, \
|
|
|
|
RING_IDX idx, \
|
|
|
|
RING_IDX ring_size) \
|
|
|
|
{ \
|
|
|
|
return buf + name##_mask(idx, ring_size); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static inline void name##_read_packet(void *opaque, \
|
|
|
|
const unsigned char *buf, \
|
|
|
|
size_t size, \
|
|
|
|
RING_IDX masked_prod, \
|
|
|
|
RING_IDX *masked_cons, \
|
|
|
|
RING_IDX ring_size) \
|
|
|
|
{ \
|
|
|
|
if (*masked_cons < masked_prod || \
|
|
|
|
size <= ring_size - *masked_cons) { \
|
|
|
|
memcpy(opaque, buf + *masked_cons, size); \
|
|
|
|
} else { \
|
|
|
|
memcpy(opaque, buf + *masked_cons, ring_size - *masked_cons); \
|
|
|
|
memcpy((unsigned char *)opaque + ring_size - *masked_cons, buf, \
|
|
|
|
size - (ring_size - *masked_cons)); \
|
|
|
|
} \
|
|
|
|
*masked_cons = name##_mask(*masked_cons + size, ring_size); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static inline void name##_write_packet(unsigned char *buf, \
|
|
|
|
const void *opaque, \
|
|
|
|
size_t size, \
|
|
|
|
RING_IDX *masked_prod, \
|
|
|
|
RING_IDX masked_cons, \
|
|
|
|
RING_IDX ring_size) \
|
|
|
|
{ \
|
|
|
|
if (*masked_prod < masked_cons || \
|
|
|
|
size <= ring_size - *masked_prod) { \
|
|
|
|
memcpy(buf + *masked_prod, opaque, size); \
|
|
|
|
} else { \
|
|
|
|
memcpy(buf + *masked_prod, opaque, ring_size - *masked_prod); \
|
|
|
|
memcpy(buf, (unsigned char *)opaque + (ring_size - *masked_prod), \
|
|
|
|
size - (ring_size - *masked_prod)); \
|
|
|
|
} \
|
|
|
|
*masked_prod = name##_mask(*masked_prod + size, ring_size); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static inline RING_IDX name##_queued(RING_IDX prod, \
|
|
|
|
RING_IDX cons, \
|
|
|
|
RING_IDX ring_size) \
|
|
|
|
{ \
|
|
|
|
RING_IDX size; \
|
|
|
|
\
|
|
|
|
if (prod == cons) \
|
|
|
|
return 0; \
|
|
|
|
\
|
|
|
|
prod = name##_mask(prod, ring_size); \
|
|
|
|
cons = name##_mask(cons, ring_size); \
|
|
|
|
\
|
|
|
|
if (prod == cons) \
|
|
|
|
return ring_size; \
|
|
|
|
\
|
|
|
|
if (prod > cons) \
|
|
|
|
size = prod - cons; \
|
|
|
|
else \
|
|
|
|
size = ring_size - (cons - prod); \
|
|
|
|
return size; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
struct name##_data { \
|
|
|
|
unsigned char *in; /* half of the allocation */ \
|
|
|
|
unsigned char *out; /* half of the allocation */ \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_XEN_FLEX_RING_AND_INTF(name) \
|
|
|
|
struct name##_data_intf { \
|
|
|
|
RING_IDX in_cons, in_prod; \
|
|
|
|
\
|
|
|
|
uint8_t pad1[56]; \
|
|
|
|
\
|
|
|
|
RING_IDX out_cons, out_prod; \
|
|
|
|
\
|
|
|
|
uint8_t pad2[56]; \
|
|
|
|
\
|
|
|
|
RING_IDX ring_order; \
|
|
|
|
grant_ref_t ref[]; \
|
|
|
|
}; \
|
|
|
|
DEFINE_XEN_FLEX_RING(name)
|
|
|
|
|
2007-07-18 08:37:04 +07:00
|
|
|
#endif /* __XEN_PUBLIC_IO_RING_H__ */
|