1ad30f8e7SGabor Kovesdan /* $NetBSD: citrus_mapper_zone.c,v 1.4 2003/07/12 15:39:21 tshiozak Exp $ */
2ad30f8e7SGabor Kovesdan
3ad30f8e7SGabor Kovesdan /*-
4*5e53a4f9SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause
5*5e53a4f9SPedro F. Giffuni *
6ad30f8e7SGabor Kovesdan * Copyright (c)2003 Citrus Project,
7ad30f8e7SGabor Kovesdan * All rights reserved.
8ad30f8e7SGabor Kovesdan *
9ad30f8e7SGabor Kovesdan * Redistribution and use in source and binary forms, with or without
10ad30f8e7SGabor Kovesdan * modification, are permitted provided that the following conditions
11ad30f8e7SGabor Kovesdan * are met:
12ad30f8e7SGabor Kovesdan * 1. Redistributions of source code must retain the above copyright
13ad30f8e7SGabor Kovesdan * notice, this list of conditions and the following disclaimer.
14ad30f8e7SGabor Kovesdan * 2. Redistributions in binary form must reproduce the above copyright
15ad30f8e7SGabor Kovesdan * notice, this list of conditions and the following disclaimer in the
16ad30f8e7SGabor Kovesdan * documentation and/or other materials provided with the distribution.
17ad30f8e7SGabor Kovesdan *
18ad30f8e7SGabor Kovesdan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19ad30f8e7SGabor Kovesdan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20ad30f8e7SGabor Kovesdan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ad30f8e7SGabor Kovesdan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22ad30f8e7SGabor Kovesdan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23ad30f8e7SGabor Kovesdan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24ad30f8e7SGabor Kovesdan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25ad30f8e7SGabor Kovesdan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26ad30f8e7SGabor Kovesdan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27ad30f8e7SGabor Kovesdan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28ad30f8e7SGabor Kovesdan * SUCH DAMAGE.
29ad30f8e7SGabor Kovesdan */
30ad30f8e7SGabor Kovesdan
31ad30f8e7SGabor Kovesdan #include <sys/cdefs.h>
32ad30f8e7SGabor Kovesdan #include <sys/queue.h>
33ad30f8e7SGabor Kovesdan
34ad30f8e7SGabor Kovesdan #include <assert.h>
35ad30f8e7SGabor Kovesdan #include <errno.h>
36ad30f8e7SGabor Kovesdan #include <stdio.h>
37ad30f8e7SGabor Kovesdan #include <stdlib.h>
38ad30f8e7SGabor Kovesdan #include <string.h>
39ad30f8e7SGabor Kovesdan
40ad30f8e7SGabor Kovesdan #include "citrus_namespace.h"
41ad30f8e7SGabor Kovesdan #include "citrus_types.h"
42ad30f8e7SGabor Kovesdan #include "citrus_bcs.h"
43ad30f8e7SGabor Kovesdan #include "citrus_module.h"
44ad30f8e7SGabor Kovesdan #include "citrus_region.h"
45ad30f8e7SGabor Kovesdan #include "citrus_memstream.h"
46ad30f8e7SGabor Kovesdan #include "citrus_mmap.h"
47ad30f8e7SGabor Kovesdan #include "citrus_hash.h"
48ad30f8e7SGabor Kovesdan #include "citrus_mapper.h"
49ad30f8e7SGabor Kovesdan #include "citrus_mapper_zone.h"
50ad30f8e7SGabor Kovesdan
51ad30f8e7SGabor Kovesdan /* ---------------------------------------------------------------------- */
52ad30f8e7SGabor Kovesdan
53ad30f8e7SGabor Kovesdan _CITRUS_MAPPER_DECLS(mapper_zone);
54ad30f8e7SGabor Kovesdan _CITRUS_MAPPER_DEF_OPS(mapper_zone);
55ad30f8e7SGabor Kovesdan
56ad30f8e7SGabor Kovesdan
57ad30f8e7SGabor Kovesdan /* ---------------------------------------------------------------------- */
58ad30f8e7SGabor Kovesdan
59ad30f8e7SGabor Kovesdan struct _zone {
60ad30f8e7SGabor Kovesdan uint32_t z_begin;
61ad30f8e7SGabor Kovesdan uint32_t z_end;
62ad30f8e7SGabor Kovesdan };
63ad30f8e7SGabor Kovesdan
64ad30f8e7SGabor Kovesdan struct _citrus_mapper_zone {
65ad30f8e7SGabor Kovesdan struct _zone mz_col;
66ad30f8e7SGabor Kovesdan struct _zone mz_row;
67ad30f8e7SGabor Kovesdan int32_t mz_col_offset;
68ad30f8e7SGabor Kovesdan int32_t mz_row_offset;
69ad30f8e7SGabor Kovesdan int mz_col_bits;
70ad30f8e7SGabor Kovesdan };
71ad30f8e7SGabor Kovesdan
72ad30f8e7SGabor Kovesdan struct _parse_state {
73ad30f8e7SGabor Kovesdan enum { S_BEGIN, S_OFFSET } ps_state;
74ad30f8e7SGabor Kovesdan union {
75ad30f8e7SGabor Kovesdan uint32_t u_imm;
76ad30f8e7SGabor Kovesdan int32_t s_imm;
77ad30f8e7SGabor Kovesdan struct _zone zone;
78ad30f8e7SGabor Kovesdan } u;
79ad30f8e7SGabor Kovesdan #define ps_u_imm u.u_imm
80ad30f8e7SGabor Kovesdan #define ps_s_imm u.s_imm
81ad30f8e7SGabor Kovesdan #define ps_zone u.zone
82ad30f8e7SGabor Kovesdan int ps_top;
83ad30f8e7SGabor Kovesdan };
84ad30f8e7SGabor Kovesdan
85ad30f8e7SGabor Kovesdan int
_citrus_mapper_zone_mapper_getops(struct _citrus_mapper_ops * ops)86ad30f8e7SGabor Kovesdan _citrus_mapper_zone_mapper_getops(struct _citrus_mapper_ops *ops)
87ad30f8e7SGabor Kovesdan {
88ad30f8e7SGabor Kovesdan
89ad30f8e7SGabor Kovesdan memcpy(ops, &_citrus_mapper_zone_mapper_ops,
90ad30f8e7SGabor Kovesdan sizeof(_citrus_mapper_zone_mapper_ops));
91ad30f8e7SGabor Kovesdan
92ad30f8e7SGabor Kovesdan return (0);
93ad30f8e7SGabor Kovesdan }
94ad30f8e7SGabor Kovesdan
95ad30f8e7SGabor Kovesdan #define BUFSIZE 20
96ad30f8e7SGabor Kovesdan #define T_ERR 0x100
97ad30f8e7SGabor Kovesdan #define T_IMM 0x101
98ad30f8e7SGabor Kovesdan
99ad30f8e7SGabor Kovesdan static int
get_imm(struct _memstream * ms,struct _parse_state * ps)100ad30f8e7SGabor Kovesdan get_imm(struct _memstream *ms, struct _parse_state *ps)
101ad30f8e7SGabor Kovesdan {
102ad30f8e7SGabor Kovesdan int c, i, sign = 0;
103ad30f8e7SGabor Kovesdan char buf[BUFSIZE + 1];
104ad30f8e7SGabor Kovesdan char *p;
105ad30f8e7SGabor Kovesdan
106ad30f8e7SGabor Kovesdan for (i = 0; i < BUFSIZE; i++) {
107ad30f8e7SGabor Kovesdan retry:
108ad30f8e7SGabor Kovesdan c = _memstream_peek(ms);
109ad30f8e7SGabor Kovesdan if (i == 0) {
110ad30f8e7SGabor Kovesdan if (sign == 0 && (c == '+' || c == '-')) {
111ad30f8e7SGabor Kovesdan sign = c;
112ad30f8e7SGabor Kovesdan _memstream_getc(ms);
113ad30f8e7SGabor Kovesdan goto retry;
114ad30f8e7SGabor Kovesdan } else if (!_bcs_isdigit(c))
115ad30f8e7SGabor Kovesdan break;
116ad30f8e7SGabor Kovesdan } else if (!_bcs_isxdigit(c))
117ad30f8e7SGabor Kovesdan if (!(i == 1 && c == 'x'))
118ad30f8e7SGabor Kovesdan break;
119ad30f8e7SGabor Kovesdan buf[i] = _memstream_getc(ms);
120ad30f8e7SGabor Kovesdan }
121ad30f8e7SGabor Kovesdan buf[i] = '\0';
122ad30f8e7SGabor Kovesdan ps->ps_u_imm = strtoul(buf, &p, 0);
123ad30f8e7SGabor Kovesdan if ((p - buf) != i)
124ad30f8e7SGabor Kovesdan return (T_ERR);
125ad30f8e7SGabor Kovesdan if (sign == '-')
126ad30f8e7SGabor Kovesdan ps->ps_u_imm = (unsigned long)-(long)ps->ps_u_imm;
127ad30f8e7SGabor Kovesdan return (T_IMM);
128ad30f8e7SGabor Kovesdan }
129ad30f8e7SGabor Kovesdan
130ad30f8e7SGabor Kovesdan static int
get_tok(struct _memstream * ms,struct _parse_state * ps)131ad30f8e7SGabor Kovesdan get_tok(struct _memstream *ms, struct _parse_state *ps)
132ad30f8e7SGabor Kovesdan {
133ad30f8e7SGabor Kovesdan int c;
134ad30f8e7SGabor Kovesdan
135ad30f8e7SGabor Kovesdan loop:
136ad30f8e7SGabor Kovesdan c = _memstream_peek(ms);
137ad30f8e7SGabor Kovesdan if (c == 0x00)
138ad30f8e7SGabor Kovesdan return (EOF);
139ad30f8e7SGabor Kovesdan if (_bcs_isspace(c)) {
140ad30f8e7SGabor Kovesdan _memstream_getc(ms);
141ad30f8e7SGabor Kovesdan goto loop;
142ad30f8e7SGabor Kovesdan }
143ad30f8e7SGabor Kovesdan
144ad30f8e7SGabor Kovesdan switch (ps->ps_state) {
145ad30f8e7SGabor Kovesdan case S_BEGIN:
146ad30f8e7SGabor Kovesdan switch (c) {
147ad30f8e7SGabor Kovesdan case ':':
148ad30f8e7SGabor Kovesdan case '-':
149ad30f8e7SGabor Kovesdan case '/':
150ad30f8e7SGabor Kovesdan _memstream_getc(ms);
151ad30f8e7SGabor Kovesdan return (c);
152ad30f8e7SGabor Kovesdan case '0':
153ad30f8e7SGabor Kovesdan case '1':
154ad30f8e7SGabor Kovesdan case '2':
155ad30f8e7SGabor Kovesdan case '3':
156ad30f8e7SGabor Kovesdan case '4':
157ad30f8e7SGabor Kovesdan case '5':
158ad30f8e7SGabor Kovesdan case '6':
159ad30f8e7SGabor Kovesdan case '7':
160ad30f8e7SGabor Kovesdan case '8':
161ad30f8e7SGabor Kovesdan case '9':
162ad30f8e7SGabor Kovesdan return (get_imm(ms, ps));
163ad30f8e7SGabor Kovesdan }
164ad30f8e7SGabor Kovesdan break;
165ad30f8e7SGabor Kovesdan case S_OFFSET:
166ad30f8e7SGabor Kovesdan switch (c) {
167ad30f8e7SGabor Kovesdan case '/':
168ad30f8e7SGabor Kovesdan _memstream_getc(ms);
169ad30f8e7SGabor Kovesdan return (c);
170ad30f8e7SGabor Kovesdan case '+':
171ad30f8e7SGabor Kovesdan case '-':
172ad30f8e7SGabor Kovesdan case '0':
173ad30f8e7SGabor Kovesdan case '1':
174ad30f8e7SGabor Kovesdan case '2':
175ad30f8e7SGabor Kovesdan case '3':
176ad30f8e7SGabor Kovesdan case '4':
177ad30f8e7SGabor Kovesdan case '5':
178ad30f8e7SGabor Kovesdan case '6':
179ad30f8e7SGabor Kovesdan case '7':
180ad30f8e7SGabor Kovesdan case '8':
181ad30f8e7SGabor Kovesdan case '9':
182ad30f8e7SGabor Kovesdan return (get_imm(ms, ps));
183ad30f8e7SGabor Kovesdan }
184ad30f8e7SGabor Kovesdan break;
185ad30f8e7SGabor Kovesdan }
186ad30f8e7SGabor Kovesdan return (T_ERR);
187ad30f8e7SGabor Kovesdan }
188ad30f8e7SGabor Kovesdan
189ad30f8e7SGabor Kovesdan static int
parse_zone(struct _memstream * ms,struct _parse_state * ps,struct _zone * z)190ad30f8e7SGabor Kovesdan parse_zone(struct _memstream *ms, struct _parse_state *ps, struct _zone *z)
191ad30f8e7SGabor Kovesdan {
192ad30f8e7SGabor Kovesdan
193ad30f8e7SGabor Kovesdan if (get_tok(ms, ps) != T_IMM)
194ad30f8e7SGabor Kovesdan return (-1);
195ad30f8e7SGabor Kovesdan z->z_begin = ps->ps_u_imm;
196ad30f8e7SGabor Kovesdan if (get_tok(ms, ps) != '-')
197ad30f8e7SGabor Kovesdan return (-1);
198ad30f8e7SGabor Kovesdan if (get_tok(ms, ps) != T_IMM)
199ad30f8e7SGabor Kovesdan return (-1);
200ad30f8e7SGabor Kovesdan z->z_end = ps->ps_u_imm;
201ad30f8e7SGabor Kovesdan
202ad30f8e7SGabor Kovesdan if (z->z_begin > z->z_end)
203ad30f8e7SGabor Kovesdan return (-1);
204ad30f8e7SGabor Kovesdan
205ad30f8e7SGabor Kovesdan return (0);
206ad30f8e7SGabor Kovesdan }
207ad30f8e7SGabor Kovesdan
208ad30f8e7SGabor Kovesdan static int
check_rowcol(struct _zone * z,int32_t ofs,uint32_t maxval)209ad30f8e7SGabor Kovesdan check_rowcol(struct _zone *z, int32_t ofs, uint32_t maxval)
210ad30f8e7SGabor Kovesdan {
211ad30f8e7SGabor Kovesdan uint32_t remain;
212ad30f8e7SGabor Kovesdan
213ad30f8e7SGabor Kovesdan if (maxval != 0 && z->z_end >= maxval)
214ad30f8e7SGabor Kovesdan return (-1);
215ad30f8e7SGabor Kovesdan
216ad30f8e7SGabor Kovesdan if (ofs > 0) {
217ad30f8e7SGabor Kovesdan if (maxval == 0)
218ad30f8e7SGabor Kovesdan /* this should 0x100000000 - z->z_end */
219ad30f8e7SGabor Kovesdan remain = (z->z_end == 0) ? 0xFFFFFFFF :
220ad30f8e7SGabor Kovesdan 0xFFFFFFFF - z->z_end + 1;
221ad30f8e7SGabor Kovesdan else
222ad30f8e7SGabor Kovesdan remain = maxval - z->z_end;
223ad30f8e7SGabor Kovesdan if ((uint32_t)ofs > remain)
224ad30f8e7SGabor Kovesdan return (-1);
225ad30f8e7SGabor Kovesdan } else if (ofs < 0) {
226ad30f8e7SGabor Kovesdan if (z->z_begin < (uint32_t)-ofs)
227ad30f8e7SGabor Kovesdan return (-1);
228ad30f8e7SGabor Kovesdan }
229ad30f8e7SGabor Kovesdan
230ad30f8e7SGabor Kovesdan return (0);
231ad30f8e7SGabor Kovesdan }
232ad30f8e7SGabor Kovesdan
233ad30f8e7SGabor Kovesdan static int
parse_var(struct _citrus_mapper_zone * mz,struct _memstream * ms)234ad30f8e7SGabor Kovesdan parse_var(struct _citrus_mapper_zone *mz, struct _memstream *ms)
235ad30f8e7SGabor Kovesdan {
236ad30f8e7SGabor Kovesdan struct _parse_state ps;
237ad30f8e7SGabor Kovesdan uint32_t colmax, rowmax;
238ad30f8e7SGabor Kovesdan int isrc, ret;
239ad30f8e7SGabor Kovesdan
240ad30f8e7SGabor Kovesdan ps.ps_state = S_BEGIN;
241ad30f8e7SGabor Kovesdan
242ad30f8e7SGabor Kovesdan if (parse_zone(ms, &ps, &mz->mz_col))
243ad30f8e7SGabor Kovesdan return (-1);
244ad30f8e7SGabor Kovesdan
245ad30f8e7SGabor Kovesdan ret = get_tok(ms, &ps);
246ad30f8e7SGabor Kovesdan if (ret == '/') {
247ad30f8e7SGabor Kovesdan /* rowzone / colzone / bits */
248ad30f8e7SGabor Kovesdan isrc = 1;
249ad30f8e7SGabor Kovesdan mz->mz_row = mz->mz_col;
250ad30f8e7SGabor Kovesdan
251ad30f8e7SGabor Kovesdan if (parse_zone(ms, &ps, &mz->mz_col))
252ad30f8e7SGabor Kovesdan return (-1);
253ad30f8e7SGabor Kovesdan if (get_tok(ms, &ps) != '/')
254ad30f8e7SGabor Kovesdan return (-1);
255ad30f8e7SGabor Kovesdan if (get_tok(ms, &ps) != T_IMM)
256ad30f8e7SGabor Kovesdan return (-1);
257ad30f8e7SGabor Kovesdan mz->mz_col_bits = ps.ps_u_imm;
258ad30f8e7SGabor Kovesdan if (mz->mz_col_bits < 0 || mz->mz_col_bits > 32)
259ad30f8e7SGabor Kovesdan return (-1);
260ad30f8e7SGabor Kovesdan ret = get_tok(ms, &ps);
261ad30f8e7SGabor Kovesdan } else {
262ad30f8e7SGabor Kovesdan /* colzone */
263ad30f8e7SGabor Kovesdan isrc = 0;
264ad30f8e7SGabor Kovesdan mz->mz_col_bits = 32;
265ad30f8e7SGabor Kovesdan mz->mz_row.z_begin = mz->mz_row.z_end = 0;
266ad30f8e7SGabor Kovesdan }
267ad30f8e7SGabor Kovesdan if (ret == ':') {
268ad30f8e7SGabor Kovesdan /* offset */
269ad30f8e7SGabor Kovesdan ps.ps_state = S_OFFSET;
270ad30f8e7SGabor Kovesdan if (get_tok(ms, &ps) != T_IMM)
271ad30f8e7SGabor Kovesdan return (-1);
272ad30f8e7SGabor Kovesdan mz->mz_col_offset = ps.ps_s_imm;
273ad30f8e7SGabor Kovesdan if (isrc) {
274ad30f8e7SGabor Kovesdan /* row/col */
275ad30f8e7SGabor Kovesdan mz->mz_row_offset = mz->mz_col_offset;
276ad30f8e7SGabor Kovesdan if (get_tok(ms, &ps) != '/')
277ad30f8e7SGabor Kovesdan return (-1);
278ad30f8e7SGabor Kovesdan if (get_tok(ms, &ps) != T_IMM)
279ad30f8e7SGabor Kovesdan return (-1);
280ad30f8e7SGabor Kovesdan mz->mz_col_offset = ps.ps_s_imm;
281ad30f8e7SGabor Kovesdan } else
282ad30f8e7SGabor Kovesdan mz->mz_row_offset = 0;
283ad30f8e7SGabor Kovesdan ret = get_tok(ms, &ps);
284ad30f8e7SGabor Kovesdan }
285ad30f8e7SGabor Kovesdan if (ret != EOF)
286ad30f8e7SGabor Kovesdan return (-1);
287ad30f8e7SGabor Kovesdan
288ad30f8e7SGabor Kovesdan /* sanity check */
289ad30f8e7SGabor Kovesdan colmax = (mz->mz_col_bits == 32) ? 0 : 1 << mz->mz_col_bits;
290ad30f8e7SGabor Kovesdan rowmax = (mz->mz_col_bits == 0) ? 0 : 1 << (32-mz->mz_col_bits);
291ad30f8e7SGabor Kovesdan if (check_rowcol(&mz->mz_col, mz->mz_col_offset, colmax))
292ad30f8e7SGabor Kovesdan return (-1);
293ad30f8e7SGabor Kovesdan if (check_rowcol(&mz->mz_row, mz->mz_row_offset, rowmax))
294ad30f8e7SGabor Kovesdan return (-1);
295ad30f8e7SGabor Kovesdan
296ad30f8e7SGabor Kovesdan return (0);
297ad30f8e7SGabor Kovesdan }
298ad30f8e7SGabor Kovesdan
299ad30f8e7SGabor Kovesdan static int
300ad30f8e7SGabor Kovesdan /*ARGSUSED*/
_citrus_mapper_zone_mapper_init(struct _citrus_mapper_area * __restrict ma __unused,struct _citrus_mapper * __restrict cm,const char * __restrict dir __unused,const void * __restrict var,size_t lenvar,struct _citrus_mapper_traits * __restrict mt,size_t lenmt)301ad30f8e7SGabor Kovesdan _citrus_mapper_zone_mapper_init(struct _citrus_mapper_area *__restrict ma __unused,
302ad30f8e7SGabor Kovesdan struct _citrus_mapper * __restrict cm, const char * __restrict dir __unused,
303ad30f8e7SGabor Kovesdan const void * __restrict var, size_t lenvar,
304ad30f8e7SGabor Kovesdan struct _citrus_mapper_traits * __restrict mt, size_t lenmt)
305ad30f8e7SGabor Kovesdan {
306ad30f8e7SGabor Kovesdan struct _citrus_mapper_zone *mz;
307ad30f8e7SGabor Kovesdan struct _memstream ms;
308ad30f8e7SGabor Kovesdan struct _region r;
309ad30f8e7SGabor Kovesdan
310ad30f8e7SGabor Kovesdan if (lenmt < sizeof(*mt))
311ad30f8e7SGabor Kovesdan return (EINVAL);
312ad30f8e7SGabor Kovesdan
313ad30f8e7SGabor Kovesdan mz = malloc(sizeof(*mz));
314ad30f8e7SGabor Kovesdan if (mz == NULL)
315ad30f8e7SGabor Kovesdan return (errno);
316ad30f8e7SGabor Kovesdan
317ad30f8e7SGabor Kovesdan mz->mz_col.z_begin = mz->mz_col.z_end = 0;
318ad30f8e7SGabor Kovesdan mz->mz_row.z_begin = mz->mz_row.z_end = 0;
319ad30f8e7SGabor Kovesdan mz->mz_col_bits = 0;
320ad30f8e7SGabor Kovesdan mz->mz_row_offset = 0;
321ad30f8e7SGabor Kovesdan mz->mz_col_offset = 0;
322ad30f8e7SGabor Kovesdan
323ad30f8e7SGabor Kovesdan _region_init(&r, __DECONST(void *, var), lenvar);
324ad30f8e7SGabor Kovesdan _memstream_bind(&ms, &r);
325ad30f8e7SGabor Kovesdan if (parse_var(mz, &ms)) {
326ad30f8e7SGabor Kovesdan free(mz);
327ad30f8e7SGabor Kovesdan return (EINVAL);
328ad30f8e7SGabor Kovesdan }
329ad30f8e7SGabor Kovesdan cm->cm_closure = mz;
330ad30f8e7SGabor Kovesdan mt->mt_src_max = mt->mt_dst_max = 1; /* 1:1 converter */
331ad30f8e7SGabor Kovesdan mt->mt_state_size = 0; /* stateless */
332ad30f8e7SGabor Kovesdan
333ad30f8e7SGabor Kovesdan return (0);
334ad30f8e7SGabor Kovesdan }
335ad30f8e7SGabor Kovesdan
336ad30f8e7SGabor Kovesdan static void
337ad30f8e7SGabor Kovesdan /*ARGSUSED*/
_citrus_mapper_zone_mapper_uninit(struct _citrus_mapper * cm __unused)338ad30f8e7SGabor Kovesdan _citrus_mapper_zone_mapper_uninit(struct _citrus_mapper *cm __unused)
339ad30f8e7SGabor Kovesdan {
340ad30f8e7SGabor Kovesdan
341ad30f8e7SGabor Kovesdan }
342ad30f8e7SGabor Kovesdan
343ad30f8e7SGabor Kovesdan static int
344ad30f8e7SGabor Kovesdan /*ARGSUSED*/
_citrus_mapper_zone_mapper_convert(struct _citrus_mapper * __restrict cm,_citrus_index_t * __restrict dst,_citrus_index_t src,void * __restrict ps __unused)345ad30f8e7SGabor Kovesdan _citrus_mapper_zone_mapper_convert(struct _citrus_mapper * __restrict cm,
346ad30f8e7SGabor Kovesdan _citrus_index_t * __restrict dst, _citrus_index_t src,
347ad30f8e7SGabor Kovesdan void * __restrict ps __unused)
348ad30f8e7SGabor Kovesdan {
349ad30f8e7SGabor Kovesdan struct _citrus_mapper_zone *mz = cm->cm_closure;
350ad30f8e7SGabor Kovesdan uint32_t col, row;
351ad30f8e7SGabor Kovesdan
352ad30f8e7SGabor Kovesdan if (mz->mz_col_bits == 32) {
353ad30f8e7SGabor Kovesdan col = src;
354ad30f8e7SGabor Kovesdan row = 0;
355ad30f8e7SGabor Kovesdan if (col < mz->mz_col.z_begin || col > mz->mz_col.z_end)
356ad30f8e7SGabor Kovesdan return (_CITRUS_MAPPER_CONVERT_NONIDENTICAL);
357ad30f8e7SGabor Kovesdan if (mz->mz_col_offset > 0)
358ad30f8e7SGabor Kovesdan col += (uint32_t)mz->mz_col_offset;
359ad30f8e7SGabor Kovesdan else
360ad30f8e7SGabor Kovesdan col -= (uint32_t)-mz->mz_col_offset;
361ad30f8e7SGabor Kovesdan *dst = col;
362ad30f8e7SGabor Kovesdan } else {
363ad30f8e7SGabor Kovesdan col = src & (((uint32_t)1 << mz->mz_col_bits) - 1);
364ad30f8e7SGabor Kovesdan row = src >> mz->mz_col_bits;
365ad30f8e7SGabor Kovesdan if (row < mz->mz_row.z_begin || row > mz->mz_row.z_end ||
366ad30f8e7SGabor Kovesdan col < mz->mz_col.z_begin || col > mz->mz_col.z_end)
367ad30f8e7SGabor Kovesdan return (_CITRUS_MAPPER_CONVERT_NONIDENTICAL);
368ad30f8e7SGabor Kovesdan if (mz->mz_col_offset > 0)
369ad30f8e7SGabor Kovesdan col += (uint32_t)mz->mz_col_offset;
370ad30f8e7SGabor Kovesdan else
371ad30f8e7SGabor Kovesdan col -= (uint32_t)-mz->mz_col_offset;
372ad30f8e7SGabor Kovesdan if (mz->mz_row_offset > 0)
373ad30f8e7SGabor Kovesdan row += (uint32_t)mz->mz_row_offset;
374ad30f8e7SGabor Kovesdan else
375ad30f8e7SGabor Kovesdan row -= (uint32_t)-mz->mz_row_offset;
376ad30f8e7SGabor Kovesdan *dst = col | (row << mz->mz_col_bits);
377ad30f8e7SGabor Kovesdan }
378ad30f8e7SGabor Kovesdan return (_CITRUS_MAPPER_CONVERT_SUCCESS);
379ad30f8e7SGabor Kovesdan }
380ad30f8e7SGabor Kovesdan
381ad30f8e7SGabor Kovesdan static void
382ad30f8e7SGabor Kovesdan /*ARGSUSED*/
_citrus_mapper_zone_mapper_init_state(void)383ad30f8e7SGabor Kovesdan _citrus_mapper_zone_mapper_init_state(void)
384ad30f8e7SGabor Kovesdan {
385ad30f8e7SGabor Kovesdan
386ad30f8e7SGabor Kovesdan }
387