File Index
Files and directories
Sign in
FILE

system-bus.c

File preview with syntax highlighting.

linux-6.19.14/arch/powerpc/platforms/ps3/system-bus.c C
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 *  PS3 system bus driver.
  4 *
  5 *  Copyright (C) 2006 Sony Computer Entertainment Inc.
  6 *  Copyright 2006 Sony Corp.
  7 */
  8
  9#include <linux/kernel.h>
 10#include <linux/init.h>
 11#include <linux/export.h>
 12#include <linux/dma-map-ops.h>
 13#include <linux/err.h>
 14#include <linux/slab.h>
 15
 16#include <asm/udbg.h>
 17#include <asm/lv1call.h>
 18#include <asm/firmware.h>
 19#include <asm/cell-regs.h>
 20
 21#include "platform.h"
 22
 23static struct device ps3_system_bus = {
 24	.init_name = "ps3_system",
 25};
 26
 27/* FIXME: need device usage counters! */
 28static struct {
 29	struct mutex mutex;
 30	int sb_11; /* usb 0 */
 31	int sb_12; /* usb 0 */
 32	int gpu;
 33} usage_hack;
 34
 35static int ps3_is_device(struct ps3_system_bus_device *dev, u64 bus_id,
 36			 u64 dev_id)
 37{
 38	return dev->bus_id == bus_id && dev->dev_id == dev_id;
 39}
 40
 41static int ps3_open_hv_device_sb(struct ps3_system_bus_device *dev)
 42{
 43	int result;
 44
 45	BUG_ON(!dev->bus_id);
 46	mutex_lock(&usage_hack.mutex);
 47
 48	if (ps3_is_device(dev, 1, 1)) {
 49		usage_hack.sb_11++;
 50		if (usage_hack.sb_11 > 1) {
 51			result = 0;
 52			goto done;
 53		}
 54	}
 55
 56	if (ps3_is_device(dev, 1, 2)) {
 57		usage_hack.sb_12++;
 58		if (usage_hack.sb_12 > 1) {
 59			result = 0;
 60			goto done;
 61		}
 62	}
 63
 64	result = lv1_open_device(dev->bus_id, dev->dev_id, 0);
 65
 66	if (result) {
 67		pr_warn("%s:%d: lv1_open_device dev=%u.%u(%s) failed: %s\n",
 68			__func__, __LINE__, dev->match_id, dev->match_sub_id,
 69			dev_name(&dev->core), ps3_result(result));
 70		result = -EPERM;
 71	}
 72
 73done:
 74	mutex_unlock(&usage_hack.mutex);
 75	return result;
 76}
 77
 78static int ps3_close_hv_device_sb(struct ps3_system_bus_device *dev)
 79{
 80	int result;
 81
 82	BUG_ON(!dev->bus_id);
 83	mutex_lock(&usage_hack.mutex);
 84
 85	if (ps3_is_device(dev, 1, 1)) {
 86		usage_hack.sb_11--;
 87		if (usage_hack.sb_11) {
 88			result = 0;
 89			goto done;
 90		}
 91	}
 92
 93	if (ps3_is_device(dev, 1, 2)) {
 94		usage_hack.sb_12--;
 95		if (usage_hack.sb_12) {
 96			result = 0;
 97			goto done;
 98		}
 99	}
100
101	result = lv1_close_device(dev->bus_id, dev->dev_id);
102	BUG_ON(result);
103
104done:
105	mutex_unlock(&usage_hack.mutex);
106	return result;
107}
108
109static int ps3_open_hv_device_gpu(struct ps3_system_bus_device *dev)
110{
111	int result;
112
113	mutex_lock(&usage_hack.mutex);
114
115	usage_hack.gpu++;
116	if (usage_hack.gpu > 1) {
117		result = 0;
118		goto done;
119	}
120
121	result = lv1_gpu_open(0);
122
123	if (result) {
124		pr_warn("%s:%d: lv1_gpu_open failed: %s\n", __func__,
125			__LINE__, ps3_result(result));
126			result = -EPERM;
127	}
128
129done:
130	mutex_unlock(&usage_hack.mutex);
131	return result;
132}
133
134static int ps3_close_hv_device_gpu(struct ps3_system_bus_device *dev)
135{
136	int result;
137
138	mutex_lock(&usage_hack.mutex);
139
140	usage_hack.gpu--;
141	if (usage_hack.gpu) {
142		result = 0;
143		goto done;
144	}
145
146	result = lv1_gpu_close();
147	BUG_ON(result);
148
149done:
150	mutex_unlock(&usage_hack.mutex);
151	return result;
152}
153
154int ps3_open_hv_device(struct ps3_system_bus_device *dev)
155{
156	BUG_ON(!dev);
157	pr_debug("%s:%d: match_id: %u\n", __func__, __LINE__, dev->match_id);
158
159	switch (dev->match_id) {
160	case PS3_MATCH_ID_EHCI:
161	case PS3_MATCH_ID_OHCI:
162	case PS3_MATCH_ID_GELIC:
163	case PS3_MATCH_ID_STOR_DISK:
164	case PS3_MATCH_ID_STOR_ROM:
165	case PS3_MATCH_ID_STOR_FLASH:
166		return ps3_open_hv_device_sb(dev);
167
168	case PS3_MATCH_ID_SOUND:
169	case PS3_MATCH_ID_GPU:
170		return ps3_open_hv_device_gpu(dev);
171
172	case PS3_MATCH_ID_AV_SETTINGS:
173	case PS3_MATCH_ID_SYSTEM_MANAGER:
174		pr_debug("%s:%d: unsupported match_id: %u\n", __func__,
175			__LINE__, dev->match_id);
176		pr_debug("%s:%d: bus_id: %llu\n", __func__, __LINE__,
177			dev->bus_id);
178		BUG();
179		return -EINVAL;
180
181	default:
182		break;
183	}
184
185	pr_debug("%s:%d: unknown match_id: %u\n", __func__, __LINE__,
186		dev->match_id);
187	BUG();
188	return -ENODEV;
189}
190EXPORT_SYMBOL_GPL(ps3_open_hv_device);
191
192int ps3_close_hv_device(struct ps3_system_bus_device *dev)
193{
194	BUG_ON(!dev);
195	pr_debug("%s:%d: match_id: %u\n", __func__, __LINE__, dev->match_id);
196
197	switch (dev->match_id) {
198	case PS3_MATCH_ID_EHCI:
199	case PS3_MATCH_ID_OHCI:
200	case PS3_MATCH_ID_GELIC:
201	case PS3_MATCH_ID_STOR_DISK:
202	case PS3_MATCH_ID_STOR_ROM:
203	case PS3_MATCH_ID_STOR_FLASH:
204		return ps3_close_hv_device_sb(dev);
205
206	case PS3_MATCH_ID_SOUND:
207	case PS3_MATCH_ID_GPU:
208		return ps3_close_hv_device_gpu(dev);
209
210	case PS3_MATCH_ID_AV_SETTINGS:
211	case PS3_MATCH_ID_SYSTEM_MANAGER:
212		pr_debug("%s:%d: unsupported match_id: %u\n", __func__,
213			__LINE__, dev->match_id);
214		pr_debug("%s:%d: bus_id: %llu\n", __func__, __LINE__,
215			dev->bus_id);
216		BUG();
217		return -EINVAL;
218
219	default:
220		break;
221	}
222
223	pr_debug("%s:%d: unknown match_id: %u\n", __func__, __LINE__,
224		dev->match_id);
225	BUG();
226	return -ENODEV;
227}
228EXPORT_SYMBOL_GPL(ps3_close_hv_device);
229
230#define dump_mmio_region(_a) _dump_mmio_region(_a, __func__, __LINE__)
231static void _dump_mmio_region(const struct ps3_mmio_region* r,
232	const char* func, int line)
233{
234	pr_debug("%s:%d: dev       %llu:%llu\n", func, line, r->dev->bus_id,
235		r->dev->dev_id);
236	pr_debug("%s:%d: bus_addr  %lxh\n", func, line, r->bus_addr);
237	pr_debug("%s:%d: len       %lxh\n", func, line, r->len);
238	pr_debug("%s:%d: lpar_addr %lxh\n", func, line, r->lpar_addr);
239}
240
241static int ps3_sb_mmio_region_create(struct ps3_mmio_region *r)
242{
243	int result;
244	u64 lpar_addr;
245
246	result = lv1_map_device_mmio_region(r->dev->bus_id, r->dev->dev_id,
247		r->bus_addr, r->len, r->page_size, &lpar_addr);
248	r->lpar_addr = lpar_addr;
249
250	if (result) {
251		pr_debug("%s:%d: lv1_map_device_mmio_region failed: %s\n",
252			__func__, __LINE__, ps3_result(result));
253		r->lpar_addr = 0;
254	}
255
256	dump_mmio_region(r);
257	return result;
258}
259
260static int ps3_ioc0_mmio_region_create(struct ps3_mmio_region *r)
261{
262	/* device specific; do nothing currently */
263	return 0;
264}
265
266int ps3_mmio_region_create(struct ps3_mmio_region *r)
267{
268	return r->mmio_ops->create(r);
269}
270EXPORT_SYMBOL_GPL(ps3_mmio_region_create);
271
272static int ps3_sb_free_mmio_region(struct ps3_mmio_region *r)
273{
274	int result;
275
276	dump_mmio_region(r);
277	result = lv1_unmap_device_mmio_region(r->dev->bus_id, r->dev->dev_id,
278		r->lpar_addr);
279
280	if (result)
281		pr_debug("%s:%d: lv1_unmap_device_mmio_region failed: %s\n",
282			__func__, __LINE__, ps3_result(result));
283
284	r->lpar_addr = 0;
285	return result;
286}
287
288static int ps3_ioc0_free_mmio_region(struct ps3_mmio_region *r)
289{
290	/* device specific; do nothing currently */
291	return 0;
292}
293
294
295int ps3_free_mmio_region(struct ps3_mmio_region *r)
296{
297	return r->mmio_ops->free(r);
298}
299
300EXPORT_SYMBOL_GPL(ps3_free_mmio_region);
301
302static const struct ps3_mmio_region_ops ps3_mmio_sb_region_ops = {
303	.create = ps3_sb_mmio_region_create,
304	.free = ps3_sb_free_mmio_region
305};
306
307static const struct ps3_mmio_region_ops ps3_mmio_ioc0_region_ops = {
308	.create = ps3_ioc0_mmio_region_create,
309	.free = ps3_ioc0_free_mmio_region
310};
311
312int ps3_mmio_region_init(struct ps3_system_bus_device *dev,
313	struct ps3_mmio_region *r, unsigned long bus_addr, unsigned long len,
314	enum ps3_mmio_page_size page_size)
315{
316	r->dev = dev;
317	r->bus_addr = bus_addr;
318	r->len = len;
319	r->page_size = page_size;
320	switch (dev->dev_type) {
321	case PS3_DEVICE_TYPE_SB:
322		r->mmio_ops = &ps3_mmio_sb_region_ops;
323		break;
324	case PS3_DEVICE_TYPE_IOC0:
325		r->mmio_ops = &ps3_mmio_ioc0_region_ops;
326		break;
327	default:
328		BUG();
329		return -EINVAL;
330	}
331	return 0;
332}
333EXPORT_SYMBOL_GPL(ps3_mmio_region_init);
334
335static int ps3_system_bus_match(struct device *_dev,
336	const struct device_driver *_drv)
337{
338	int result;
339	const struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv);
340	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
341
342	if (!dev->match_sub_id)
343		result = dev->match_id == drv->match_id;
344	else
345		result = dev->match_sub_id == drv->match_sub_id &&
346			dev->match_id == drv->match_id;
347
348	if (result)
349		pr_info("%s:%d: dev=%u.%u(%s), drv=%u.%u(%s): match\n",
350			__func__, __LINE__,
351			dev->match_id, dev->match_sub_id, dev_name(&dev->core),
352			drv->match_id, drv->match_sub_id, drv->core.name);
353	else
354		pr_debug("%s:%d: dev=%u.%u(%s), drv=%u.%u(%s): miss\n",
355			__func__, __LINE__,
356			dev->match_id, dev->match_sub_id, dev_name(&dev->core),
357			drv->match_id, drv->match_sub_id, drv->core.name);
358
359	return result;
360}
361
362static int ps3_system_bus_probe(struct device *_dev)
363{
364	int result = 0;
365	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
366	struct ps3_system_bus_driver *drv;
367
368	BUG_ON(!dev);
369	dev_dbg(_dev, "%s:%d\n", __func__, __LINE__);
370
371	drv = ps3_system_bus_dev_to_system_bus_drv(dev);
372	BUG_ON(!drv);
373
374	if (drv->probe)
375		result = drv->probe(dev);
376	else
377		pr_debug("%s:%d: %s no probe method\n", __func__, __LINE__,
378			dev_name(&dev->core));
379
380	pr_debug(" <- %s:%d: %s\n", __func__, __LINE__, dev_name(&dev->core));
381	return result;
382}
383
384static void ps3_system_bus_remove(struct device *_dev)
385{
386	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
387	struct ps3_system_bus_driver *drv;
388
389	BUG_ON(!dev);
390	dev_dbg(_dev, "%s:%d\n", __func__, __LINE__);
391
392	drv = ps3_system_bus_dev_to_system_bus_drv(dev);
393	BUG_ON(!drv);
394
395	if (drv->remove)
396		drv->remove(dev);
397	else
398		dev_dbg(&dev->core, "%s:%d %s: no remove method\n",
399			__func__, __LINE__, drv->core.name);
400
401	pr_debug(" <- %s:%d: %s\n", __func__, __LINE__, dev_name(&dev->core));
402}
403
404static void ps3_system_bus_shutdown(struct device *_dev)
405{
406	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
407	struct ps3_system_bus_driver *drv;
408
409	BUG_ON(!dev);
410
411	dev_dbg(&dev->core, " -> %s:%d: match_id %d\n", __func__, __LINE__,
412		dev->match_id);
413
414	if (!dev->core.driver) {
415		dev_dbg(&dev->core, "%s:%d: no driver bound\n", __func__,
416			__LINE__);
417		return;
418	}
419
420	drv = ps3_system_bus_dev_to_system_bus_drv(dev);
421
422	BUG_ON(!drv);
423
424	dev_dbg(&dev->core, "%s:%d: %s -> %s\n", __func__, __LINE__,
425		dev_name(&dev->core), drv->core.name);
426
427	if (drv->shutdown)
428		drv->shutdown(dev);
429	else if (drv->remove) {
430		dev_dbg(&dev->core, "%s:%d %s: no shutdown, calling remove\n",
431			__func__, __LINE__, drv->core.name);
432		drv->remove(dev);
433	} else {
434		dev_dbg(&dev->core, "%s:%d %s: no shutdown method\n",
435			__func__, __LINE__, drv->core.name);
436		BUG();
437	}
438
439	dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
440}
441
442static int ps3_system_bus_uevent(const struct device *_dev, struct kobj_uevent_env *env)
443{
444	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
445
446	if (add_uevent_var(env, "MODALIAS=ps3:%d:%d", dev->match_id,
447			   dev->match_sub_id))
448		return -ENOMEM;
449	return 0;
450}
451
452static ssize_t modalias_show(struct device *_dev, struct device_attribute *a,
453	char *buf)
454{
455	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
456
457	return sysfs_emit(buf, "ps3:%d:%d\n", dev->match_id,
458			  dev->match_sub_id);
459}
460static DEVICE_ATTR_RO(modalias);
461
462static struct attribute *ps3_system_bus_dev_attrs[] = {
463	&dev_attr_modalias.attr,
464	NULL,
465};
466ATTRIBUTE_GROUPS(ps3_system_bus_dev);
467
468static const struct bus_type ps3_system_bus_type = {
469	.name = "ps3_system_bus",
470	.match = ps3_system_bus_match,
471	.uevent = ps3_system_bus_uevent,
472	.probe = ps3_system_bus_probe,
473	.remove = ps3_system_bus_remove,
474	.shutdown = ps3_system_bus_shutdown,
475	.dev_groups = ps3_system_bus_dev_groups,
476};
477
478static int __init ps3_system_bus_init(void)
479{
480	int result;
481
482	if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
483		return -ENODEV;
484
485	pr_debug(" -> %s:%d\n", __func__, __LINE__);
486
487	mutex_init(&usage_hack.mutex);
488
489	result = device_register(&ps3_system_bus);
490	BUG_ON(result);
491
492	result = bus_register(&ps3_system_bus_type);
493	BUG_ON(result);
494
495	pr_debug(" <- %s:%d\n", __func__, __LINE__);
496	return result;
497}
498
499core_initcall(ps3_system_bus_init);
500
501/* Allocates a contiguous real buffer and creates mappings over it.
502 * Returns the virtual address of the buffer and sets dma_handle
503 * to the dma address (mapping) of the first page.
504 */
505static void * ps3_alloc_coherent(struct device *_dev, size_t size,
506				 dma_addr_t *dma_handle, gfp_t flag,
507				 unsigned long attrs)
508{
509	int result;
510	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
511	unsigned long virt_addr;
512
513	flag &= ~(__GFP_DMA | __GFP_HIGHMEM);
514	flag |= __GFP_ZERO;
515
516	virt_addr = __get_free_pages(flag, get_order(size));
517
518	if (!virt_addr) {
519		pr_debug("%s:%d: get_free_pages failed\n", __func__, __LINE__);
520		goto clean_none;
521	}
522
523	result = ps3_dma_map(dev->d_region, virt_addr, size, dma_handle,
524			     CBE_IOPTE_PP_W | CBE_IOPTE_PP_R |
525			     CBE_IOPTE_SO_RW | CBE_IOPTE_M);
526
527	if (result) {
528		pr_debug("%s:%d: ps3_dma_map failed (%d)\n",
529			__func__, __LINE__, result);
530		BUG_ON("check region type");
531		goto clean_alloc;
532	}
533
534	return (void*)virt_addr;
535
536clean_alloc:
537	free_pages(virt_addr, get_order(size));
538clean_none:
539	dma_handle = NULL;
540	return NULL;
541}
542
543static void ps3_free_coherent(struct device *_dev, size_t size, void *vaddr,
544			      dma_addr_t dma_handle, unsigned long attrs)
545{
546	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
547
548	ps3_dma_unmap(dev->d_region, dma_handle, size);
549	free_pages((unsigned long)vaddr, get_order(size));
550}
551
552/* Creates TCEs for a user provided buffer.  The user buffer must be
553 * contiguous real kernel storage (not vmalloc).  The address passed here
554 * is physical address to that hat page. The dma_addr_t returned will point
555 * to the same byte within the page as was passed in.
556 */
557
558static dma_addr_t ps3_sb_map_phys(struct device *_dev, phys_addr_t phys,
559	size_t size, enum dma_data_direction direction, unsigned long attrs)
560{
561	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
562	int result;
563	dma_addr_t bus_addr;
564	void *ptr = phys_to_virt(phys);
565
566	if (unlikely(attrs & DMA_ATTR_MMIO))
567		return DMA_MAPPING_ERROR;
568
569	result = ps3_dma_map(dev->d_region, (unsigned long)ptr, size,
570			     &bus_addr,
571			     CBE_IOPTE_PP_R | CBE_IOPTE_PP_W |
572			     CBE_IOPTE_SO_RW | CBE_IOPTE_M);
573
574	if (result) {
575		pr_debug("%s:%d: ps3_dma_map failed (%d)\n",
576			__func__, __LINE__, result);
577	}
578
579	return bus_addr;
580}
581
582static dma_addr_t ps3_ioc0_map_phys(struct device *_dev, phys_addr_t phys,
583				    size_t size,
584				    enum dma_data_direction direction,
585				    unsigned long attrs)
586{
587	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
588	int result;
589	dma_addr_t bus_addr;
590	u64 iopte_flag;
591	void *ptr = phys_to_virt(phys);
592
593	if (unlikely(attrs & DMA_ATTR_MMIO))
594		return DMA_MAPPING_ERROR;
595
596	iopte_flag = CBE_IOPTE_M;
597	switch (direction) {
598	case DMA_BIDIRECTIONAL:
599		iopte_flag |= CBE_IOPTE_PP_R | CBE_IOPTE_PP_W | CBE_IOPTE_SO_RW;
600		break;
601	case DMA_TO_DEVICE:
602		iopte_flag |= CBE_IOPTE_PP_R | CBE_IOPTE_SO_R;
603		break;
604	case DMA_FROM_DEVICE:
605		iopte_flag |= CBE_IOPTE_PP_W | CBE_IOPTE_SO_RW;
606		break;
607	default:
608		/* not happened */
609		BUG();
610	}
611	result = ps3_dma_map(dev->d_region, (unsigned long)ptr, size,
612			     &bus_addr, iopte_flag);
613
614	if (result) {
615		pr_debug("%s:%d: ps3_dma_map failed (%d)\n",
616			__func__, __LINE__, result);
617	}
618	return bus_addr;
619}
620
621static void ps3_unmap_phys(struct device *_dev, dma_addr_t dma_addr,
622	size_t size, enum dma_data_direction direction, unsigned long attrs)
623{
624	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
625	int result;
626
627	result = ps3_dma_unmap(dev->d_region, dma_addr, size);
628
629	if (result) {
630		pr_debug("%s:%d: ps3_dma_unmap failed (%d)\n",
631			__func__, __LINE__, result);
632	}
633}
634
635static int ps3_sb_map_sg(struct device *_dev, struct scatterlist *sgl,
636	int nents, enum dma_data_direction direction, unsigned long attrs)
637{
638#if defined(CONFIG_PS3_DYNAMIC_DMA)
639	BUG_ON("do");
640	return -EPERM;
641#else
642	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
643	struct scatterlist *sg;
644	int i;
645
646	for_each_sg(sgl, sg, nents, i) {
647		int result = ps3_dma_map(dev->d_region, sg_phys(sg),
648					sg->length, &sg->dma_address, 0);
649
650		if (result) {
651			pr_debug("%s:%d: ps3_dma_map failed (%d)\n",
652				__func__, __LINE__, result);
653			return -EINVAL;
654		}
655
656		sg->dma_length = sg->length;
657	}
658
659	return nents;
660#endif
661}
662
663static int ps3_ioc0_map_sg(struct device *_dev, struct scatterlist *sg,
664			   int nents,
665			   enum dma_data_direction direction,
666			   unsigned long attrs)
667{
668	BUG();
669	return -EINVAL;
670}
671
672static void ps3_sb_unmap_sg(struct device *_dev, struct scatterlist *sg,
673	int nents, enum dma_data_direction direction, unsigned long attrs)
674{
675#if defined(CONFIG_PS3_DYNAMIC_DMA)
676	BUG_ON("do");
677#endif
678}
679
680static void ps3_ioc0_unmap_sg(struct device *_dev, struct scatterlist *sg,
681			    int nents, enum dma_data_direction direction,
682			    unsigned long attrs)
683{
684	BUG();
685}
686
687static int ps3_dma_supported(struct device *_dev, u64 mask)
688{
689	return mask >= DMA_BIT_MASK(32);
690}
691
692static const struct dma_map_ops ps3_sb_dma_ops = {
693	.alloc = ps3_alloc_coherent,
694	.free = ps3_free_coherent,
695	.map_sg = ps3_sb_map_sg,
696	.unmap_sg = ps3_sb_unmap_sg,
697	.dma_supported = ps3_dma_supported,
698	.map_phys = ps3_sb_map_phys,
699	.unmap_phys = ps3_unmap_phys,
700	.mmap = dma_common_mmap,
701	.get_sgtable = dma_common_get_sgtable,
702	.alloc_pages_op = dma_common_alloc_pages,
703	.free_pages = dma_common_free_pages,
704};
705
706static const struct dma_map_ops ps3_ioc0_dma_ops = {
707	.alloc = ps3_alloc_coherent,
708	.free = ps3_free_coherent,
709	.map_sg = ps3_ioc0_map_sg,
710	.unmap_sg = ps3_ioc0_unmap_sg,
711	.dma_supported = ps3_dma_supported,
712	.map_phys = ps3_ioc0_map_phys,
713	.unmap_phys = ps3_unmap_phys,
714	.mmap = dma_common_mmap,
715	.get_sgtable = dma_common_get_sgtable,
716	.alloc_pages_op = dma_common_alloc_pages,
717	.free_pages = dma_common_free_pages,
718};
719
720/**
721 * ps3_system_bus_release_device - remove a device from the system bus
722 */
723
724static void ps3_system_bus_release_device(struct device *_dev)
725{
726	struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev);
727	kfree(dev);
728}
729
730/**
731 * ps3_system_bus_device_register - add a device to the system bus
732 *
733 * ps3_system_bus_device_register() expects the dev object to be allocated
734 * dynamically by the caller.  The system bus takes ownership of the dev
735 * object and frees the object in ps3_system_bus_release_device().
736 */
737
738int ps3_system_bus_device_register(struct ps3_system_bus_device *dev)
739{
740	int result;
741	static unsigned int dev_ioc0_count;
742	static unsigned int dev_sb_count;
743	static unsigned int dev_vuart_count;
744	static unsigned int dev_lpm_count;
745
746	if (!dev->core.parent)
747		dev->core.parent = &ps3_system_bus;
748	dev->core.bus = &ps3_system_bus_type;
749	dev->core.release = ps3_system_bus_release_device;
750
751	switch (dev->dev_type) {
752	case PS3_DEVICE_TYPE_IOC0:
753		dev->core.dma_ops = &ps3_ioc0_dma_ops;
754		dev_set_name(&dev->core, "ioc0_%02x", ++dev_ioc0_count);
755		break;
756	case PS3_DEVICE_TYPE_SB:
757		dev->core.dma_ops = &ps3_sb_dma_ops;
758		dev_set_name(&dev->core, "sb_%02x", ++dev_sb_count);
759
760		break;
761	case PS3_DEVICE_TYPE_VUART:
762		dev_set_name(&dev->core, "vuart_%02x", ++dev_vuart_count);
763		break;
764	case PS3_DEVICE_TYPE_LPM:
765		dev_set_name(&dev->core, "lpm_%02x", ++dev_lpm_count);
766		break;
767	default:
768		BUG();
769	}
770
771	dev->core.of_node = NULL;
772	set_dev_node(&dev->core, 0);
773
774	pr_debug("%s:%d add %s\n", __func__, __LINE__, dev_name(&dev->core));
775
776	result = device_register(&dev->core);
777	return result;
778}
779
780EXPORT_SYMBOL_GPL(ps3_system_bus_device_register);
781
782int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv)
783{
784	int result;
785
786	pr_debug(" -> %s:%d: %s\n", __func__, __LINE__, drv->core.name);
787
788	if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
789		return -ENODEV;
790
791	drv->core.bus = &ps3_system_bus_type;
792
793	result = driver_register(&drv->core);
794	pr_debug(" <- %s:%d: %s\n", __func__, __LINE__, drv->core.name);
795	return result;
796}
797
798EXPORT_SYMBOL_GPL(ps3_system_bus_driver_register);
799
800void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv)
801{
802	pr_debug(" -> %s:%d: %s\n", __func__, __LINE__, drv->core.name);
803	driver_unregister(&drv->core);
804	pr_debug(" <- %s:%d: %s\n", __func__, __LINE__, drv->core.name);
805}
806
807EXPORT_SYMBOL_GPL(ps3_system_bus_driver_unregister);
~/ Read-only file preview.