linux/drivers/block/z2ram.c
Linus Torvalds 685f7e4f16 powerpc updates for 4.20
Notable changes:
 
  - A large series to rewrite our SLB miss handling, replacing a lot of fairly
    complicated asm with much fewer lines of C.
 
  - Following on from that, we now maintain a cache of SLB entries for each
    process and preload them on context switch. Leading to a 27% speedup for our
    context switch benchmark on Power9.
 
  - Improvements to our handling of SLB multi-hit errors. We now print more debug
    information when they occur, and try to continue running by flushing the SLB
    and reloading, rather than treating them as fatal.
 
  - Enable THP migration on 64-bit Book3S machines (eg. Power7/8/9).
 
  - Add support for physical memory up to 2PB in the linear mapping on 64-bit
    Book3S. We only support up to 512TB as regular system memory, otherwise the
    percpu allocator runs out of vmalloc space.
 
  - Add stack protector support for 32 and 64-bit, with a per-task canary.
 
  - Add support for PTRACE_SYSEMU and PTRACE_SYSEMU_SINGLESTEP.
 
  - Support recognising "big cores" on Power9, where two SMT4 cores are presented
    to us as a single SMT8 core.
 
  - A large series to cleanup some of our ioremap handling and PTE flags.
 
  - Add a driver for the PAPR SCM (storage class memory) interface, allowing
    guests to operate on SCM devices (acked by Dan).
 
  - Changes to our ftrace code to handle very large kernels, where we need to use
    a trampoline to get to ftrace_caller().
 
 Many other smaller enhancements and cleanups.
 
 Thanks to:
   Alan Modra, Alistair Popple, Aneesh Kumar K.V, Anton Blanchard, Aravinda
   Prasad, Bartlomiej Zolnierkiewicz, Benjamin Herrenschmidt, Breno Leitao,
   Cédric Le Goater, Christophe Leroy, Christophe Lombard, Dan Carpenter, Daniel
   Axtens, Finn Thain, Gautham R. Shenoy, Gustavo Romero, Haren Myneni, Hari
   Bathini, Jia Hongtao, Joel Stanley, John Allen, Laurent Dufour, Madhavan
   Srinivasan, Mahesh Salgaonkar, Mark Hairgrove, Masahiro Yamada, Michael
   Bringmann, Michael Neuling, Michal Suchanek, Murilo Opsfelder Araujo, Nathan
   Fontenot, Naveen N. Rao, Nicholas Piggin, Nick Desaulniers, Oliver O'Halloran,
   Paul Mackerras, Petr Vorel, Rashmica Gupta, Reza Arbab, Rob Herring, Sam
   Bobroff, Samuel Mendoza-Jonas, Scott Wood, Stan Johnson, Stephen Rothwell,
   Stewart Smith, Suraj Jitindar Singh, Tyrel Datwyler, Vaibhav Jain, Vasant
   Hegde, YueHaibing, zhong jiang,
 -----BEGIN PGP SIGNATURE-----
 
 iQIcBAABAgAGBQJb01vTAAoJEFHr6jzI4aWADsEP/jqL3+2qxs098ra80tpXCpXJ
 tgXCosEs4b35sGtyHeUWZZZfWXeisaPAIlP8zTx1n50HACZduDYRAl0Ew9XB7Xdw
 enDHRVccD21FsmHBOx/Ii1rVJlovWlj6EQCWHKeZmNjeRoFuClVZ7CYmf+mBifKR
 sw2Db2fKA/59wMTq2zIMy5pqYgqlAs4jTWS6uN5hKPoBmO/82ARnNG+qgLuloD3Z
 O8zSDM9QQ7PpuyDgTjO9SAo2YjmEfXlEG6cOCCejsU3DMctaEAK5PUZ+blsHYHBH
 BYZYKs/x4pcw0SO41GtTh0M2YqDYBVuBIpRw8lLZap97Xo9ucSkAm5WD3rGxk4CY
 YeZKEPUql6MHN3+DKl8mx2F0V+Et/tio2HNqc9KReR1tfoolZAbe+SFZHfgmc/Rq
 RD9nnG8KRd4K2K1BTqpkTmI1EtE7jPtPJPSV8gMGhgL/N5vPmH3mql/qyOtYx48E
 6/hPzWESgs16VRZ/opLh8VvjlY1HBDODQhehhhl+o23/Vb8qEgRf8Uqhq50rQW1H
 EeOqyyYQ90txSU31Sgy1kQkvOgIFAsBObWT1ZCJ3RbfGbB4/tdEAvZqTZRlXo2OY
 7P0Sqcw/9Le5eJkHIlLtBv0TF7y1OYemCbLgRQzFlcRP+UKtYyg8eFnFjqbPEEmP
 ulwhn/BfFVSgaYKQ503u
 =I0pj
 -----END PGP SIGNATURE-----

Merge tag 'powerpc-4.20-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux

Pull powerpc updates from Michael Ellerman:
 "Notable changes:

   - A large series to rewrite our SLB miss handling, replacing a lot of
     fairly complicated asm with much fewer lines of C.

   - Following on from that, we now maintain a cache of SLB entries for
     each process and preload them on context switch. Leading to a 27%
     speedup for our context switch benchmark on Power9.

   - Improvements to our handling of SLB multi-hit errors. We now print
     more debug information when they occur, and try to continue running
     by flushing the SLB and reloading, rather than treating them as
     fatal.

   - Enable THP migration on 64-bit Book3S machines (eg. Power7/8/9).

   - Add support for physical memory up to 2PB in the linear mapping on
     64-bit Book3S. We only support up to 512TB as regular system
     memory, otherwise the percpu allocator runs out of vmalloc space.

   - Add stack protector support for 32 and 64-bit, with a per-task
     canary.

   - Add support for PTRACE_SYSEMU and PTRACE_SYSEMU_SINGLESTEP.

   - Support recognising "big cores" on Power9, where two SMT4 cores are
     presented to us as a single SMT8 core.

   - A large series to cleanup some of our ioremap handling and PTE
     flags.

   - Add a driver for the PAPR SCM (storage class memory) interface,
     allowing guests to operate on SCM devices (acked by Dan).

   - Changes to our ftrace code to handle very large kernels, where we
     need to use a trampoline to get to ftrace_caller().

  And many other smaller enhancements and cleanups.

  Thanks to: Alan Modra, Alistair Popple, Aneesh Kumar K.V, Anton
  Blanchard, Aravinda Prasad, Bartlomiej Zolnierkiewicz, Benjamin
  Herrenschmidt, Breno Leitao, Cédric Le Goater, Christophe Leroy,
  Christophe Lombard, Dan Carpenter, Daniel Axtens, Finn Thain, Gautham
  R. Shenoy, Gustavo Romero, Haren Myneni, Hari Bathini, Jia Hongtao,
  Joel Stanley, John Allen, Laurent Dufour, Madhavan Srinivasan, Mahesh
  Salgaonkar, Mark Hairgrove, Masahiro Yamada, Michael Bringmann,
  Michael Neuling, Michal Suchanek, Murilo Opsfelder Araujo, Nathan
  Fontenot, Naveen N. Rao, Nicholas Piggin, Nick Desaulniers, Oliver
  O'Halloran, Paul Mackerras, Petr Vorel, Rashmica Gupta, Reza Arbab,
  Rob Herring, Sam Bobroff, Samuel Mendoza-Jonas, Scott Wood, Stan
  Johnson, Stephen Rothwell, Stewart Smith, Suraj Jitindar Singh, Tyrel
  Datwyler, Vaibhav Jain, Vasant Hegde, YueHaibing, zhong jiang"

* tag 'powerpc-4.20-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (221 commits)
  Revert "selftests/powerpc: Fix out-of-tree build errors"
  powerpc/msi: Fix compile error on mpc83xx
  powerpc: Fix stack protector crashes on CPU hotplug
  powerpc/traps: restore recoverability of machine_check interrupts
  powerpc/64/module: REL32 relocation range check
  powerpc/64s/radix: Fix radix__flush_tlb_collapsed_pmd double flushing pmd
  selftests/powerpc: Add a test of wild bctr
  powerpc/mm: Fix page table dump to work on Radix
  powerpc/mm/radix: Display if mappings are exec or not
  powerpc/mm/radix: Simplify split mapping logic
  powerpc/mm/radix: Remove the retry in the split mapping logic
  powerpc/mm/radix: Fix small page at boundary when splitting
  powerpc/mm/radix: Fix overuse of small pages in splitting logic
  powerpc/mm/radix: Fix off-by-one in split mapping logic
  powerpc/ftrace: Handle large kernel configs
  powerpc/mm: Fix WARN_ON with THP NUMA migration
  selftests/powerpc: Fix out-of-tree build errors
  powerpc/time: no steal_time when CONFIG_PPC_SPLPAR is not selected
  powerpc/time: Only set CONFIG_ARCH_HAS_SCALED_CPUTIME on PPC64
  powerpc/time: isolate scaled cputime accounting in dedicated functions.
  ...
2018-10-26 14:36:21 -07:00

430 lines
9.5 KiB
C

/*
** z2ram - Amiga pseudo-driver to access 16bit-RAM in ZorroII space
** as a block device, to be used as a RAM disk or swap space
**
** Copyright (C) 1994 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
**
** ++Geert: support for zorro_unused_z2ram, better range checking
** ++roman: translate accesses via an array
** ++Milan: support for ChipRAM usage
** ++yambo: converted to 2.0 kernel
** ++yambo: modularized and support added for 3 minor devices including:
** MAJOR MINOR DESCRIPTION
** ----- ----- ----------------------------------------------
** 37 0 Use Zorro II and Chip ram
** 37 1 Use only Zorro II ram
** 37 2 Use only Chip ram
** 37 4-7 Use memory list entry 1-4 (first is 0)
** ++jskov: support for 1-4th memory list entry.
**
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted, provided
** that the above copyright notice appear in all copies and that both that
** copyright notice and this permission notice appear in supporting
** documentation. This software is provided "as is" without express or
** implied warranty.
*/
#define DEVICE_NAME "Z2RAM"
#include <linux/major.h>
#include <linux/vmalloc.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/blk-mq.h>
#include <linux/bitops.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <asm/setup.h>
#include <asm/amigahw.h>
#include <asm/pgtable.h>
#include <linux/zorro.h>
#define Z2MINOR_COMBINED (0)
#define Z2MINOR_Z2ONLY (1)
#define Z2MINOR_CHIPONLY (2)
#define Z2MINOR_MEMLIST1 (4)
#define Z2MINOR_MEMLIST2 (5)
#define Z2MINOR_MEMLIST3 (6)
#define Z2MINOR_MEMLIST4 (7)
#define Z2MINOR_COUNT (8) /* Move this down when adding a new minor */
#define Z2RAM_CHUNK1024 ( Z2RAM_CHUNKSIZE >> 10 )
static DEFINE_MUTEX(z2ram_mutex);
static u_long *z2ram_map = NULL;
static u_long z2ram_size = 0;
static int z2_count = 0;
static int chip_count = 0;
static int list_count = 0;
static int current_device = -1;
static DEFINE_SPINLOCK(z2ram_lock);
static struct gendisk *z2ram_gendisk;
static blk_status_t z2_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct request *req = bd->rq;
unsigned long start = blk_rq_pos(req) << 9;
unsigned long len = blk_rq_cur_bytes(req);
blk_mq_start_request(req);
if (start + len > z2ram_size) {
pr_err(DEVICE_NAME ": bad access: block=%llu, "
"count=%u\n",
(unsigned long long)blk_rq_pos(req),
blk_rq_cur_sectors(req));
return BLK_STS_IOERR;
}
spin_lock_irq(&z2ram_lock);
while (len) {
unsigned long addr = start & Z2RAM_CHUNKMASK;
unsigned long size = Z2RAM_CHUNKSIZE - addr;
void *buffer = bio_data(req->bio);
if (len < size)
size = len;
addr += z2ram_map[ start >> Z2RAM_CHUNKSHIFT ];
if (rq_data_dir(req) == READ)
memcpy(buffer, (char *)addr, size);
else
memcpy((char *)addr, buffer, size);
start += size;
len -= size;
}
spin_unlock_irq(&z2ram_lock);
blk_mq_end_request(req, BLK_STS_OK);
return BLK_STS_OK;
}
static void
get_z2ram( void )
{
int i;
for ( i = 0; i < Z2RAM_SIZE / Z2RAM_CHUNKSIZE; i++ )
{
if ( test_bit( i, zorro_unused_z2ram ) )
{
z2_count++;
z2ram_map[z2ram_size++] = (unsigned long)ZTWO_VADDR(Z2RAM_START) +
(i << Z2RAM_CHUNKSHIFT);
clear_bit( i, zorro_unused_z2ram );
}
}
return;
}
static void
get_chipram( void )
{
while ( amiga_chip_avail() > ( Z2RAM_CHUNKSIZE * 4 ) )
{
chip_count++;
z2ram_map[ z2ram_size ] =
(u_long)amiga_chip_alloc( Z2RAM_CHUNKSIZE, "z2ram" );
if ( z2ram_map[ z2ram_size ] == 0 )
{
break;
}
z2ram_size++;
}
return;
}
static int z2_open(struct block_device *bdev, fmode_t mode)
{
int device;
int max_z2_map = ( Z2RAM_SIZE / Z2RAM_CHUNKSIZE ) *
sizeof( z2ram_map[0] );
int max_chip_map = ( amiga_chip_size / Z2RAM_CHUNKSIZE ) *
sizeof( z2ram_map[0] );
int rc = -ENOMEM;
device = MINOR(bdev->bd_dev);
mutex_lock(&z2ram_mutex);
if ( current_device != -1 && current_device != device )
{
rc = -EBUSY;
goto err_out;
}
if ( current_device == -1 )
{
z2_count = 0;
chip_count = 0;
list_count = 0;
z2ram_size = 0;
/* Use a specific list entry. */
if (device >= Z2MINOR_MEMLIST1 && device <= Z2MINOR_MEMLIST4) {
int index = device - Z2MINOR_MEMLIST1 + 1;
unsigned long size, paddr, vaddr;
if (index >= m68k_realnum_memory) {
printk( KERN_ERR DEVICE_NAME
": no such entry in z2ram_map\n" );
goto err_out;
}
paddr = m68k_memory[index].addr;
size = m68k_memory[index].size & ~(Z2RAM_CHUNKSIZE-1);
#ifdef __powerpc__
/* FIXME: ioremap doesn't build correct memory tables. */
{
vfree(vmalloc (size));
}
vaddr = (unsigned long)ioremap_wt(paddr, size);
#else
vaddr = (unsigned long)z_remap_nocache_nonser(paddr, size);
#endif
z2ram_map =
kmalloc_array(size / Z2RAM_CHUNKSIZE,
sizeof(z2ram_map[0]),
GFP_KERNEL);
if ( z2ram_map == NULL )
{
printk( KERN_ERR DEVICE_NAME
": cannot get mem for z2ram_map\n" );
goto err_out;
}
while (size) {
z2ram_map[ z2ram_size++ ] = vaddr;
size -= Z2RAM_CHUNKSIZE;
vaddr += Z2RAM_CHUNKSIZE;
list_count++;
}
if ( z2ram_size != 0 )
printk( KERN_INFO DEVICE_NAME
": using %iK List Entry %d Memory\n",
list_count * Z2RAM_CHUNK1024, index );
} else
switch ( device )
{
case Z2MINOR_COMBINED:
z2ram_map = kmalloc( max_z2_map + max_chip_map, GFP_KERNEL );
if ( z2ram_map == NULL )
{
printk( KERN_ERR DEVICE_NAME
": cannot get mem for z2ram_map\n" );
goto err_out;
}
get_z2ram();
get_chipram();
if ( z2ram_size != 0 )
printk( KERN_INFO DEVICE_NAME
": using %iK Zorro II RAM and %iK Chip RAM (Total %dK)\n",
z2_count * Z2RAM_CHUNK1024,
chip_count * Z2RAM_CHUNK1024,
( z2_count + chip_count ) * Z2RAM_CHUNK1024 );
break;
case Z2MINOR_Z2ONLY:
z2ram_map = kmalloc( max_z2_map, GFP_KERNEL );
if ( z2ram_map == NULL )
{
printk( KERN_ERR DEVICE_NAME
": cannot get mem for z2ram_map\n" );
goto err_out;
}
get_z2ram();
if ( z2ram_size != 0 )
printk( KERN_INFO DEVICE_NAME
": using %iK of Zorro II RAM\n",
z2_count * Z2RAM_CHUNK1024 );
break;
case Z2MINOR_CHIPONLY:
z2ram_map = kmalloc( max_chip_map, GFP_KERNEL );
if ( z2ram_map == NULL )
{
printk( KERN_ERR DEVICE_NAME
": cannot get mem for z2ram_map\n" );
goto err_out;
}
get_chipram();
if ( z2ram_size != 0 )
printk( KERN_INFO DEVICE_NAME
": using %iK Chip RAM\n",
chip_count * Z2RAM_CHUNK1024 );
break;
default:
rc = -ENODEV;
goto err_out;
break;
}
if ( z2ram_size == 0 )
{
printk( KERN_NOTICE DEVICE_NAME
": no unused ZII/Chip RAM found\n" );
goto err_out_kfree;
}
current_device = device;
z2ram_size <<= Z2RAM_CHUNKSHIFT;
set_capacity(z2ram_gendisk, z2ram_size >> 9);
}
mutex_unlock(&z2ram_mutex);
return 0;
err_out_kfree:
kfree(z2ram_map);
err_out:
mutex_unlock(&z2ram_mutex);
return rc;
}
static void
z2_release(struct gendisk *disk, fmode_t mode)
{
mutex_lock(&z2ram_mutex);
if ( current_device == -1 ) {
mutex_unlock(&z2ram_mutex);
return;
}
mutex_unlock(&z2ram_mutex);
/*
* FIXME: unmap memory
*/
}
static const struct block_device_operations z2_fops =
{
.owner = THIS_MODULE,
.open = z2_open,
.release = z2_release,
};
static struct kobject *z2_find(dev_t dev, int *part, void *data)
{
*part = 0;
return get_disk_and_module(z2ram_gendisk);
}
static struct request_queue *z2_queue;
static struct blk_mq_tag_set tag_set;
static const struct blk_mq_ops z2_mq_ops = {
.queue_rq = z2_queue_rq,
};
static int __init
z2_init(void)
{
int ret;
if (!MACH_IS_AMIGA)
return -ENODEV;
ret = -EBUSY;
if (register_blkdev(Z2RAM_MAJOR, DEVICE_NAME))
goto err;
ret = -ENOMEM;
z2ram_gendisk = alloc_disk(1);
if (!z2ram_gendisk)
goto out_disk;
z2_queue = blk_mq_init_sq_queue(&tag_set, &z2_mq_ops, 16,
BLK_MQ_F_SHOULD_MERGE);
if (IS_ERR(z2_queue)) {
ret = PTR_ERR(z2_queue);
z2_queue = NULL;
goto out_queue;
}
z2ram_gendisk->major = Z2RAM_MAJOR;
z2ram_gendisk->first_minor = 0;
z2ram_gendisk->fops = &z2_fops;
sprintf(z2ram_gendisk->disk_name, "z2ram");
z2ram_gendisk->queue = z2_queue;
add_disk(z2ram_gendisk);
blk_register_region(MKDEV(Z2RAM_MAJOR, 0), Z2MINOR_COUNT, THIS_MODULE,
z2_find, NULL, NULL);
return 0;
out_queue:
put_disk(z2ram_gendisk);
out_disk:
unregister_blkdev(Z2RAM_MAJOR, DEVICE_NAME);
err:
return ret;
}
static void __exit z2_exit(void)
{
int i, j;
blk_unregister_region(MKDEV(Z2RAM_MAJOR, 0), Z2MINOR_COUNT);
unregister_blkdev(Z2RAM_MAJOR, DEVICE_NAME);
del_gendisk(z2ram_gendisk);
put_disk(z2ram_gendisk);
blk_cleanup_queue(z2_queue);
blk_mq_free_tag_set(&tag_set);
if ( current_device != -1 )
{
i = 0;
for ( j = 0 ; j < z2_count; j++ )
{
set_bit( i++, zorro_unused_z2ram );
}
for ( j = 0 ; j < chip_count; j++ )
{
if ( z2ram_map[ i ] )
{
amiga_chip_free( (void *) z2ram_map[ i++ ] );
}
}
if ( z2ram_map != NULL )
{
kfree( z2ram_map );
}
}
return;
}
module_init(z2_init);
module_exit(z2_exit);
MODULE_LICENSE("GPL");