1/*-
2 * Copyright (c) 2013, 2014 Antti Kantee.  All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
14 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <hw/types.h>
27#include <hw/kernel.h>
28
29#include <bmk-core/pgalloc.h>
30
31#include <bmk-pcpu/pcpu.h>
32
33#include <bmk-rumpuser/core_types.h>
34
35#include "pci_user.h"
36
37int
38rumpcomp_pci_dmalloc(size_t size, size_t align,
39	unsigned long *pap, unsigned long *vap)
40{
41	void *mem;
42	int i;
43
44        for (i = 0; size >> (i + BMK_PCPU_PAGE_SHIFT); i++)
45                continue;
46	if (align < BMK_PCPU_PAGE_SIZE)
47		align = BMK_PCPU_PAGE_SIZE;
48
49	mem = bmk_pgalloc_align(i, align);
50	if (!mem)
51		return BMK_ENOMEM;
52
53	*pap = (unsigned long)mem;
54	*vap = (unsigned long)mem;
55
56	return 0;
57}
58
59int
60rumpcomp_pci_dmamem_map(struct rumpcomp_pci_dmaseg *dss, size_t nseg,
61	size_t totlen, void **vap)
62{
63
64	if (nseg > 1)
65		return 1;
66
67	*vap = (void *)dss[0].ds_vacookie;
68	return 0;
69}
70
71void
72rumpcomp_pci_dmafree(unsigned long mem, size_t size)
73{
74	int i;
75
76        for (i = 0; size >> (i + BMK_PCPU_PAGE_SHIFT); i++)
77                continue;
78	bmk_pgfree((void *)mem, i);
79}
80
81unsigned long
82rumpcomp_pci_virt_to_mach(void *virt)
83{
84
85	return (unsigned long)virt;
86}
87