Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Jul 2011 19:01:09 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r224106 - head/sys/boot/powerpc/ps3
Message-ID:  <201107161901.p6GJ196Q040112@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Sat Jul 16 19:01:09 2011
New Revision: 224106
URL: http://svn.freebsd.org/changeset/base/224106

Log:
  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 >

Added:
  head/sys/boot/powerpc/ps3/ps3bus.h   (contents, props changed)
  head/sys/boot/powerpc/ps3/ps3devdesc.h   (contents, props changed)
  head/sys/boot/powerpc/ps3/ps3disk.c   (contents, props changed)
  head/sys/boot/powerpc/ps3/ps3repo.c   (contents, props changed)
  head/sys/boot/powerpc/ps3/ps3repo.h   (contents, props changed)
  head/sys/boot/powerpc/ps3/ps3stor.c   (contents, props changed)
  head/sys/boot/powerpc/ps3/ps3stor.h   (contents, props changed)
Modified:
  head/sys/boot/powerpc/ps3/Makefile
  head/sys/boot/powerpc/ps3/conf.c
  head/sys/boot/powerpc/ps3/devicename.c
  head/sys/boot/powerpc/ps3/lv1call.S
  head/sys/boot/powerpc/ps3/lv1call.h
  head/sys/boot/powerpc/ps3/main.c
  head/sys/boot/powerpc/ps3/version

Modified: head/sys/boot/powerpc/ps3/Makefile
==============================================================================
--- head/sys/boot/powerpc/ps3/Makefile	Sat Jul 16 17:22:01 2011	(r224105)
+++ head/sys/boot/powerpc/ps3/Makefile	Sat Jul 16 19:01:09 2011	(r224106)
@@ -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

Modified: head/sys/boot/powerpc/ps3/conf.c
==============================================================================
--- head/sys/boot/powerpc/ps3/conf.c	Sat Jul 16 17:22:01 2011	(r224105)
+++ head/sys/boot/powerpc/ps3/conf.c	Sat Jul 16 19:01:09 2011	(r224106)
@@ -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

Modified: head/sys/boot/powerpc/ps3/devicename.c
==============================================================================
--- head/sys/boot/powerpc/ps3/devicename.c	Sat Jul 16 17:22:01 2011	(r224105)
+++ head/sys/boot/powerpc/ps3/devicename.c	Sat Jul 16 19:01:09 2011	(r224106)
@@ -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 *
 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 *devs
  *
  */
 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
 	}
 	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
 	case DEVT_NONE:
 		break;
 
-#ifdef NOTYET
 	case DEVT_DISK:
 		unit = -1;
 		pnum = -1;
@@ -154,7 +155,6 @@ ps3_parsedev(struct devdesc **dev, const
 		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)

Modified: head/sys/boot/powerpc/ps3/lv1call.S
==============================================================================
--- head/sys/boot/powerpc/ps3/lv1call.S	Sat Jul 16 17:22:01 2011	(r224105)
+++ head/sys/boot/powerpc/ps3/lv1call.S	Sat Jul 16 19:01:09 2011	(r224106)
@@ -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

Modified: head/sys/boot/powerpc/ps3/lv1call.h
==============================================================================
--- head/sys/boot/powerpc/ps3/lv1call.h	Sat Jul 16 17:22:01 2011	(r224105)
+++ head/sys/boot/powerpc/ps3/lv1call.h	Sat Jul 16 19:01:09 2011	(r224106)
@@ -68,5 +68,13 @@ int lv1_net_start_rx_dma(int bus, int de
 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
 

Modified: head/sys/boot/powerpc/ps3/main.c
==============================================================================
--- head/sys/boot/powerpc/ps3/main.c	Sat Jul 16 17:22:01 2011	(r224105)
+++ head/sys/boot/powerpc/ps3/main.c	Sat Jul 16 19:01:09 2011	(r224106)
@@ -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);
 

Added: head/sys/boot/powerpc/ps3/ps3bus.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/boot/powerpc/ps3/ps3bus.h	Sat Jul 16 19:01:09 2011	(r224106)
@@ -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

Added: head/sys/boot/powerpc/ps3/ps3devdesc.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/boot/powerpc/ps3/ps3devdesc.h	Sat Jul 16 19:01:09 2011	(r224106)
@@ -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

Added: head/sys/boot/powerpc/ps3/ps3disk.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/boot/powerpc/ps3/ps3disk.c	Sat Jul 16 19:01:09 2011	(r224106)
@@ -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);
+}

Added: head/sys/boot/powerpc/ps3/ps3repo.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/boot/powerpc/ps3/ps3repo.c	Sat Jul 16 19:01:09 2011	(r224106)
@@ -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;
+}
+

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107161901.p6GJ196Q040112>