13af7e7aaSFrançois Tigeot /*
23af7e7aaSFrançois Tigeot * Copyright (c) 2020 François Tigeot <ftigeot@wolfpond.org>
33af7e7aaSFrançois Tigeot * All rights reserved.
43af7e7aaSFrançois Tigeot *
53af7e7aaSFrançois Tigeot * Redistribution and use in source and binary forms, with or without
63af7e7aaSFrançois Tigeot * modification, are permitted provided that the following conditions
73af7e7aaSFrançois Tigeot * are met:
83af7e7aaSFrançois Tigeot * 1. Redistributions of source code must retain the above copyright
93af7e7aaSFrançois Tigeot * notice unmodified, this list of conditions, and the following
103af7e7aaSFrançois Tigeot * disclaimer.
113af7e7aaSFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright
123af7e7aaSFrançois Tigeot * notice, this list of conditions and the following disclaimer in the
133af7e7aaSFrançois Tigeot * documentation and/or other materials provided with the distribution.
143af7e7aaSFrançois Tigeot *
153af7e7aaSFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
163af7e7aaSFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
173af7e7aaSFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
183af7e7aaSFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
193af7e7aaSFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
203af7e7aaSFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
213af7e7aaSFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223af7e7aaSFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
233af7e7aaSFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
243af7e7aaSFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
253af7e7aaSFrançois Tigeot */
263af7e7aaSFrançois Tigeot
273af7e7aaSFrançois Tigeot #ifndef _LINUX_PAGEVEC_H_
283af7e7aaSFrançois Tigeot #define _LINUX_PAGEVEC_H_
293af7e7aaSFrançois Tigeot
303af7e7aaSFrançois Tigeot #define PAGEVEC_SIZE 15
313af7e7aaSFrançois Tigeot
323af7e7aaSFrançois Tigeot struct page;
333af7e7aaSFrançois Tigeot
343af7e7aaSFrançois Tigeot struct pagevec {
353af7e7aaSFrançois Tigeot unsigned char nr;
363af7e7aaSFrançois Tigeot bool pv_unused0;
373af7e7aaSFrançois Tigeot struct page *pages[PAGEVEC_SIZE];
383af7e7aaSFrançois Tigeot };
393af7e7aaSFrançois Tigeot
403af7e7aaSFrançois Tigeot static inline void
pagevec_init(struct pagevec * pvec)413af7e7aaSFrançois Tigeot pagevec_init(struct pagevec *pvec)
423af7e7aaSFrançois Tigeot {
433af7e7aaSFrançois Tigeot pvec->nr = 0;
443af7e7aaSFrançois Tigeot }
453af7e7aaSFrançois Tigeot
463af7e7aaSFrançois Tigeot static inline unsigned int
pagevec_count(struct pagevec * pvec)473af7e7aaSFrançois Tigeot pagevec_count(struct pagevec *pvec)
483af7e7aaSFrançois Tigeot {
493af7e7aaSFrançois Tigeot return pvec->nr;
503af7e7aaSFrançois Tigeot }
513af7e7aaSFrançois Tigeot
523af7e7aaSFrançois Tigeot static inline unsigned int
pagevec_add(struct pagevec * pvec,struct page * page)533af7e7aaSFrançois Tigeot pagevec_add(struct pagevec *pvec, struct page *page)
543af7e7aaSFrançois Tigeot {
553af7e7aaSFrançois Tigeot pvec->pages[pvec->nr] = page;
563af7e7aaSFrançois Tigeot pvec->nr++;
573af7e7aaSFrançois Tigeot
583af7e7aaSFrançois Tigeot return (PAGEVEC_SIZE - pvec->nr);
593af7e7aaSFrançois Tigeot }
603af7e7aaSFrançois Tigeot
613af7e7aaSFrançois Tigeot static inline void
__pagevec_release(struct pagevec * pvec)623af7e7aaSFrançois Tigeot __pagevec_release(struct pagevec *pvec)
633af7e7aaSFrançois Tigeot {
643af7e7aaSFrançois Tigeot for (int i = 0; i < pvec->nr; i++)
653af7e7aaSFrançois Tigeot put_page(pvec->pages[i]);
663af7e7aaSFrançois Tigeot
673af7e7aaSFrançois Tigeot pvec->nr = 0;
683af7e7aaSFrançois Tigeot }
693af7e7aaSFrançois Tigeot
70*5bddfc7aSFrançois Tigeot static inline unsigned int
pagevec_space(struct pagevec * pvec)71*5bddfc7aSFrançois Tigeot pagevec_space(struct pagevec *pvec)
72*5bddfc7aSFrançois Tigeot {
73*5bddfc7aSFrançois Tigeot return PAGEVEC_SIZE - pvec->nr;
74*5bddfc7aSFrançois Tigeot }
75*5bddfc7aSFrançois Tigeot
763af7e7aaSFrançois Tigeot #endif /* _LINUX_PAGEVEC_H_ */
77