Mon Apr 9 22:26:16 2018 UTC ()
Fix encoding of MMAP flags for generic_bs_mmap


(jmcneill)
diff -r1.2 -r1.3 src/sys/arch/aarch64/aarch64/bus_space.c
diff -r1.2 -r1.3 src/sys/arch/aarch64/include/pmap.h

cvs diff -r1.2 -r1.3 src/sys/arch/aarch64/aarch64/bus_space.c (expand / switch to unified diff)

--- src/sys/arch/aarch64/aarch64/bus_space.c 2018/04/01 04:35:03 1.2
+++ src/sys/arch/aarch64/aarch64/bus_space.c 2018/04/09 22:26:15 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bus_space.c,v 1.2 2018/04/01 04:35:03 ryo Exp $ */ 1/* $NetBSD: bus_space.c,v 1.3 2018/04/09 22:26:15 jmcneill Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org> 4 * Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(1, "$NetBSD: bus_space.c,v 1.2 2018/04/01 04:35:03 ryo Exp $"); 30__KERNEL_RCSID(1, "$NetBSD: bus_space.c,v 1.3 2018/04/09 22:26:15 jmcneill Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/systm.h> 33#include <sys/systm.h>
34#include <sys/bus.h> 34#include <sys/bus.h>
35 35
36#include <uvm/uvm_extern.h> 36#include <uvm/uvm_extern.h>
37 37
38#include <aarch64/bus_funcs.h> 38#include <aarch64/bus_funcs.h>
39#include <aarch64/machdep.h> 39#include <aarch64/machdep.h>
40 40
41 41
42/* Prototypes for all the bus_space structure functions */ 42/* Prototypes for all the bus_space structure functions */
43bs_protos(generic) 43bs_protos(generic)
@@ -605,28 +605,32 @@ generic_bs_barrier(void *t, bus_space_ha @@ -605,28 +605,32 @@ generic_bs_barrier(void *t, bus_space_ha
605} 605}
606 606
607void * 607void *
608generic_bs_vaddr(void *t, bus_space_handle_t bsh) 608generic_bs_vaddr(void *t, bus_space_handle_t bsh)
609{ 609{
610 return (void *)bsh; 610 return (void *)bsh;
611} 611}
612 612
613paddr_t 613paddr_t
614generic_bs_mmap(void *t, bus_addr_t bpa, off_t offset, int prot, int flags) 614generic_bs_mmap(void *t, bus_addr_t bpa, off_t offset, int prot, int flags)
615{ 615{
616 paddr_t bus_flags = 0; 616 paddr_t bus_flags = 0;
617 617
618 if ((flags & (BUS_SPACE_MAP_CACHEABLE|BUS_SPACE_MAP_PREFETCHABLE)) != 0) 618 if ((flags & BUS_SPACE_MAP_CACHEABLE) != 0)
619 bus_flags |= AARCH64_MMAP_WRITEBACK; 619 bus_flags |= (AARCH64_MMAP_WRITEBACK << AARCH64_MMAP_FLAG_SHIFT);
 620 else if ((flags & BUS_SPACE_MAP_PREFETCHABLE) != 0)
 621 bus_flags |= (AARCH64_MMAP_WRITECOMBINE << AARCH64_MMAP_FLAG_SHIFT);
 622 else
 623 bus_flags |= (AARCH64_MMAP_DEVICE << AARCH64_MMAP_FLAG_SHIFT);
620 624
621 return (atop(bpa + (offset << ((struct bus_space *)t)->bs_stride)) | 625 return (atop(bpa + (offset << ((struct bus_space *)t)->bs_stride)) |
622 bus_flags); 626 bus_flags);
623} 627}
624 628
625int 629int
626generic_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, 630generic_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
627 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags, 631 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
628 bus_addr_t *bpap, bus_space_handle_t *bshp) 632 bus_addr_t *bpap, bus_space_handle_t *bshp)
629{ 633{
630 panic("%s(): not implemented\n", __func__); 634 panic("%s(): not implemented\n", __func__);
631} 635}
632 636

cvs diff -r1.2 -r1.3 src/sys/arch/aarch64/include/pmap.h (expand / switch to unified diff)

--- src/sys/arch/aarch64/include/pmap.h 2018/04/01 04:35:03 1.2
+++ src/sys/arch/aarch64/include/pmap.h 2018/04/09 22:26:16 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.h,v 1.2 2018/04/01 04:35:03 ryo Exp $ */ 1/* $NetBSD: pmap.h,v 1.3 2018/04/09 22:26:16 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry. 8 * by Matt Thomas of 3am Software Foundry.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -140,30 +140,30 @@ paddr_t pmap_devmap_vtophys(paddr_t); @@ -140,30 +140,30 @@ paddr_t pmap_devmap_vtophys(paddr_t);
140#define DEVMAP_ENTRY(va, pa, sz) \ 140#define DEVMAP_ENTRY(va, pa, sz) \
141 { \ 141 { \
142 .pd_va = DEVMAP_TRUNC_ADDR(va), \ 142 .pd_va = DEVMAP_TRUNC_ADDR(va), \
143 .pd_pa = DEVMAP_TRUNC_ADDR(pa), \ 143 .pd_pa = DEVMAP_TRUNC_ADDR(pa), \
144 .pd_size = DEVMAP_ROUND_SIZE(sz), \ 144 .pd_size = DEVMAP_ROUND_SIZE(sz), \
145 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, \ 145 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, \
146 .pd_flags = PMAP_NOCACHE \ 146 .pd_flags = PMAP_NOCACHE \
147 } 147 }
148#define DEVMAP_ENTRY_END { 0 } 148#define DEVMAP_ENTRY_END { 0 }
149 149
150/* mmap cookie and flags */ 150/* mmap cookie and flags */
151#define AARCH64_MMAP_FLAG_SHIFT (64 - PGSHIFT) 151#define AARCH64_MMAP_FLAG_SHIFT (64 - PGSHIFT)
152#define AARCH64_MMAP_FLAG_MASK 0xf 152#define AARCH64_MMAP_FLAG_MASK 0xf
153#define AARCH64_MMAP_WRITEBACK 0 153#define AARCH64_MMAP_WRITEBACK 0UL
154#define AARCH64_MMAP_NOCACHE 1 154#define AARCH64_MMAP_NOCACHE 1UL
155#define AARCH64_MMAP_WRITECOMBINE 2 155#define AARCH64_MMAP_WRITECOMBINE 2UL
156#define AARCH64_MMAP_DEVICE 3 156#define AARCH64_MMAP_DEVICE 3UL
157 157
158#define ARM_MMAP_WRITECOMBINE AARCH64_MMAP_WRITECOMBINE 158#define ARM_MMAP_WRITECOMBINE AARCH64_MMAP_WRITECOMBINE
159#define ARM_MMAP_WRITEBACK AARCH64_MMAP_WRITEBACK 159#define ARM_MMAP_WRITEBACK AARCH64_MMAP_WRITEBACK
160#define ARM_MMAP_NOCACHE AARCH64_MMAP_NOCACHE 160#define ARM_MMAP_NOCACHE AARCH64_MMAP_NOCACHE
161#define ARM_MMAP_DEVICE AARCH64_MMAP_DEVICE 161#define ARM_MMAP_DEVICE AARCH64_MMAP_DEVICE
162 162
163#define PMAP_PTE 0x10000000 /* kenter_pa */ 163#define PMAP_PTE 0x10000000 /* kenter_pa */
164#define PMAP_DEV 0x20000000 /* kenter_pa */ 164#define PMAP_DEV 0x20000000 /* kenter_pa */
165 165
166static inline u_int 166static inline u_int
167aarch64_mmap_flags(paddr_t mdpgno) 167aarch64_mmap_flags(paddr_t mdpgno)
168{ 168{
169 u_int nflag, pflag; 169 u_int nflag, pflag;