ofw_copy.c (84620) | ofw_copy.c (100318) |
---|---|
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 unchanged lines hidden (view full) --- 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 unchanged lines hidden (view full) --- 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); --- 21 unchanged lines hidden (view full) --- 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); --- 21 unchanged lines hidden (view full) --- 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} |