# SuperH Interfaces Guide

_Peios Kernel / Hardware and drivers / Processor architectures / SuperH_

> Reference for SuperH Interfaces Guide.

<a id="rst-superh-interfaces-guide"></a>

**Author:** Paul Mundt

- [DeviceTree Booting](</kernel/hardware/arch/sh/booting.md>)
- [Adding a new board to LinuxSH](</kernel/hardware/arch/sh/new-machine.md>)
- [Notes on register bank usage in the kernel](</kernel/hardware/arch/sh/register-banks.md>)
- [features](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/arch/sh/features.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

<a id="rst-memory-management"></a>

## Memory Management

<a id="rst-sh-4"></a>

### SH-4

<a id="rst-store-queue-api"></a>

#### Store Queue API


#### <a id="c-sq_flush_range"></a>`sq_flush_range()`

```c
void sq_flush_range(unsigned long start, unsigned int len)
```

Flush (prefetch) a specific SQ range

**Parameters**

- `unsigned long start`: the store queue address to start flushing from
- `unsigned int len`: the length to flush

**Description**

Flushes the store queue cache from **start** to **start** + **len** in a
linear fashion.

#### <a id="c-sq_remap"></a>`sq_remap()`

```c
unsigned long sq_remap(unsigned long phys, unsigned int size, const char *name, pgprot_t prot)
```

Map a physical address through the Store Queues

**Parameters**

- `unsigned long phys`: Physical address of mapping.
- `unsigned int size`: Length of mapping.
- `const char *name`: User invoking mapping.
- `pgprot_t prot`: Protection bits.

**Description**

Remaps the physical address **phys** through the next available store queue
address of **size** length. **name** is logged at boot time as well as through
the sysfs interface.

#### <a id="c-sq_unmap"></a>`sq_unmap()`

```c
void sq_unmap(unsigned long vaddr)
```

Unmap a Store Queue allocation

**Parameters**

- `unsigned long vaddr`: Pre-allocated Store Queue mapping.

**Description**

Unmaps the store queue allocation **map** that was previously created by
[`sq_remap()`](#c-sq_remap). Also frees up the pte that was previously inserted into
the kernel page table and discards the UTLB translation.


<a id="rst-machine-specific-interfaces"></a>

## Machine Specific Interfaces

<a id="rst-mach-dreamcast"></a>

### mach-dreamcast


#### <a id="c-aica_rtc_gettimeofday"></a>`aica_rtc_gettimeofday()`

```c
int aica_rtc_gettimeofday(struct device *dev, struct rtc_time *tm)
```

Get the time from the AICA RTC

**Parameters**

- `struct device *dev`: the RTC device (ignored)
- `struct rtc_time *tm`: pointer to resulting RTC time structure

**Description**

Grabs the current RTC seconds counter and adjusts it to the Unix Epoch.

#### <a id="c-aica_rtc_settimeofday"></a>`aica_rtc_settimeofday()`

```c
int aica_rtc_settimeofday(struct device *dev, struct rtc_time *tm)
```

Set the AICA RTC to the current time

**Parameters**

- `struct device *dev`: the RTC device (ignored)
- `struct rtc_time *tm`: pointer to new RTC time structure

**Description**

Adjusts the given **tv** to the AICA Epoch and sets the RTC seconds counter.


<a id="rst-mach-x3proto"></a>

### mach-x3proto


#### <a id="c-ilsel_enable"></a>`ilsel_enable()`

```c
int ilsel_enable(ilsel_source_t set)
```

Enable an ILSEL set.

**Parameters**

- `ilsel_source_t set`: ILSEL source (see ilsel_source_t enum in include/asm-sh/ilsel.h).

**Description**

Enables a given non-aliased ILSEL source (\<= ILSEL_KEY) at the highest
available interrupt level. Callers should take care to order callsites
noting descending interrupt levels. Aliasing FPGA and external board
IRQs need to use [`ilsel_enable_fixed()`](#c-ilsel_enable_fixed).

The return value is an IRQ number that can later be taken down with
[`ilsel_disable()`](#c-ilsel_disable).

#### <a id="c-ilsel_enable_fixed"></a>`ilsel_enable_fixed()`

```c
int ilsel_enable_fixed(ilsel_source_t set, unsigned int level)
```

Enable an ILSEL set at a fixed interrupt level

**Parameters**

- `ilsel_source_t set`: ILSEL source (see ilsel_source_t enum in include/asm-sh/ilsel.h).
- `unsigned int level`: Interrupt level (1 - 15)

**Description**

Enables a given ILSEL source at a fixed interrupt level. Necessary
both for level reservation as well as for aliased sources that only
exist on special ILSEL#s.

Returns an IRQ number (as [`ilsel_enable()`](#c-ilsel_enable)).

#### <a id="c-ilsel_disable"></a>`ilsel_disable()`

```c
void ilsel_disable(unsigned int irq)
```

Disable an ILSEL set

**Parameters**

- `unsigned int irq`: Bit position for ILSEL set value (retval from enable routines)

**Description**

Disable a previously enabled ILSEL set.


<a id="rst-busses"></a>

## Busses

<a id="rst-maple"></a>

### Maple


#### <a id="c-maple_driver_register"></a>`maple_driver_register()`

```c
int maple_driver_register(struct maple_driver *drv)
```

register a maple driver

**Parameters**

- `struct maple_driver *drv`: maple driver to be registered.

**Description**

Registers the passed in **drv**, while updating the bus type.
Devices with matching function IDs will be automatically probed.

#### <a id="c-maple_driver_unregister"></a>`maple_driver_unregister()`

```c
void maple_driver_unregister(struct maple_driver *drv)
```

unregister a maple driver.

**Parameters**

- `struct maple_driver *drv`: maple driver to unregister.

**Description**

Cleans up after [`maple_driver_register()`](#c-maple_driver_register). To be invoked in the exit
path of any module drivers.

#### <a id="c-maple_getcond_callback"></a>`maple_getcond_callback()`

```c
void maple_getcond_callback(struct maple_device *dev, void (*callback) (struct mapleq *mq), unsigned long interval, unsigned long function)
```

setup handling MAPLE_COMMAND_GETCOND

**Parameters**

- `struct maple_device *dev`: device responding
- `void (*callback) (struct mapleq *mq)`: handler callback
- `unsigned long interval`: interval in jiffies between callbacks
- `unsigned long function`: the function code for the device

#### <a id="c-maple_add_packet"></a>`maple_add_packet()`

```c
int maple_add_packet(struct maple_device *mdev, u32 function, u32 command, size_t length, void *data)
```

add a single instruction to the maple bus queue

**Parameters**

- `struct maple_device *mdev`: maple device
- `u32 function`: function on device being queried
- `u32 command`: maple command to add
- `size_t length`: length of command string (in 32 bit words)
- `void *data`: remainder of command string
