1/*- 2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
| 1/*- 2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
|
26 * $FreeBSD: head/sys/boot/ofw/libofw/ofw_copy.c 84620 2001-10-07 13:27:27Z benno $
| 26 * $FreeBSD: head/sys/boot/ofw/libofw/ofw_copy.c 100318 2002-07-18 12:39:02Z benno $
|
27 */ 28/* 29 * MD primitives supporting placement of module data 30 * 31 * XXX should check load address/size against memory top. 32 */ 33#include <stand.h> 34 35#include "libofw.h" 36 37#define READIN_BUF (4 * 1024)
| 27 */ 28/* 29 * MD primitives supporting placement of module data 30 * 31 * XXX should check load address/size against memory top. 32 */ 33#include <stand.h> 34 35#include "libofw.h" 36 37#define READIN_BUF (4 * 1024)
|
| 38#define PAGE_SIZE 0x1000 39#define PAGE_MASK 0x0fff
|
38
| 40
|
| 41#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 42
|
39ssize_t 40ofw_copyin(const void *src, vm_offset_t dest, const size_t len) 41{
| 43ssize_t 44ofw_copyin(const void *src, vm_offset_t dest, const size_t len) 45{
|
| 46 void *destp, *addr; 47 size_t dlen; 48 49 destp = (void *)(dest & ~PAGE_MASK); 50 dlen = roundup(len, PAGE_SIZE); 51 52 if (OF_call_method("claim", memory, 3, 1, destp, dlen, 0, &addr) 53 == -1) { 54 printf("ofw_copyin: physical claim failed\n"); 55 return (0); 56 } 57 58 if (OF_call_method("claim", mmu, 3, 1, destp, dlen, 0, &addr) == -1) { 59 printf("ofw_copyin: virtual claim failed\n"); 60 return (0); 61 } 62 63 if (OF_call_method("map", mmu, 4, 0, destp, destp, dlen, 0) == -1) { 64 printf("ofw_copyin: map failed\n"); 65 return (0); 66 } 67
|
42 bcopy(src, (void *)dest, len); 43 return(len); 44} 45 46ssize_t 47ofw_copyout(const vm_offset_t src, void *dest, const size_t len) 48{ 49 bcopy((void *)src, dest, len); 50 return(len); 51} 52 53ssize_t 54ofw_readin(const int fd, vm_offset_t dest, const size_t len) 55{ 56 void *buf; 57 size_t resid, chunk, get; 58 ssize_t got; 59 vm_offset_t p; 60 61 p = dest; 62 63 chunk = min(READIN_BUF, len); 64 buf = malloc(chunk); 65 if (buf == NULL) { 66 printf("ofw_readin: buf malloc failed\n"); 67 return(0); 68 } 69 70 for (resid = len; resid > 0; resid -= got, p += got) { 71 get = min(chunk, resid); 72 got = read(fd, buf, get); 73 74 if (got <= 0) { 75 printf("ofw_readin: read failed\n"); 76 break; 77 } 78
| 68 bcopy(src, (void *)dest, len); 69 return(len); 70} 71 72ssize_t 73ofw_copyout(const vm_offset_t src, void *dest, const size_t len) 74{ 75 bcopy((void *)src, dest, len); 76 return(len); 77} 78 79ssize_t 80ofw_readin(const int fd, vm_offset_t dest, const size_t len) 81{ 82 void *buf; 83 size_t resid, chunk, get; 84 ssize_t got; 85 vm_offset_t p; 86 87 p = dest; 88 89 chunk = min(READIN_BUF, len); 90 buf = malloc(chunk); 91 if (buf == NULL) { 92 printf("ofw_readin: buf malloc failed\n"); 93 return(0); 94 } 95 96 for (resid = len; resid > 0; resid -= got, p += got) { 97 get = min(chunk, resid); 98 got = read(fd, buf, get); 99 100 if (got <= 0) { 101 printf("ofw_readin: read failed\n"); 102 break; 103 } 104
|
79 bcopy(buf, (void *)p, got);
| 105 ofw_copyin(buf, p, got);
|
80 } 81 82 free(buf); 83 return(len - resid); 84}
| 106 } 107 108 free(buf); 109 return(len - resid); 110}
|