summaryrefslogtreecommitdiffstats
path: root/sys/boot/powerpc
diff options
context:
space:
mode:
authornwhitehorn <nwhitehorn@FreeBSD.org>2011-07-16 19:01:09 +0000
committernwhitehorn <nwhitehorn@FreeBSD.org>2011-07-16 19:01:09 +0000
commit1cbd4038aac28f6e17a854f68068d524a5e7eba2 (patch)
tree9b45755eeb9f61b8653c919479b8b3edc44d4e06 /sys/boot/powerpc
parente9e63eab3cc5ac56470f75d279a788df7e047ffd (diff)
downloadFreeBSD-src-1cbd4038aac28f6e17a854f68068d524a5e7eba2.zip
FreeBSD-src-1cbd4038aac28f6e17a854f68068d524a5e7eba2.tar.gz
Add support for booting PS3s from disk. This is still a little hackish until
we can find a way to get the information from petitboot or to guess it, so the current algorithm is: 1. See if ps3disk3p1 (first GPT slice on OtherOS partition) exists, and if so try to boot it. 2. Otherwise, netboot. Submitted by: glevand <geoffrey.levand at mail dot ru >
Diffstat (limited to 'sys/boot/powerpc')
-rw-r--r--sys/boot/powerpc/ps3/Makefile4
-rw-r--r--sys/boot/powerpc/ps3/conf.c6
-rw-r--r--sys/boot/powerpc/ps3/devicename.c20
-rw-r--r--sys/boot/powerpc/ps3/lv1call.S98
-rw-r--r--sys/boot/powerpc/ps3/lv1call.h8
-rw-r--r--sys/boot/powerpc/ps3/main.c46
-rw-r--r--sys/boot/powerpc/ps3/ps3bus.h41
-rw-r--r--sys/boot/powerpc/ps3/ps3devdesc.h53
-rw-r--r--sys/boot/powerpc/ps3/ps3disk.c313
-rw-r--r--sys/boot/powerpc/ps3/ps3repo.c249
-rw-r--r--sys/boot/powerpc/ps3/ps3repo.h51
-rw-r--r--sys/boot/powerpc/ps3/ps3stor.c165
-rw-r--r--sys/boot/powerpc/ps3/ps3stor.h59
-rw-r--r--sys/boot/powerpc/ps3/version2
14 files changed, 1092 insertions, 23 deletions
diff --git a/sys/boot/powerpc/ps3/Makefile b/sys/boot/powerpc/ps3/Makefile
index b05470b..0f0b782 100644
--- a/sys/boot/powerpc/ps3/Makefile
+++ b/sys/boot/powerpc/ps3/Makefile
@@ -10,13 +10,13 @@ INSTALLFLAGS= -b
# Architecture-specific loader code
SRCS= start.S conf.c metadata.c vers.c main.c devicename.c ppc64_elf_freebsd.c
-SRCS+= lv1call.S ps3cons.c font.h ps3mmu.c ps3net.c
+SRCS+= lv1call.S ps3cons.c font.h ps3mmu.c ps3net.c ps3repo.c ps3stor.c ps3disk.c
SRCS+= ucmpdi2.c
LOADER_DISK_SUPPORT?= yes
LOADER_UFS_SUPPORT?= yes
LOADER_CD9660_SUPPORT?= yes
-LOADER_EXT2FS_SUPPORT?= no
+LOADER_EXT2FS_SUPPORT?= yes
LOADER_NET_SUPPORT?= yes
LOADER_NFS_SUPPORT?= yes
LOADER_TFTP_SUPPORT?= no
diff --git a/sys/boot/powerpc/ps3/conf.c b/sys/boot/powerpc/ps3/conf.c
index 7749a15..200fc7f 100644
--- a/sys/boot/powerpc/ps3/conf.c
+++ b/sys/boot/powerpc/ps3/conf.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
+ * Copyright (C) 1999 Michael Smith <msmith@freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,6 +34,8 @@ __FBSDID("$FreeBSD$");
#include "dev_net.h"
#endif
+extern struct devsw ps3disk;
+
/*
* We could use linker sets for some or all of these, but
* then we would have to control what ended up linked into
@@ -46,10 +48,8 @@ __FBSDID("$FreeBSD$");
/* Exported for libstand */
struct devsw *devsw[] = {
#if defined(LOADER_DISK_SUPPORT) || defined(LOADER_CD9660_SUPPORT)
-#ifdef NOTYET
&ps3disk,
#endif
-#endif
#if defined(LOADER_NET_SUPPORT)
&netdev,
#endif
diff --git a/sys/boot/powerpc/ps3/devicename.c b/sys/boot/powerpc/ps3/devicename.c
index b652d9b..c46bc89 100644
--- a/sys/boot/powerpc/ps3/devicename.c
+++ b/sys/boot/powerpc/ps3/devicename.c
@@ -33,8 +33,10 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include "bootstrap.h"
+#include "ps3.h"
+#include "ps3devdesc.h"
-static int ps3_parsedev(struct devdesc **dev, const char *devspec,
+static int ps3_parsedev(struct ps3_devdesc **dev, const char *devspec,
const char **path);
/*
@@ -45,7 +47,7 @@ static int ps3_parsedev(struct devdesc **dev, const char *devspec,
int
ps3_getdev(void **vdev, const char *devspec, const char **path)
{
- struct devdesc **dev = (struct devdesc **)vdev;
+ struct ps3_devdesc **dev = (struct ps3_devdesc **)vdev;
int rv = 0;
/*
@@ -82,9 +84,9 @@ ps3_getdev(void **vdev, const char *devspec, const char **path)
*
*/
static int
-ps3_parsedev(struct devdesc **dev, const char *devspec, const char **path)
+ps3_parsedev(struct ps3_devdesc **dev, const char *devspec, const char **path)
{
- struct devdesc *idev;
+ struct ps3_devdesc *idev;
struct devsw *dv;
char *cp;
const char *np;
@@ -104,7 +106,7 @@ ps3_parsedev(struct devdesc **dev, const char *devspec, const char **path)
}
if (dv == NULL)
return(ENOENT);
- idev = malloc(sizeof(struct devdesc));
+ idev = malloc(sizeof(struct ps3_devdesc));
err = 0;
np = (devspec + strlen(dv->dv_name));
@@ -112,7 +114,6 @@ ps3_parsedev(struct devdesc **dev, const char *devspec, const char **path)
case DEVT_NONE:
break;
-#ifdef NOTYET
case DEVT_DISK:
unit = -1;
pnum = -1;
@@ -154,7 +155,6 @@ ps3_parsedev(struct devdesc **dev, const char *devspec, const char **path)
if (path != NULL)
*path = (*cp == 0) ? cp : cp + 1;
break;
-#endif
case DEVT_NET:
/*
@@ -188,7 +188,7 @@ fail:
char *
ps3_fmtdev(void *vdev)
{
- struct devdesc *dev = (struct devdesc *)vdev;
+ struct ps3_devdesc *dev = (struct ps3_devdesc *)vdev;
char *cp;
static char buf[128];
@@ -197,7 +197,6 @@ ps3_fmtdev(void *vdev)
strcpy(buf, "(no device)");
break;
-#ifdef NOTYET
case DEVT_DISK:
cp = buf;
cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_unit);
@@ -212,7 +211,6 @@ ps3_fmtdev(void *vdev)
strcat(cp, ":");
break;
-#endif
case DEVT_NET:
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
@@ -227,7 +225,7 @@ ps3_fmtdev(void *vdev)
int
ps3_setcurrdev(struct env_var *ev, int flags, const void *value)
{
- struct devdesc *ncurr;
+ struct ps3_devdesc *ncurr;
int rv;
if ((rv = ps3_parsedev(&ncurr, value, NULL)) != 0)
diff --git a/sys/boot/powerpc/ps3/lv1call.S b/sys/boot/powerpc/ps3/lv1call.S
index a5dafdd..1c1e28e 100644
--- a/sys/boot/powerpc/ps3/lv1call.S
+++ b/sys/boot/powerpc/ps3/lv1call.S
@@ -1,5 +1,6 @@
/*-
* Copyright (C) 2010 Nathan Whitehorn
+ * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -163,7 +164,7 @@ lv1_gpu_context_allocate:
sldi %r3,%r3,32
clrldi %r4,%r4,32
- ori %r3,%r3,%r4
+ or %r3,%r3,%r4
clrldi %r4,%r5,32
clrldi %r5,%r6,32
@@ -254,3 +255,98 @@ lv1_setup_dma:
mtlr %r0
blr
+.global lv1_get_repository_node_value
+lv1_get_repository_node_value:
+ mflr %r0
+ stw %r0,4(%r1)
+
+ sldi %r3,%r3,32
+ clrldi %r4,%r4,32
+ or %r3,%r3,%r4
+ sldi %r4,%r5,32
+ clrldi %r5,%r6,32
+ or %r4,%r4,%r5
+ sldi %r5,%r7,32
+ clrldi %r6,%r8,32
+ or %r5,%r5,%r6
+ sldi %r6,%r9,32
+ clrldi %r7,%r10,32
+ or %r6,%r6,%r7
+ lwz %r7,8(%r1)
+ lwz %r8,12(%r1)
+ sldi %r7,%r7,32
+ or %r7,%r7,%r8
+
+ li %r11,91
+ hc
+ extsw %r3,%r3
+
+ lwz %r6,16(%r1)
+ std %r4,0(%r6)
+ lwz %r6,20(%r1)
+ std %r5,0(%r6)
+
+ lwz %r0,4(%r1)
+ mtlr %r0
+ blr
+
+.global lv1_storage_read
+lv1_storage_read:
+ mflr %r0
+ stw %r0,4(%r1)
+
+ sldi %r3,%r3,32
+ clrldi %r4,%r4,32
+ or %r3,%r3,%r4
+ sldi %r4,%r5,32
+ clrldi %r5,%r6,32
+ or %r4,%r4,%r5
+ sldi %r5,%r7,32
+ clrldi %r6,%r8,32
+ or %r5,%r5,%r6
+ sldi %r6,%r9,32
+ clrldi %r7,%r10,32
+ or %r6,%r6,%r7
+ lwz %r7,8(%r1)
+ lwz %r8,12(%r1)
+ sldi %r7,%r7,32
+ or %r7,%r7,%r8
+ lwz %r8,16(%r1)
+ lwz %r9,20(%r1)
+ sldi %r8,%r8,32
+ or %r8,%r8,%r9
+
+ li %r11,245
+ hc
+ extsw %r3,%r3
+
+ lwz %r5,24(%r1)
+ std %r4,0(%r5)
+
+ lwz %r0,4(%r1)
+ mtlr %r0
+ blr
+
+.global lv1_storage_check_async_status
+lv1_storage_check_async_status:
+ mflr %r0
+ stw %r0,4(%r1)
+ stw %r7,-4(%r1)
+
+ sldi %r3,%r3,32
+ clrldi %r4,%r4,32
+ or %r3,%r3,%r4
+ sldi %r4,%r5,32
+ clrldi %r5,%r6,32
+ or %r4,%r4,%r5
+
+ li %r11,254
+ hc
+ extsw %r3,%r3
+
+ lwz %r5,-4(%r1)
+ std %r4,0(%r5)
+
+ lwz %r0,4(%r1)
+ mtlr %r0
+ blr
diff --git a/sys/boot/powerpc/ps3/lv1call.h b/sys/boot/powerpc/ps3/lv1call.h
index 26e6e14..da47afb 100644
--- a/sys/boot/powerpc/ps3/lv1call.h
+++ b/sys/boot/powerpc/ps3/lv1call.h
@@ -68,5 +68,13 @@ int lv1_net_start_rx_dma(int bus, int dev, uint32_t addr, int);
int lv1_net_stop_tx_dma(int bus, int dev, int);
int lv1_net_stop_rx_dma(int bus, int dev, int);
+int lv1_get_repository_node_value(uint64_t lpar_id, uint64_t n1, uint64_t n2,
+ uint64_t n3, uint64_t n4, uint64_t *v1, uint64_t *v2);
+
+int lv1_storage_read(uint64_t dev_id, uint64_t region_id,
+ uint64_t start_sector, uint64_t sector_count,
+ uint64_t flags, uint64_t buf, uint64_t *tag);
+int lv1_storage_check_async_status(uint64_t dev_id, uint64_t tag, uint64_t *status);
+
#endif
diff --git a/sys/boot/powerpc/ps3/main.c b/sys/boot/powerpc/ps3/main.c
index 22c51fa..db808ad 100644
--- a/sys/boot/powerpc/ps3/main.c
+++ b/sys/boot/powerpc/ps3/main.c
@@ -1,5 +1,6 @@
/*-
* Copyright (C) 2010 Nathan Whitehorn
+ * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -35,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include "bootstrap.h"
#include "lv1call.h"
#include "ps3.h"
+#include "ps3devdesc.h"
struct arch_switch archsw;
extern void *_end;
@@ -58,7 +60,9 @@ main(void)
{
uint64_t maxmem = 0;
void *heapbase;
- int i;
+ int i, err;
+ struct ps3_devdesc currdev;
+ struct open_file f;
lv1_get_physmem(&maxmem);
@@ -78,9 +82,37 @@ main(void)
/*
* March through the device switch probing for things.
*/
- for (i = 0; devsw[i] != NULL; i++)
- if (devsw[i]->dv_init != NULL)
- (devsw[i]->dv_init)();
+ for (i = 0; devsw[i] != NULL; i++) {
+ if (devsw[i]->dv_init != NULL) {
+ err = (devsw[i]->dv_init)();
+ if (err) {
+ printf("\n%s: initialization failed err=%d\n",
+ devsw[i]->dv_name, err);
+ continue;
+ }
+ }
+
+ printf("\nDevice: %s\n", devsw[i]->dv_name);
+
+ currdev.d_dev = devsw[i];
+ currdev.d_type = currdev.d_dev->dv_type;
+
+ if (strcmp(devsw[i]->dv_name, "disk") == 0) {
+ f.f_devdata = &currdev;
+ currdev.d_unit = 3;
+ currdev.d_disk.pnum = 1;
+ currdev.d_disk.ptype = PTYPE_GPT;
+
+ if (devsw[i]->dv_open(&f, &currdev) == 0)
+ break;
+ }
+
+ if (strcmp(devsw[i]->dv_name, "net") == 0)
+ break;
+ }
+
+ if (devsw[i] == NULL)
+ panic("No boot device found!");
/*
* Get timebase at boot.
@@ -98,8 +130,10 @@ main(void)
printf("(%s, %s)\n", bootprog_maker, bootprog_date);
printf("Memory: %lldKB\n", maxmem / 1024);
- env_setenv("currdev", EV_VOLATILE, "net", ps3_setcurrdev, env_nounset);
- env_setenv("loaddev", EV_VOLATILE, "net", env_noset, env_nounset);
+ env_setenv("currdev", EV_VOLATILE, ps3_fmtdev(&currdev),
+ ps3_setcurrdev, env_nounset);
+ env_setenv("loaddev", EV_VOLATILE, ps3_fmtdev(&currdev), env_noset,
+ env_nounset);
setenv("LINES", "24", 1);
setenv("hw.platform", "ps3", 1);
diff --git a/sys/boot/powerpc/ps3/ps3bus.h b/sys/boot/powerpc/ps3/ps3bus.h
new file mode 100644
index 0000000..a3b20f3
--- /dev/null
+++ b/sys/boot/powerpc/ps3/ps3bus.h
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _PS3_BUS_H
+#define _PS3_BUS_H
+
+enum {
+ PS3_BUS_TYPE_STOR = 5,
+};
+
+enum {
+ PS3_DEV_TYPE_STOR_DISK = 0,
+ PS3_DEV_TYPE_STOR_CDROM = 5,
+ PS3_DEV_TYPE_STOR_FLASH = 14,
+};
+
+#endif
diff --git a/sys/boot/powerpc/ps3/ps3devdesc.h b/sys/boot/powerpc/ps3/ps3devdesc.h
new file mode 100644
index 0000000..5a6e52f
--- /dev/null
+++ b/sys/boot/powerpc/ps3/ps3devdesc.h
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (C) 2000 Benno Rice.
+ * Copyright (C) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com>
+ * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _PS3_DEV_DESC_H
+#define _PS3_DEV_DESC_H
+
+/* Note: Must match the 'struct devdesc' in bootstrap.h */
+struct ps3_devdesc {
+ struct devsw *d_dev;
+ int d_type;
+ int d_unit;
+
+ union {
+ struct {
+ void *data;
+ int pnum;
+ int ptype;
+ } disk;
+ } d_kind;
+};
+
+#define d_disk d_kind.disk
+
+#define PTYPE_BSDLABEL 1
+#define PTYPE_GPT 2
+
+#endif
diff --git a/sys/boot/powerpc/ps3/ps3disk.c b/sys/boot/powerpc/ps3/ps3disk.c
new file mode 100644
index 0000000..5c5195b
--- /dev/null
+++ b/sys/boot/powerpc/ps3/ps3disk.c
@@ -0,0 +1,313 @@
+/*-
+ * Copyright (C) 2008 Semihalf, Rafal Jaworowski
+ * Copyright (C) 2009 Semihalf, Piotr Ziecik
+ * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/endian.h>
+#include <machine/stdarg.h>
+#include <stand.h>
+#include <uuid.h>
+
+#define FSTYPENAMES
+#include <sys/disklabel.h>
+#include <sys/diskmbr.h>
+#include <sys/gpt.h>
+
+#include "bootstrap.h"
+#include "ps3bus.h"
+#include "ps3devdesc.h"
+#include "ps3stor.h"
+
+#define dev_printf(dev, fmt, args...) \
+ printf("%s%d: " fmt "\n" , dev->d_dev->dv_name, dev->d_unit, ##args)
+
+#ifdef DISK_DEBUG
+#define DEBUG(fmt, args...) printf("%s:%d: " fmt "\n" , __func__ , __LINE__, ##args)
+#else
+#define DEBUG(fmt, args...)
+#endif
+
+struct open_dev;
+
+static int ps3disk_open_gpt(struct ps3_devdesc *dev, struct open_dev *od);
+static void ps3disk_uuid_letoh(uuid_t *uuid);
+
+static int ps3disk_init(void);
+static int ps3disk_strategy(void *devdata, int flag, daddr_t dblk,
+ size_t size, char *buf, size_t *rsize);
+static int ps3disk_open(struct open_file *f, ...);
+static int ps3disk_close(struct open_file *f);
+static void ps3disk_print(int verbose);
+
+struct devsw ps3disk = {
+ "disk",
+ DEVT_DISK,
+ ps3disk_init,
+ ps3disk_strategy,
+ ps3disk_open,
+ ps3disk_close,
+ noioctl,
+ ps3disk_print,
+};
+
+struct gpt_part {
+ int gp_index;
+ uuid_t gp_type;
+ uint64_t gp_start;
+ uint64_t gp_end;
+};
+
+struct open_dev {
+ uint64_t od_start;
+
+ union {
+ struct {
+ int nparts;
+ struct gpt_part *parts;
+ } gpt;
+ } od_kind;
+};
+
+#define od_gpt_nparts od_kind.gpt.nparts
+#define od_gpt_parts od_kind.gpt.parts
+
+static struct ps3_stordev stor_dev;
+
+static int ps3disk_init(void)
+{
+ int err;
+
+ err = ps3stor_setup(&stor_dev, PS3_DEV_TYPE_STOR_DISK);
+ if (err)
+ return err;
+
+ return 0;
+}
+
+static int ps3disk_strategy(void *devdata, int flag, daddr_t dblk,
+ size_t size, char *buf, size_t *rsize)
+{
+ struct ps3_devdesc *dev = (struct ps3_devdesc *) devdata;
+ struct open_dev *od = (struct open_dev *) dev->d_disk.data;
+ int err;
+
+ if (flag != F_READ) {
+ dev_printf(dev, "write operation is not supported!\n");
+ return EROFS;
+ }
+
+ if (size % stor_dev.sd_blksize) {
+ dev_printf(dev, "size=%u is not multiple of device block size=%llu\n",
+ size, stor_dev.sd_blksize);
+ return EIO;
+ }
+
+ if (rsize)
+ *rsize = 0;
+
+ err = ps3stor_read_sectors(&stor_dev, dev->d_unit, od->od_start + dblk,
+ size / stor_dev.sd_blksize, 0, buf);
+
+ if (!err && rsize)
+ *rsize = size;
+
+ if (err)
+ dev_printf(dev, "read operation failed dblk=%llu size=%d err=%d\n",
+ dblk, size, err);
+
+ return err;
+}
+
+static int ps3disk_open(struct open_file *f, ...)
+{
+ va_list ap;
+ struct ps3_devdesc *dev;
+ struct open_dev *od;
+ int err;
+
+ va_start(ap, f);
+ dev = va_arg(ap, struct ps3_devdesc *);
+ va_end(ap);
+
+ od = malloc(sizeof(struct open_dev));
+ if (!od) {
+ dev_printf(dev, "couldn't allocate memory for new open_dev\n");
+ return ENOMEM;
+ }
+
+ err = ps3disk_open_gpt(dev, od);
+
+ if (err) {
+ dev_printf(dev, "couldn't open GPT disk error=%d\n", err);
+ free(od);
+ } else {
+ ((struct ps3_devdesc *) (f->f_devdata))->d_disk.data = od;
+ }
+
+ return err;
+}
+
+static int ps3disk_close(struct open_file *f)
+{
+ struct ps3_devdesc *dev = f->f_devdata;
+ struct open_dev *od = dev->d_disk.data;
+
+ if (dev->d_disk.ptype == PTYPE_GPT && od->od_gpt_nparts)
+ free(od->od_gpt_parts);
+
+ free(od);
+
+ dev->d_disk.data = NULL;
+
+ return 0;
+}
+
+static void ps3disk_print(int verbose)
+{
+}
+
+static int ps3disk_open_gpt(struct ps3_devdesc *dev, struct open_dev *od)
+{
+ char buf[512];
+ struct gpt_hdr *hdr;
+ struct gpt_ent *ent;
+ daddr_t slba, elba, lba;
+ int nparts, eps, i, part, err;
+
+ od->od_gpt_nparts = 0;
+ od->od_gpt_parts = NULL;
+
+ err = ps3stor_read_sectors(&stor_dev, dev->d_unit, 0, 1, 0, buf);
+ if (err) {
+ err = EIO;
+ goto out;
+ }
+
+ if (le16toh(*((uint16_t *) (buf + DOSMAGICOFFSET))) != DOSMAGIC) {
+ err = ENXIO;
+ goto out;
+ }
+
+ err = ps3stor_read_sectors(&stor_dev, dev->d_unit, 1, 1, 0, buf);
+ if (err) {
+ err = EIO;
+ goto out;
+ }
+
+ hdr = (struct gpt_hdr *) buf;
+
+ if (bcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)) ||
+ le64toh(hdr->hdr_lba_self) != 1 || le32toh(hdr->hdr_revision) < 0x00010000 ||
+ le32toh(hdr->hdr_entsz) < sizeof(struct gpt_ent) ||
+ stor_dev.sd_blksize % le32toh(hdr->hdr_entsz) != 0) {
+ err = ENXIO;
+ goto out;
+ }
+
+ nparts = 0;
+ eps = stor_dev.sd_blksize / le32toh(hdr->hdr_entsz);
+ slba = le64toh(hdr->hdr_lba_table);
+ elba = slba + le32toh(hdr->hdr_entries) / eps;
+
+ for (lba = slba; lba < elba; lba++) {
+ err = ps3stor_read_sectors(&stor_dev, dev->d_unit, lba, 1, 0, buf);
+ if (err) {
+ err = EIO;
+ goto out;
+ }
+
+ ent = (struct gpt_ent *) buf;
+
+ for (i = 0; i < eps; i++) {
+ if (uuid_is_nil(&ent[i].ent_type, NULL) ||
+ le64toh(ent[i].ent_lba_start) == 0 ||
+ le64toh(ent[i].ent_lba_end) < le64toh(ent[i].ent_lba_start))
+ continue;
+
+ nparts++;
+ }
+ }
+
+ if (nparts) {
+ od->od_gpt_nparts = nparts;
+
+ od->od_gpt_parts = malloc(nparts * sizeof(struct gpt_part));
+ if (!od->od_gpt_parts) {
+ err = ENOMEM;
+ goto out;
+ }
+
+ for (lba = slba, part = 0; lba < elba; lba++) {
+ err = ps3stor_read_sectors(&stor_dev, dev->d_unit, lba, 1, 0, buf);
+ if (err) {
+ err = EIO;
+ goto out;
+ }
+
+ ent = (struct gpt_ent *) buf;
+
+ for (i = 0; i < eps; i++) {
+ if (uuid_is_nil(&ent[i].ent_type, NULL) ||
+ le64toh(ent[i].ent_lba_start) == 0 ||
+ le64toh(ent[i].ent_lba_end) < le64toh(ent[i].ent_lba_start))
+ continue;
+
+ od->od_gpt_parts[part].gp_index = (lba - slba) * eps + i + 1;
+ od->od_gpt_parts[part].gp_type = ent[i].ent_type;
+ od->od_gpt_parts[part].gp_start = le64toh(ent[i].ent_lba_start);
+ od->od_gpt_parts[part].gp_end = le64toh(ent[i].ent_lba_end);
+ ps3disk_uuid_letoh(&od->od_gpt_parts[part].gp_type);
+ part++;
+ }
+ }
+ }
+
+ dev->d_disk.ptype = PTYPE_GPT;
+
+ if (od->od_gpt_nparts && !dev->d_disk.pnum)
+ dev->d_disk.pnum = od->od_gpt_parts[0].gp_index;
+
+ for (i = 0; i < od->od_gpt_nparts; i++)
+ if (od->od_gpt_parts[i].gp_index == dev->d_disk.pnum)
+ od->od_start = od->od_gpt_parts[i].gp_start;
+
+ err = 0;
+
+out:
+
+ if (err && od->od_gpt_parts)
+ free(od->od_gpt_parts);
+
+ return err;
+}
+
+static void ps3disk_uuid_letoh(uuid_t *uuid)
+{
+ uuid->time_low = le32toh(uuid->time_low);
+ uuid->time_mid = le16toh(uuid->time_mid);
+ uuid->time_hi_and_version = le16toh(uuid->time_hi_and_version);
+}
diff --git a/sys/boot/powerpc/ps3/ps3repo.c b/sys/boot/powerpc/ps3/ps3repo.c
new file mode 100644
index 0000000..0064769
--- /dev/null
+++ b/sys/boot/powerpc/ps3/ps3repo.c
@@ -0,0 +1,249 @@
+/*-
+ * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <stand.h>
+
+#include "lv1call.h"
+#include "ps3.h"
+#include "ps3repo.h"
+
+static uint64_t make_n1(const char *text, unsigned int index)
+{
+ uint64_t n1;
+
+ n1 = 0;
+ strncpy((char *) &n1, text, sizeof(n1));
+ n1 = (n1 >> 32) + index;
+
+ return n1;
+}
+
+static uint64_t make_n(const char *text, unsigned int index)
+{
+ uint64_t n;
+
+ n = 0;
+ strncpy((char *) &n, text, sizeof(n));
+ n = n + index;
+
+ return n;
+}
+
+int ps3repo_read_bus_type(unsigned int bus_index, uint64_t *bus_type)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("type", 0), 0, 0, &v1, &v2);
+
+ *bus_type = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_id(unsigned int bus_index, uint64_t *bus_id)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("id", 0), 0, 0, &v1, &v2);
+
+ *bus_id = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_num_dev(unsigned int bus_index, uint64_t *num_dev)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("num_dev", 0), 0, 0, &v1, &v2);
+
+ *num_dev = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_dev_type(unsigned int bus_index, unsigned int dev_index, uint64_t *dev_type)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("dev", dev_index), make_n("type", 0), 0, &v1, &v2);
+
+ *dev_type = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_dev_id(unsigned int bus_index, unsigned int dev_index, uint64_t *dev_id)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("dev", dev_index), make_n("id", 0), 0, &v1, &v2);
+
+ *dev_id = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_dev_blk_size(unsigned int bus_index, unsigned int dev_index, uint64_t *blk_size)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("dev", dev_index), make_n("blk_size", 0), 0, &v1, &v2);
+
+ *blk_size = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_dev_nblocks(unsigned int bus_index, unsigned int dev_index, uint64_t *nblocks)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("dev", dev_index), make_n("n_blocks", 0), 0, &v1, &v2);
+
+ *nblocks = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_dev_nregs(unsigned int bus_index, unsigned int dev_index, uint64_t *nregs)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("dev", dev_index), make_n("n_regs", 0), 0, &v1, &v2);
+
+ *nregs = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_dev_reg_id(unsigned int bus_index, unsigned int dev_index,
+ unsigned int reg_index, uint64_t *reg_id)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("dev", dev_index), make_n("region", reg_index), make_n("id", 0), &v1, &v2);
+
+ *reg_id = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_dev_reg_start(unsigned int bus_index, unsigned int dev_index,
+ unsigned int reg_index, uint64_t *reg_start)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("dev", dev_index), make_n("region", reg_index), make_n("start", 0), &v1, &v2);
+
+ *reg_start = v1;
+
+ return err;
+}
+
+int ps3repo_read_bus_dev_reg_size(unsigned int bus_index, unsigned int dev_index,
+ unsigned int reg_index, uint64_t *reg_size)
+{
+ uint64_t v1, v2;
+ int err;
+
+ err = lv1_get_repository_node_value(PS3_LPAR_ID_PME, make_n1("bus", bus_index),
+ make_n("dev", dev_index), make_n("region", reg_index), make_n("size", 0), &v1, &v2);
+
+ *reg_size = v1;
+
+ return err;
+}
+
+int ps3repo_find_bus_by_type(uint64_t bus_type, unsigned int *bus_index)
+{
+ unsigned int i;
+ uint64_t type;
+ int err;
+
+ for (i = 0; i < 10; i++) {
+ err = ps3repo_read_bus_type(i, &type);
+ if (err) {
+ *bus_index = (unsigned int) -1;
+ return err;
+ }
+
+ if (type == bus_type) {
+ *bus_index = i;
+ return 0;
+ }
+ }
+
+ *bus_index = (unsigned int) -1;
+
+ return ENODEV;
+}
+
+int ps3repo_find_bus_dev_by_type(unsigned int bus_index, uint64_t dev_type,
+ unsigned int *dev_index)
+{
+ unsigned int i;
+ uint64_t type;
+ int err;
+
+ for (i = 0; i < 10; i++) {
+ err = ps3repo_read_bus_dev_type(bus_index, i, &type);
+ if (err) {
+ *dev_index = (unsigned int) -1;
+ return err;
+ }
+
+ if (type == dev_type) {
+ *dev_index = i;
+ return 0;
+ }
+ }
+
+ *dev_index = (unsigned int) -1;
+
+ return ENODEV;
+}
diff --git a/sys/boot/powerpc/ps3/ps3repo.h b/sys/boot/powerpc/ps3/ps3repo.h
new file mode 100644
index 0000000..68001df
--- /dev/null
+++ b/sys/boot/powerpc/ps3/ps3repo.h
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _PS3_REPO_H
+#define _PS3_REPO_H
+
+#define PS3_LPAR_ID_PME 1
+
+int ps3repo_read_bus_type(unsigned int bus_index, uint64_t *bus_type);
+int ps3repo_read_bus_id(unsigned int bus_index, uint64_t *bus_id);
+int ps3repo_read_bus_num_dev(unsigned int bus_index, uint64_t *num_dev);
+int ps3repo_read_bus_dev_type(unsigned int bus_index, unsigned int dev_index, uint64_t *dev_type);
+int ps3repo_read_bus_dev_id(unsigned int bus_index, unsigned int dev_index, uint64_t *dev_id);
+int ps3repo_read_bus_dev_blk_size(unsigned int bus_index, unsigned int dev_index, uint64_t *blk_size);
+int ps3repo_read_bus_dev_nblocks(unsigned int bus_index, unsigned int dev_index, uint64_t *nblocks);
+int ps3repo_read_bus_dev_nregs(unsigned int bus_index, unsigned int dev_index, uint64_t *nregs);
+int ps3repo_read_bus_dev_reg_id(unsigned int bus_index, unsigned int dev_index,
+ unsigned int reg_index, uint64_t *reg_id);
+int ps3repo_read_bus_dev_reg_start(unsigned int bus_index, unsigned int dev_index,
+ unsigned int reg_index, uint64_t *reg_start);
+int ps3repo_read_bus_dev_reg_size(unsigned int bus_index, unsigned int dev_index,
+ unsigned int reg_index, uint64_t *reg_size);
+int ps3repo_find_bus_by_type(uint64_t bus_type, unsigned int *bus_index);
+int ps3repo_find_bus_dev_by_type(unsigned int bus_index, uint64_t dev_type,
+ unsigned int *dev_index);
+
+#endif
diff --git a/sys/boot/powerpc/ps3/ps3stor.c b/sys/boot/powerpc/ps3/ps3stor.c
new file mode 100644
index 0000000..667b39c
--- /dev/null
+++ b/sys/boot/powerpc/ps3/ps3stor.c
@@ -0,0 +1,165 @@
+/*-
+ * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <stand.h>
+
+#include "bootstrap.h"
+#include "lv1call.h"
+#include "ps3bus.h"
+#include "ps3repo.h"
+#include "ps3stor.h"
+
+int ps3stor_setup(struct ps3_stordev *sd, int type)
+{
+ unsigned int i;
+ int err;
+
+ sd->sd_type = type;
+
+ err = ps3repo_find_bus_by_type(PS3_BUS_TYPE_STOR, &sd->sd_busidx);
+ if (err)
+ goto out;
+
+ err = ps3repo_read_bus_id(sd->sd_busidx, &sd->sd_busid);
+ if (err)
+ goto out;
+
+ err = ps3repo_find_bus_dev_by_type(sd->sd_busidx, type, &sd->sd_devidx);
+ if (err)
+ goto out;
+
+ err = ps3repo_read_bus_dev_id(sd->sd_busidx, sd->sd_devidx, &sd->sd_devid);
+ if (err)
+ goto out;
+
+ err = ps3repo_read_bus_dev_blk_size(sd->sd_busidx, sd->sd_devidx, &sd->sd_blksize);
+ if (err)
+ goto out;
+
+ err = ps3repo_read_bus_dev_nblocks(sd->sd_busidx, sd->sd_devidx, &sd->sd_nblocks);
+ if (err)
+ goto out;
+
+ err = ps3repo_read_bus_dev_nregs(sd->sd_busidx, sd->sd_devidx, &sd->sd_nregs);
+ if (err)
+ goto out;
+
+ for (i = 0; i < sd->sd_nregs; i++) {
+ err = ps3repo_read_bus_dev_reg_id(sd->sd_busidx, sd->sd_devidx, i,
+ &sd->sd_regs[i].sr_id);
+ if (err)
+ goto out;
+
+ err = ps3repo_read_bus_dev_reg_start(sd->sd_busidx, sd->sd_devidx, i,
+ &sd->sd_regs[i].sr_start);
+ if (err)
+ goto out;
+
+ err = ps3repo_read_bus_dev_reg_size(sd->sd_busidx, sd->sd_devidx, i,
+ &sd->sd_regs[i].sr_size);
+ if (err)
+ goto out;
+ }
+
+ if (!sd->sd_nregs) {
+ err = ENODEV;
+ goto out;
+ }
+
+ err = lv1_open_device(sd->sd_busid, sd->sd_devid, 0);
+ if (err)
+ goto out;
+
+ err = lv1_setup_dma(sd->sd_busid, sd->sd_devid, &sd->sd_dmabase);
+ if (err)
+ goto close_dev;
+
+ return 0;
+
+close_dev:
+
+ lv1_close_device(sd->sd_busid, sd->sd_devid);
+
+out:
+
+ return err;
+}
+
+int ps3stor_read_sectors(struct ps3_stordev *sd, int regidx,
+ uint64_t start_sector, uint64_t sector_count, uint64_t flags, char *buf)
+{
+#define MIN(a, b) ((a) <= (b) ? (a) : (b))
+#define BOUNCE_SECTORS 4
+#define ASYNC_STATUS_POLL_PERIOD 100 /* microseconds */
+
+ struct ps3_storreg *reg = &sd->sd_regs[regidx];
+ char dma_buf[sd->sd_blksize * BOUNCE_SECTORS];
+ uint64_t nleft, nread, nsectors;
+ uint64_t tag, status;
+ unsigned int timeout;
+ int err;
+
+ nleft = sector_count;
+ nread = 0;
+
+ while (nleft) {
+ nsectors = MIN(nleft, BOUNCE_SECTORS);
+
+ err = lv1_storage_read(sd->sd_devid, reg->sr_id, start_sector + nread, nsectors,
+ flags, (uint32_t) dma_buf, &tag);
+ if (err)
+ return err;
+
+ timeout = 5000000; /* microseconds */
+
+ while (1) {
+ if (timeout < ASYNC_STATUS_POLL_PERIOD)
+ return ETIMEDOUT;
+
+ err = lv1_storage_check_async_status(sd->sd_devid, tag, &status);
+ if (!err && !status)
+ break;
+
+ delay(ASYNC_STATUS_POLL_PERIOD);
+ timeout -= ASYNC_STATUS_POLL_PERIOD;
+ }
+
+ memcpy(buf + nread * sd->sd_blksize, (u_char *) dma_buf, nsectors * sd->sd_blksize);
+ nread += nsectors;
+ nleft -= nsectors;
+ }
+
+ return 0;
+
+#undef MIN
+#undef BOUNCE_SECTORS
+#undef ASYNC_STATUS_POLL_PERIOD
+}
+
+void ps3stor_print(struct ps3_stordev *sd)
+{
+}
diff --git a/sys/boot/powerpc/ps3/ps3stor.h b/sys/boot/powerpc/ps3/ps3stor.h
new file mode 100644
index 0000000..350b716
--- /dev/null
+++ b/sys/boot/powerpc/ps3/ps3stor.h
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _PS3_STOR_H
+#define _PS3_STOR_H
+
+#define PS3_STOR_DEV_MAXREGS 8
+
+struct ps3_storreg {
+ uint64_t sr_id;
+ uint64_t sr_start;
+ uint64_t sr_size;
+};
+
+struct ps3_stordev {
+ int sd_type;
+ unsigned int sd_busidx;
+ unsigned int sd_devidx;
+ uint64_t sd_busid;
+ uint64_t sd_devid;
+ uint64_t sd_blksize;
+ uint64_t sd_nblocks;
+ uint64_t sd_nregs;
+ struct ps3_storreg sd_regs[PS3_STOR_DEV_MAXREGS];
+ uint64_t sd_dmabase;
+};
+
+int ps3stor_setup(struct ps3_stordev *sd, int type);
+
+int ps3stor_read_sectors(struct ps3_stordev *sd, int regidx,
+ uint64_t start_sector, uint64_t sector_count, uint64_t flags, char *buf);
+
+void ps3stor_print(struct ps3_stordev *sd);
+
+#endif
diff --git a/sys/boot/powerpc/ps3/version b/sys/boot/powerpc/ps3/version
index fa0b185..fdac54e 100644
--- a/sys/boot/powerpc/ps3/version
+++ b/sys/boot/powerpc/ps3/version
@@ -3,4 +3,6 @@ $FreeBSD$
NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this
file is important. Make sure the current version number is on line 6.
+0.3: Added GPT support to disk.
+0.2: Added disk support.
0.1: Initial PS3/PowerPC version.
OpenPOWER on IntegriCloud