/*
* PS3 device registration routines.
*
* Copyright (C) 2007 Sony Computer Entertainment Inc.
* Copyright 2007 Sony Corp.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/delay.h>
#include <linux/freezer.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/reboot.h>
#include <asm/firmware.h>
#include <asm/lv1call.h>
#include <asm/ps3stor.h>
#include "platform.h"
static int __init ps3_register_lpm_devices(void)
{
int result;
u64 tmp1;
u64 tmp2;
struct ps3_system_bus_device *dev;
pr_debug(" -> %s:%d\n", __func__, __LINE__);
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
dev->match_id = PS3_MATCH_ID_LPM;
dev->dev_type = PS3_DEVICE_TYPE_LPM;
/* The current lpm driver only supports a single BE processor. */
result = ps3_repository_read_be_node_id(0, &dev->lpm.node_id);
if (result) {
pr_debug("%s:%d: ps3_repository_read_be_node_id failed \n",
__func__, __LINE__);
goto fail_read_repo;
}
result = ps3_repository_read_lpm_privileges(dev->lpm.node_id, &tmp1,
&dev->lpm.rights);
if (result) {
pr_debug("%s:%d: ps3_repository_read_lpm_privleges failed \n",
__func__, __LINE__);
goto fail_read_repo;
}
lv1_get_logical_partition_id(&tmp2);
if (tmp1 != tmp2) {
pr_debug("%s:%d: wrong lpar\n",
__func__, __LINE__);
result = -ENODEV;
goto fail_rights;
}
if (!(dev->lpm.rights & PS3_LPM_RIGHTS_USE_LPM)) {
pr_debug("%s:%d: don't have rights to use lpm\n",
__func__, __LINE__);
result = -EPERM;
goto fail_rights;
}
pr_debug("%s:%d: pu_id %llu, rights %llu(%llxh)\n",
__func__, __LINE__, dev->lpm.pu_id, dev->lpm.rights,
dev->lpm.rights);
result = ps3_repository_read_pu_id(0, &dev->lpm.pu_id);
if (result) {
pr_debug("%s:%d: ps3_repository_read_pu_id failed \n",
__func__, __LINE__);
goto fail_read_repo;
}
result = ps3_system_bus_device_register(dev);
if (result) {
pr_debug("%s:%d ps3_system_bus_device_register failed\n",
__func__, __LINE__);
goto fail_register;
}
pr_debug(" <- %s:%d\n", __func__, __LINE__);
return 0;
fail_register:
fail_rights:
fail_read_repo:
kfree(dev);
pr_debug(" <- %s:%d: failed\n", __func__, __LINE__);
return result;
}
/**
* ps3_setup_gelic_device - Setup and register a gelic device instance.
*
* Allocates memory for a struct ps3_system_bus_device instance, initialises the
* structure members, and registers the device instance with the system bus.
*/
static int __init ps3_setup_gelic_device(
const struct ps3_repository_device *repo)
{
int result;
struct layout {
struct ps3_system_bus_device dev;
struct ps3_dma_region d_region;
} *p;
pr_debug(" -> %s:%d\n", __func__, __LINE__);
BUG_ON(repo->bus_type != PS3_BUS_TYPE_SB);
BUG_ON(repo->dev_type != PS3_DEV_TYPE_SB_GELIC);
p = kzalloc(sizeof(struct layout), GFP_KERNEL);
if (!p) {
result = -ENOMEM;
goto fail_malloc;
}
p->dev.match_id = PS3_MATCH_ID_GELIC;
p->dev.dev_type = PS3_DEVICE_TYPE_SB;
p->dev.bus_id = repo->bus_id;
p->dev.dev_id = repo->dev_id;
p->dev.d_region = &p->d_region;
result = ps3_repository_find_interrupt(repo,
PS3_INTERRUPT_TYPE_EVENT_PORT, &p->dev.interrupt_id);
if (result) {
pr_debug("%s:%d ps3_repository_find_interrupt failed\n",
__func__, __LINE__);
goto fail_find_interrupt;
}
BUG_ON(p->dev.interrupt_id != 0);
result = ps3_dma_region_init(&p->dev, p->dev.d_region, PS3_DMA_64K,
PS3_DMA_OTHER, NULL, 0);
if (result) {
pr_debug("%s:%d ps3_dma_region_init failed\n",
__func__, __LINE__