Path: blob/master/arch/powerpc/platforms/ps3/device-init.c
26481 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* PS3 device registration routines.3*4* Copyright (C) 2007 Sony Computer Entertainment Inc.5* Copyright 2007 Sony Corp.6*/78#include <linux/delay.h>9#include <linux/freezer.h>10#include <linux/kernel.h>11#include <linux/kthread.h>12#include <linux/init.h>13#include <linux/slab.h>14#include <linux/reboot.h>15#include <linux/rcuwait.h>16#include <linux/string_choices.h>1718#include <asm/firmware.h>19#include <asm/lv1call.h>20#include <asm/ps3stor.h>2122#include "platform.h"2324static int __init ps3_register_lpm_devices(void)25{26int result;27u64 tmp1;28u64 tmp2;29struct ps3_system_bus_device *dev;3031pr_debug(" -> %s:%d\n", __func__, __LINE__);3233dev = kzalloc(sizeof(*dev), GFP_KERNEL);34if (!dev)35return -ENOMEM;3637dev->match_id = PS3_MATCH_ID_LPM;38dev->dev_type = PS3_DEVICE_TYPE_LPM;3940/* The current lpm driver only supports a single BE processor. */4142result = ps3_repository_read_be_node_id(0, &dev->lpm.node_id);4344if (result) {45pr_debug("%s:%d: ps3_repository_read_be_node_id failed \n",46__func__, __LINE__);47goto fail_read_repo;48}4950result = ps3_repository_read_lpm_privileges(dev->lpm.node_id, &tmp1,51&dev->lpm.rights);5253if (result) {54pr_debug("%s:%d: ps3_repository_read_lpm_privileges failed\n",55__func__, __LINE__);56goto fail_read_repo;57}5859lv1_get_logical_partition_id(&tmp2);6061if (tmp1 != tmp2) {62pr_debug("%s:%d: wrong lpar\n",63__func__, __LINE__);64result = -ENODEV;65goto fail_rights;66}6768if (!(dev->lpm.rights & PS3_LPM_RIGHTS_USE_LPM)) {69pr_debug("%s:%d: don't have rights to use lpm\n",70__func__, __LINE__);71result = -EPERM;72goto fail_rights;73}7475pr_debug("%s:%d: pu_id %llu, rights %llu(%llxh)\n",76__func__, __LINE__, dev->lpm.pu_id, dev->lpm.rights,77dev->lpm.rights);7879result = ps3_repository_read_pu_id(0, &dev->lpm.pu_id);8081if (result) {82pr_debug("%s:%d: ps3_repository_read_pu_id failed \n",83__func__, __LINE__);84goto fail_read_repo;85}8687result = ps3_system_bus_device_register(dev);8889if (result) {90pr_debug("%s:%d ps3_system_bus_device_register failed\n",91__func__, __LINE__);92goto fail_register;93}9495pr_debug(" <- %s:%d\n", __func__, __LINE__);96return 0;979899fail_register:100fail_rights:101fail_read_repo:102kfree(dev);103pr_debug(" <- %s:%d: failed\n", __func__, __LINE__);104return result;105}106107/**108* ps3_setup_gelic_device - Setup and register a gelic device instance.109*110* Allocates memory for a struct ps3_system_bus_device instance, initialises the111* structure members, and registers the device instance with the system bus.112*/113114static int __init ps3_setup_gelic_device(115const struct ps3_repository_device *repo)116{117int result;118struct layout {119struct ps3_system_bus_device dev;120struct ps3_dma_region d_region;121} *p;122123pr_debug(" -> %s:%d\n", __func__, __LINE__);124125BUG_ON(repo->bus_type != PS3_BUS_TYPE_SB);126BUG_ON(repo->dev_type != PS3_DEV_TYPE_SB_GELIC);127128p = kzalloc(sizeof(struct layout), GFP_KERNEL);129130if (!p) {131result = -ENOMEM;132goto fail_malloc;133}134135p->dev.match_id = PS3_MATCH_ID_GELIC;136p->dev.dev_type = PS3_DEVICE_TYPE_SB;137p->dev.bus_id = repo->bus_id;138p->dev.dev_id = repo->dev_id;139p->dev.d_region = &p->d_region;140141result = ps3_repository_find_interrupt(repo,142PS3_INTERRUPT_TYPE_EVENT_PORT, &p->dev.interrupt_id);143144if (result) {145pr_debug("%s:%d ps3_repository_find_interrupt failed\n",146__func__, __LINE__);147goto fail_find_interrupt;148}149150BUG_ON(p->dev.interrupt_id != 0);151152result = ps3_dma_region_init(&p->dev, p->dev.d_region, PS3_DMA_64K,153PS3_DMA_OTHER, NULL, 0);154155if (result) {156pr_debug("%s:%d ps3_dma_region_init failed\n",157__func__, __LINE__);158goto fail_dma_init;159}160161result = ps3_system_bus_device_register(&p->dev);162163if (result) {164pr_debug("%s:%d ps3_system_bus_device_register failed\n",165__func__, __LINE__);166goto fail_device_register;167}168169pr_debug(" <- %s:%d\n", __func__, __LINE__);170return result;171172fail_device_register:173fail_dma_init:174fail_find_interrupt:175kfree(p);176fail_malloc:177pr_debug(" <- %s:%d: fail.\n", __func__, __LINE__);178return result;179}180181static int __init ps3_setup_uhc_device(182const struct ps3_repository_device *repo, enum ps3_match_id match_id,183enum ps3_interrupt_type interrupt_type, enum ps3_reg_type reg_type)184{185int result;186struct layout {187struct ps3_system_bus_device dev;188struct ps3_dma_region d_region;189struct ps3_mmio_region m_region;190} *p;191u64 bus_addr;192u64 len;193194pr_debug(" -> %s:%d\n", __func__, __LINE__);195196BUG_ON(repo->bus_type != PS3_BUS_TYPE_SB);197BUG_ON(repo->dev_type != PS3_DEV_TYPE_SB_USB);198199p = kzalloc(sizeof(struct layout), GFP_KERNEL);200201if (!p) {202result = -ENOMEM;203goto fail_malloc;204}205206p->dev.match_id = match_id;207p->dev.dev_type = PS3_DEVICE_TYPE_SB;208p->dev.bus_id = repo->bus_id;209p->dev.dev_id = repo->dev_id;210p->dev.d_region = &p->d_region;211p->dev.m_region = &p->m_region;212213result = ps3_repository_find_interrupt(repo,214interrupt_type, &p->dev.interrupt_id);215216if (result) {217pr_debug("%s:%d ps3_repository_find_interrupt failed\n",218__func__, __LINE__);219goto fail_find_interrupt;220}221222result = ps3_repository_find_reg(repo, reg_type,223&bus_addr, &len);224225if (result) {226pr_debug("%s:%d ps3_repository_find_reg failed\n",227__func__, __LINE__);228goto fail_find_reg;229}230231result = ps3_dma_region_init(&p->dev, p->dev.d_region, PS3_DMA_64K,232PS3_DMA_INTERNAL, NULL, 0);233234if (result) {235pr_debug("%s:%d ps3_dma_region_init failed\n",236__func__, __LINE__);237goto fail_dma_init;238}239240result = ps3_mmio_region_init(&p->dev, p->dev.m_region, bus_addr, len,241PS3_MMIO_4K);242243if (result) {244pr_debug("%s:%d ps3_mmio_region_init failed\n",245__func__, __LINE__);246goto fail_mmio_init;247}248249result = ps3_system_bus_device_register(&p->dev);250251if (result) {252pr_debug("%s:%d ps3_system_bus_device_register failed\n",253__func__, __LINE__);254goto fail_device_register;255}256257pr_debug(" <- %s:%d\n", __func__, __LINE__);258return result;259260fail_device_register:261fail_mmio_init:262fail_dma_init:263fail_find_reg:264fail_find_interrupt:265kfree(p);266fail_malloc:267pr_debug(" <- %s:%d: fail.\n", __func__, __LINE__);268return result;269}270271static int __init ps3_setup_ehci_device(272const struct ps3_repository_device *repo)273{274return ps3_setup_uhc_device(repo, PS3_MATCH_ID_EHCI,275PS3_INTERRUPT_TYPE_SB_EHCI, PS3_REG_TYPE_SB_EHCI);276}277278static int __init ps3_setup_ohci_device(279const struct ps3_repository_device *repo)280{281return ps3_setup_uhc_device(repo, PS3_MATCH_ID_OHCI,282PS3_INTERRUPT_TYPE_SB_OHCI, PS3_REG_TYPE_SB_OHCI);283}284285static int __init ps3_setup_vuart_device(enum ps3_match_id match_id,286unsigned int port_number)287{288int result;289struct layout {290struct ps3_system_bus_device dev;291} *p;292293pr_debug(" -> %s:%d: match_id %u, port %u\n", __func__, __LINE__,294match_id, port_number);295296p = kzalloc(sizeof(struct layout), GFP_KERNEL);297298if (!p)299return -ENOMEM;300301p->dev.match_id = match_id;302p->dev.dev_type = PS3_DEVICE_TYPE_VUART;303p->dev.port_number = port_number;304305result = ps3_system_bus_device_register(&p->dev);306307if (result) {308pr_debug("%s:%d ps3_system_bus_device_register failed\n",309__func__, __LINE__);310goto fail_device_register;311}312pr_debug(" <- %s:%d\n", __func__, __LINE__);313return 0;314315fail_device_register:316kfree(p);317pr_debug(" <- %s:%d fail\n", __func__, __LINE__);318return result;319}320321static int ps3_setup_storage_dev(const struct ps3_repository_device *repo,322enum ps3_match_id match_id)323{324int result;325struct ps3_storage_device *p;326u64 port, blk_size, num_blocks;327unsigned int num_regions, i;328329pr_debug(" -> %s:%u: match_id %u\n", __func__, __LINE__, match_id);330331result = ps3_repository_read_stor_dev_info(repo->bus_index,332repo->dev_index, &port,333&blk_size, &num_blocks,334&num_regions);335if (result) {336printk(KERN_ERR "%s:%u: _read_stor_dev_info failed %d\n",337__func__, __LINE__, result);338return -ENODEV;339}340341pr_debug("%s:%u: (%u:%u:%u): port %llu blk_size %llu num_blocks %llu "342"num_regions %u\n", __func__, __LINE__, repo->bus_index,343repo->dev_index, repo->dev_type, port, blk_size, num_blocks,344num_regions);345346p = kzalloc(struct_size(p, regions, num_regions), GFP_KERNEL);347if (!p) {348result = -ENOMEM;349goto fail_malloc;350}351352p->sbd.match_id = match_id;353p->sbd.dev_type = PS3_DEVICE_TYPE_SB;354p->sbd.bus_id = repo->bus_id;355p->sbd.dev_id = repo->dev_id;356p->sbd.d_region = &p->dma_region;357p->blk_size = blk_size;358p->num_regions = num_regions;359360result = ps3_repository_find_interrupt(repo,361PS3_INTERRUPT_TYPE_EVENT_PORT,362&p->sbd.interrupt_id);363if (result) {364printk(KERN_ERR "%s:%u: find_interrupt failed %d\n", __func__,365__LINE__, result);366result = -ENODEV;367goto fail_find_interrupt;368}369370for (i = 0; i < num_regions; i++) {371unsigned int id;372u64 start, size;373374result = ps3_repository_read_stor_dev_region(repo->bus_index,375repo->dev_index,376i, &id, &start,377&size);378if (result) {379printk(KERN_ERR380"%s:%u: read_stor_dev_region failed %d\n",381__func__, __LINE__, result);382result = -ENODEV;383goto fail_read_region;384}385pr_debug("%s:%u: region %u: id %u start %llu size %llu\n",386__func__, __LINE__, i, id, start, size);387388p->regions[i].id = id;389p->regions[i].start = start;390p->regions[i].size = size;391}392393result = ps3_system_bus_device_register(&p->sbd);394if (result) {395pr_debug("%s:%u ps3_system_bus_device_register failed\n",396__func__, __LINE__);397goto fail_device_register;398}399400pr_debug(" <- %s:%u\n", __func__, __LINE__);401return 0;402403fail_device_register:404fail_read_region:405fail_find_interrupt:406kfree(p);407fail_malloc:408pr_debug(" <- %s:%u: fail.\n", __func__, __LINE__);409return result;410}411412static int __init ps3_register_vuart_devices(void)413{414int result;415unsigned int port_number;416417pr_debug(" -> %s:%d\n", __func__, __LINE__);418419result = ps3_repository_read_vuart_av_port(&port_number);420if (result)421port_number = 0; /* av default */422423result = ps3_setup_vuart_device(PS3_MATCH_ID_AV_SETTINGS, port_number);424WARN_ON(result);425426result = ps3_repository_read_vuart_sysmgr_port(&port_number);427if (result)428port_number = 2; /* sysmgr default */429430result = ps3_setup_vuart_device(PS3_MATCH_ID_SYSTEM_MANAGER,431port_number);432WARN_ON(result);433434pr_debug(" <- %s:%d\n", __func__, __LINE__);435return result;436}437438static int __init ps3_register_sound_devices(void)439{440int result;441struct layout {442struct ps3_system_bus_device dev;443struct ps3_dma_region d_region;444struct ps3_mmio_region m_region;445} *p;446447pr_debug(" -> %s:%d\n", __func__, __LINE__);448449p = kzalloc(sizeof(*p), GFP_KERNEL);450if (!p)451return -ENOMEM;452453p->dev.match_id = PS3_MATCH_ID_SOUND;454p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;455p->dev.d_region = &p->d_region;456p->dev.m_region = &p->m_region;457458result = ps3_system_bus_device_register(&p->dev);459460if (result) {461pr_debug("%s:%d ps3_system_bus_device_register failed\n",462__func__, __LINE__);463goto fail_device_register;464}465pr_debug(" <- %s:%d\n", __func__, __LINE__);466return 0;467468fail_device_register:469kfree(p);470pr_debug(" <- %s:%d failed\n", __func__, __LINE__);471return result;472}473474static int __init ps3_register_graphics_devices(void)475{476int result;477struct layout {478struct ps3_system_bus_device dev;479} *p;480481pr_debug(" -> %s:%d\n", __func__, __LINE__);482483p = kzalloc(sizeof(struct layout), GFP_KERNEL);484485if (!p)486return -ENOMEM;487488p->dev.match_id = PS3_MATCH_ID_GPU;489p->dev.match_sub_id = PS3_MATCH_SUB_ID_GPU_FB;490p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;491492result = ps3_system_bus_device_register(&p->dev);493494if (result) {495pr_debug("%s:%d ps3_system_bus_device_register failed\n",496__func__, __LINE__);497goto fail_device_register;498}499500pr_debug(" <- %s:%d\n", __func__, __LINE__);501return 0;502503fail_device_register:504kfree(p);505pr_debug(" <- %s:%d failed\n", __func__, __LINE__);506return result;507}508509static int __init ps3_register_ramdisk_device(void)510{511int result;512struct layout {513struct ps3_system_bus_device dev;514} *p;515516pr_debug(" -> %s:%d\n", __func__, __LINE__);517518p = kzalloc(sizeof(struct layout), GFP_KERNEL);519520if (!p)521return -ENOMEM;522523p->dev.match_id = PS3_MATCH_ID_GPU;524p->dev.match_sub_id = PS3_MATCH_SUB_ID_GPU_RAMDISK;525p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;526527result = ps3_system_bus_device_register(&p->dev);528529if (result) {530pr_debug("%s:%d ps3_system_bus_device_register failed\n",531__func__, __LINE__);532goto fail_device_register;533}534535pr_debug(" <- %s:%d\n", __func__, __LINE__);536return 0;537538fail_device_register:539kfree(p);540pr_debug(" <- %s:%d failed\n", __func__, __LINE__);541return result;542}543544/**545* ps3_setup_dynamic_device - Setup a dynamic device from the repository546*/547548static int ps3_setup_dynamic_device(const struct ps3_repository_device *repo)549{550int result;551552switch (repo->dev_type) {553case PS3_DEV_TYPE_STOR_DISK:554result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_DISK);555556/* Some devices are not accessible from the Other OS lpar. */557if (result == -ENODEV) {558result = 0;559pr_debug("%s:%u: not accessible\n", __func__,560__LINE__);561}562563if (result)564pr_debug("%s:%u ps3_setup_storage_dev failed\n",565__func__, __LINE__);566break;567568case PS3_DEV_TYPE_STOR_ROM:569result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_ROM);570if (result)571pr_debug("%s:%u ps3_setup_storage_dev failed\n",572__func__, __LINE__);573break;574575case PS3_DEV_TYPE_STOR_FLASH:576result = ps3_setup_storage_dev(repo, PS3_MATCH_ID_STOR_FLASH);577if (result)578pr_debug("%s:%u ps3_setup_storage_dev failed\n",579__func__, __LINE__);580break;581582default:583result = 0;584pr_debug("%s:%u: unsupported dev_type %u\n", __func__, __LINE__,585repo->dev_type);586}587588return result;589}590591/**592* ps3_setup_static_device - Setup a static device from the repository593*/594595static int __init ps3_setup_static_device(const struct ps3_repository_device *repo)596{597int result;598599switch (repo->dev_type) {600case PS3_DEV_TYPE_SB_GELIC:601result = ps3_setup_gelic_device(repo);602if (result) {603pr_debug("%s:%d ps3_setup_gelic_device failed\n",604__func__, __LINE__);605}606break;607case PS3_DEV_TYPE_SB_USB:608609/* Each USB device has both an EHCI and an OHCI HC */610611result = ps3_setup_ehci_device(repo);612613if (result) {614pr_debug("%s:%d ps3_setup_ehci_device failed\n",615__func__, __LINE__);616}617618result = ps3_setup_ohci_device(repo);619620if (result) {621pr_debug("%s:%d ps3_setup_ohci_device failed\n",622__func__, __LINE__);623}624break;625626default:627return ps3_setup_dynamic_device(repo);628}629630return result;631}632633static void ps3_find_and_add_device(u64 bus_id, u64 dev_id)634{635struct ps3_repository_device repo;636int res;637unsigned int retries;638unsigned long rem;639640/*641* On some firmware versions (e.g. 1.90), the device may not show up642* in the repository immediately643*/644for (retries = 0; retries < 10; retries++) {645res = ps3_repository_find_device_by_id(&repo, bus_id, dev_id);646if (!res)647goto found;648649rem = msleep_interruptible(100);650if (rem)651break;652}653pr_warn("%s:%u: device %llu:%llu not found\n",654__func__, __LINE__, bus_id, dev_id);655return;656657found:658if (retries)659pr_debug("%s:%u: device %llu:%llu found after %u retries\n",660__func__, __LINE__, bus_id, dev_id, retries);661662ps3_setup_dynamic_device(&repo);663return;664}665666#define PS3_NOTIFICATION_DEV_ID ULONG_MAX667#define PS3_NOTIFICATION_INTERRUPT_ID 0668669struct ps3_notification_device {670struct ps3_system_bus_device sbd;671spinlock_t lock;672u64 tag;673u64 lv1_status;674struct rcuwait wait;675bool done;676};677678enum ps3_notify_type {679notify_device_ready = 0,680notify_region_probe = 1,681notify_region_update = 2,682};683684struct ps3_notify_cmd {685u64 operation_code; /* must be zero */686u64 event_mask; /* OR of 1UL << enum ps3_notify_type */687};688689struct ps3_notify_event {690u64 event_type; /* enum ps3_notify_type */691u64 bus_id;692u64 dev_id;693u64 dev_type;694u64 dev_port;695};696697static irqreturn_t ps3_notification_interrupt(int irq, void *data)698{699struct ps3_notification_device *dev = data;700int res;701u64 tag, status;702703spin_lock(&dev->lock);704res = lv1_storage_get_async_status(PS3_NOTIFICATION_DEV_ID, &tag,705&status);706if (tag != dev->tag)707pr_err("%s:%u: tag mismatch, got %llx, expected %llx\n",708__func__, __LINE__, tag, dev->tag);709710if (res) {711pr_err("%s:%u: res %d status 0x%llx\n", __func__, __LINE__, res,712status);713} else {714pr_debug("%s:%u: completed, status 0x%llx\n", __func__,715__LINE__, status);716dev->lv1_status = status;717dev->done = true;718rcuwait_wake_up(&dev->wait);719}720spin_unlock(&dev->lock);721return IRQ_HANDLED;722}723724static int ps3_notification_read_write(struct ps3_notification_device *dev,725u64 lpar, int write)726{727const char *op = str_write_read(write);728unsigned long flags;729int res;730731spin_lock_irqsave(&dev->lock, flags);732res = write ? lv1_storage_write(dev->sbd.dev_id, 0, 0, 1, 0, lpar,733&dev->tag)734: lv1_storage_read(dev->sbd.dev_id, 0, 0, 1, 0, lpar,735&dev->tag);736dev->done = false;737spin_unlock_irqrestore(&dev->lock, flags);738if (res) {739pr_err("%s:%u: %s failed %d\n", __func__, __LINE__, op, res);740return -EPERM;741}742pr_debug("%s:%u: notification %s issued\n", __func__, __LINE__, op);743744rcuwait_wait_event(&dev->wait, dev->done || kthread_should_stop(), TASK_IDLE);745746if (kthread_should_stop())747res = -EINTR;748749if (dev->lv1_status) {750pr_err("%s:%u: %s not completed, status 0x%llx\n", __func__,751__LINE__, op, dev->lv1_status);752return -EIO;753}754pr_debug("%s:%u: notification %s completed\n", __func__, __LINE__, op);755756return 0;757}758759static struct task_struct *probe_task;760761/**762* ps3_probe_thread - Background repository probing at system startup.763*764* This implementation only supports background probing on a single bus.765* It uses the hypervisor's storage device notification mechanism to wait until766* a storage device is ready. The device notification mechanism uses a767* pseudo device to asynchronously notify the guest when storage devices become768* ready. The notification device has a block size of 512 bytes.769*/770771static int ps3_probe_thread(void *data)772{773struct {774struct ps3_notification_device dev;775u8 buf[512];776} *local;777struct ps3_notify_cmd *notify_cmd;778struct ps3_notify_event *notify_event;779int res;780unsigned int irq;781u64 lpar;782783pr_debug(" -> %s:%u: kthread started\n", __func__, __LINE__);784785local = kzalloc(sizeof(*local), GFP_KERNEL);786if (!local)787return -ENOMEM;788789lpar = ps3_mm_phys_to_lpar(__pa(&local->buf));790notify_cmd = (struct ps3_notify_cmd *)&local->buf;791notify_event = (struct ps3_notify_event *)&local->buf;792793/* dummy system bus device */794local->dev.sbd.bus_id = (u64)data;795local->dev.sbd.dev_id = PS3_NOTIFICATION_DEV_ID;796local->dev.sbd.interrupt_id = PS3_NOTIFICATION_INTERRUPT_ID;797798res = lv1_open_device(local->dev.sbd.bus_id, local->dev.sbd.dev_id, 0);799if (res) {800pr_err("%s:%u: lv1_open_device failed %s\n", __func__,801__LINE__, ps3_result(res));802goto fail_free;803}804805res = ps3_sb_event_receive_port_setup(&local->dev.sbd,806PS3_BINDING_CPU_ANY, &irq);807if (res) {808pr_err("%s:%u: ps3_sb_event_receive_port_setup failed %d\n",809__func__, __LINE__, res);810goto fail_close_device;811}812813spin_lock_init(&local->dev.lock);814rcuwait_init(&local->dev.wait);815816res = request_irq(irq, ps3_notification_interrupt, 0,817"ps3_notification", &local->dev);818if (res) {819pr_err("%s:%u: request_irq failed %d\n", __func__, __LINE__,820res);821goto fail_sb_event_receive_port_destroy;822}823824/* Setup and write the request for device notification. */825notify_cmd->operation_code = 0; /* must be zero */826notify_cmd->event_mask = 1UL << notify_region_probe;827828res = ps3_notification_read_write(&local->dev, lpar, 1);829if (res)830goto fail_free_irq;831832set_freezable();833/* Loop here processing the requested notification events. */834do {835try_to_freeze();836837memset(notify_event, 0, sizeof(*notify_event));838839res = ps3_notification_read_write(&local->dev, lpar, 0);840if (res)841break;842843pr_debug("%s:%u: notify event type 0x%llx bus id %llu dev id %llu"844" type %llu port %llu\n", __func__, __LINE__,845notify_event->event_type, notify_event->bus_id,846notify_event->dev_id, notify_event->dev_type,847notify_event->dev_port);848849if (notify_event->event_type != notify_region_probe ||850notify_event->bus_id != local->dev.sbd.bus_id) {851pr_warn("%s:%u: bad notify_event: event %llu, dev_id %llu, dev_type %llu\n",852__func__, __LINE__, notify_event->event_type,853notify_event->dev_id, notify_event->dev_type);854continue;855}856857ps3_find_and_add_device(local->dev.sbd.bus_id,858notify_event->dev_id);859860} while (!kthread_should_stop());861862fail_free_irq:863free_irq(irq, &local->dev);864fail_sb_event_receive_port_destroy:865ps3_sb_event_receive_port_destroy(&local->dev.sbd, irq);866fail_close_device:867lv1_close_device(local->dev.sbd.bus_id, local->dev.sbd.dev_id);868fail_free:869kfree(local);870871probe_task = NULL;872873pr_debug(" <- %s:%u: kthread finished\n", __func__, __LINE__);874875return 0;876}877878/**879* ps3_stop_probe_thread - Stops the background probe thread.880*881*/882883static int ps3_stop_probe_thread(struct notifier_block *nb, unsigned long code,884void *data)885{886if (probe_task)887kthread_stop(probe_task);888return 0;889}890891static struct notifier_block nb = {892.notifier_call = ps3_stop_probe_thread893};894895/**896* ps3_start_probe_thread - Starts the background probe thread.897*898*/899900static int __init ps3_start_probe_thread(enum ps3_bus_type bus_type)901{902int result;903struct task_struct *task;904struct ps3_repository_device repo;905906pr_debug(" -> %s:%d\n", __func__, __LINE__);907908memset(&repo, 0, sizeof(repo));909910repo.bus_type = bus_type;911912result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index);913914if (result) {915printk(KERN_ERR "%s: Cannot find bus (%d)\n", __func__, result);916return -ENODEV;917}918919result = ps3_repository_read_bus_id(repo.bus_index, &repo.bus_id);920921if (result) {922printk(KERN_ERR "%s: read_bus_id failed %d\n", __func__,923result);924return -ENODEV;925}926927task = kthread_run(ps3_probe_thread, (void *)repo.bus_id,928"ps3-probe-%u", bus_type);929930if (IS_ERR(task)) {931result = PTR_ERR(task);932printk(KERN_ERR "%s: kthread_run failed %d\n", __func__,933result);934return result;935}936937probe_task = task;938register_reboot_notifier(&nb);939940pr_debug(" <- %s:%d\n", __func__, __LINE__);941return 0;942}943944/**945* ps3_register_devices - Probe the system and register devices found.946*947* A device_initcall() routine.948*/949950static int __init ps3_register_devices(void)951{952int result;953954if (!firmware_has_feature(FW_FEATURE_PS3_LV1))955return -ENODEV;956957pr_debug(" -> %s:%d\n", __func__, __LINE__);958959/* ps3_repository_dump_bus_info(); */960961result = ps3_start_probe_thread(PS3_BUS_TYPE_STORAGE);962963ps3_register_vuart_devices();964965ps3_register_graphics_devices();966967ps3_repository_find_devices(PS3_BUS_TYPE_SB, ps3_setup_static_device);968969ps3_register_sound_devices();970971ps3_register_lpm_devices();972973ps3_register_ramdisk_device();974975pr_debug(" <- %s:%d\n", __func__, __LINE__);976return 0;977}978979device_initcall(ps3_register_devices);980981982