/* SPDX-License-Identifier: GPL-2.0 */1#ifndef STICORE_H2#define STICORE_H34struct device;56/* generic STI structures & functions */78#define MAX_STI_ROMS 4 /* max no. of ROMs which this driver handles */910#define STI_REGION_MAX 8 /* hardcoded STI constants */11#define STI_DEV_NAME_LENGTH 3212#define STI_MONITOR_MAX 2561314#define STI_FONT_HPROMAN8 115#define STI_FONT_KANA8 21617#define ALT_CODE_TYPE_UNKNOWN 0x00 /* alt code type values */18#define ALT_CODE_TYPE_PA_RISC_64 0x011920/* The latency of the STI functions cannot really be reduced by setting21* this to 0; STI doesn't seem to be designed to allow calling a different22* function (or the same function with different arguments) after a23* function exited with 1 as return value.24*25* As all of the functions below could be called from interrupt context,26* we have to spin_lock_irqsave around the do { ret = bla(); } while(ret==1)27* block. Really bad latency there.28*29* Probably the best solution to all this is have the generic code manage30* the screen buffer and a kernel thread to call STI occasionally.31*32* Luckily, the frame buffer guys have the same problem so we can just wait33* for them to fix it and steal their solution. prumpf34*/3536#include <asm/io.h>3738#define STI_WAIT 13940#define STI_PTR(p) ( virt_to_phys(p) )4142#define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x)43#define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y)4445/* sti_font_xy() use the native font ROM ! */46#define sti_font_x(sti) (PTR_STI(sti->font)->width)47#define sti_font_y(sti) (PTR_STI(sti->font)->height)4849#ifdef CONFIG_64BIT50#define STI_LOWMEM (GFP_KERNEL | GFP_DMA)51#else52#define STI_LOWMEM (GFP_KERNEL)53#endif545556/* STI function configuration structs */5758typedef union region {59struct {60u32 offset : 14; /* offset in 4kbyte page */61u32 sys_only : 1; /* don't map to user space */62u32 cache : 1; /* map to data cache */63u32 btlb : 1; /* map to block tlb */64u32 last : 1; /* last region in list */65u32 length : 14; /* length in 4kbyte page */66} region_desc;6768u32 region; /* complete region value */69} region_t;7071#define REGION_OFFSET_TO_PHYS( rt, hpa ) \72(((rt).region_desc.offset << 12) + (hpa))7374struct sti_glob_cfg_ext {75u8 curr_mon; /* current monitor configured */76u8 friendly_boot; /* in friendly boot mode */77s16 power; /* power calculation (in Watts) */78s32 freq_ref; /* frequency reference */79u32 *sti_mem_addr; /* pointer to global sti memory (size=sti_mem_request) */80u32 *future_ptr; /* pointer to future data */81};8283struct sti_glob_cfg {84s32 text_planes; /* number of planes used for text */85s16 onscreen_x; /* screen width in pixels */86s16 onscreen_y; /* screen height in pixels */87s16 offscreen_x; /* offset width in pixels */88s16 offscreen_y; /* offset height in pixels */89s16 total_x; /* frame buffer width in pixels */90s16 total_y; /* frame buffer height in pixels */91u32 *region_ptrs[STI_REGION_MAX]; /* region pointers */92s32 reent_lvl; /* storage for reentry level value */93u32 *save_addr; /* where to save or restore reentrant state */94u32 *ext_ptr; /* pointer to extended glob_cfg data structure */95};969798/* STI init function structs */99100struct sti_init_flags {101u32 wait : 1; /* should routine idle wait or not */102u32 reset : 1; /* hard reset the device? */103u32 text : 1; /* turn on text display planes? */104u32 nontext : 1; /* turn on non-text display planes? */105u32 clear : 1; /* clear text display planes? */106u32 cmap_blk : 1; /* non-text planes cmap black? */107u32 enable_be_timer : 1; /* enable bus error timer */108u32 enable_be_int : 1; /* enable bus error timer interrupt */109u32 no_chg_tx : 1; /* don't change text settings */110u32 no_chg_ntx : 1; /* don't change non-text settings */111u32 no_chg_bet : 1; /* don't change berr timer settings */112u32 no_chg_bei : 1; /* don't change berr int settings */113u32 init_cmap_tx : 1; /* initialize cmap for text planes */114u32 cmt_chg : 1; /* change current monitor type */115u32 retain_ie : 1; /* don't allow reset to clear int enables */116u32 caller_bootrom : 1; /* set only by bootrom for each call */117u32 caller_kernel : 1; /* set only by kernel for each call */118u32 caller_other : 1; /* set only by non-[BR/K] caller */119u32 pad : 14; /* pad to word boundary */120u32 *future_ptr; /* pointer to future data */121};122123struct sti_init_inptr_ext {124u8 config_mon_type; /* configure to monitor type */125u8 pad[1]; /* pad to word boundary */126u16 inflight_data; /* inflight data possible on PCI */127u32 *future_ptr; /* pointer to future data */128};129130struct sti_init_inptr {131s32 text_planes; /* number of planes to use for text */132u32 *ext_ptr; /* pointer to extended init_graph inptr data structure*/133};134135136struct sti_init_outptr {137s32 errno; /* error number on failure */138s32 text_planes; /* number of planes used for text */139u32 *future_ptr; /* pointer to future data */140};141142143144/* STI configuration function structs */145146struct sti_conf_flags {147u32 wait : 1; /* should routine idle wait or not */148u32 pad : 31; /* pad to word boundary */149u32 *future_ptr; /* pointer to future data */150};151152struct sti_conf_inptr {153u32 *future_ptr; /* pointer to future data */154};155156struct sti_conf_outptr_ext {157u32 crt_config[3]; /* hardware specific X11/OGL information */158u32 crt_hdw[3];159u32 *future_ptr;160};161162struct sti_conf_outptr {163s32 errno; /* error number on failure */164s16 onscreen_x; /* screen width in pixels */165s16 onscreen_y; /* screen height in pixels */166s16 offscreen_x; /* offscreen width in pixels */167s16 offscreen_y; /* offscreen height in pixels */168s16 total_x; /* frame buffer width in pixels */169s16 total_y; /* frame buffer height in pixels */170s32 bits_per_pixel; /* bits/pixel device has configured */171s32 bits_used; /* bits which can be accessed */172s32 planes; /* number of fb planes in system */173u8 dev_name[STI_DEV_NAME_LENGTH]; /* null terminated product name */174u32 attributes; /* flags denoting attributes */175u32 *ext_ptr; /* pointer to future data */176};177178struct sti_rom {179u8 type[4];180u8 res004;181u8 num_mons;182u8 revno[2];183u32 graphics_id[2];184185u32 font_start;186u32 statesize;187u32 last_addr;188u32 region_list;189190u16 reentsize;191u16 maxtime;192u32 mon_tbl_addr;193u32 user_data_addr;194u32 sti_mem_req;195196u32 user_data_size;197u16 power;198u8 bus_support;199u8 ext_bus_support;200u8 alt_code_type;201u8 ext_dd_struct[3];202u32 cfb_addr;203204u32 init_graph;205u32 state_mgmt;206u32 font_unpmv;207u32 block_move;208u32 self_test;209u32 excep_hdlr;210u32 inq_conf;211u32 set_cm_entry;212u32 dma_ctrl;213u8 res040[7 * 4];214215u32 init_graph_addr;216u32 state_mgmt_addr;217u32 font_unp_addr;218u32 block_move_addr;219u32 self_test_addr;220u32 excep_hdlr_addr;221u32 inq_conf_addr;222u32 set_cm_entry_addr;223u32 image_unpack_addr;224u32 pa_risx_addrs[7];225};226227struct sti_rom_font {228u16 first_char;229u16 last_char;230u8 width;231u8 height;232u8 font_type; /* language type */233u8 bytes_per_char;234s32 next_font; /* note: signed int */235u8 underline_height;236u8 underline_pos;237u8 res008[2];238};239240/* sticore internal font handling */241242struct sti_cooked_font {243struct sti_rom_font *raw; /* native ptr for STI functions */244void *raw_ptr; /* kmalloc'ed font data */245struct sti_cooked_font *next_font;246int height, width;247int refcount;248u32 crc;249};250251struct sti_cooked_rom {252struct sti_rom *raw;253struct sti_cooked_font *font_start;254};255256/* STI font printing function structs */257258struct sti_font_inptr {259u32 *font_start_addr; /* address of font start */260s16 index; /* index into font table of character */261u8 fg_color; /* foreground color of character */262u8 bg_color; /* background color of character */263s16 dest_x; /* X location of character upper left */264s16 dest_y; /* Y location of character upper left */265u32 *future_ptr; /* pointer to future data */266};267268struct sti_font_flags {269u32 wait : 1; /* should routine idle wait or not */270u32 non_text : 1; /* font unpack/move in non_text planes =1, text =0 */271u32 pad : 30; /* pad to word boundary */272u32 *future_ptr; /* pointer to future data */273};274275struct sti_font_outptr {276s32 errno; /* error number on failure */277u32 *future_ptr; /* pointer to future data */278};279280/* STI blockmove structs */281282struct sti_blkmv_flags {283u32 wait : 1; /* should routine idle wait or not */284u32 color : 1; /* change color during move? */285u32 clear : 1; /* clear during move? */286u32 non_text : 1; /* block move in non_text planes =1, text =0 */287u32 pad : 28; /* pad to word boundary */288u32 *future_ptr; /* pointer to future data */289};290291struct sti_blkmv_inptr {292u8 fg_color; /* foreground color after move */293u8 bg_color; /* background color after move */294s16 src_x; /* source upper left pixel x location */295s16 src_y; /* source upper left pixel y location */296s16 dest_x; /* dest upper left pixel x location */297s16 dest_y; /* dest upper left pixel y location */298s16 width; /* block width in pixels */299s16 height; /* block height in pixels */300u32 *future_ptr; /* pointer to future data */301};302303struct sti_blkmv_outptr {304s32 errno; /* error number on failure */305u32 *future_ptr; /* pointer to future data */306};307308309/* sti_all_data is an internal struct which needs to be allocated in310* low memory (< 4GB) if STI is used with 32bit STI on a 64bit kernel */311312struct sti_all_data {313struct sti_glob_cfg glob_cfg;314struct sti_glob_cfg_ext glob_cfg_ext;315316struct sti_conf_inptr inq_inptr;317struct sti_conf_outptr inq_outptr; /* configuration */318struct sti_conf_outptr_ext inq_outptr_ext;319320struct sti_init_inptr_ext init_inptr_ext;321struct sti_init_inptr init_inptr;322struct sti_init_outptr init_outptr;323324struct sti_blkmv_inptr blkmv_inptr;325struct sti_blkmv_outptr blkmv_outptr;326327struct sti_font_inptr font_inptr;328struct sti_font_outptr font_outptr;329330/* leave as last entries */331unsigned long save_addr[1024 / sizeof(unsigned long)];332/* min 256 bytes which is STI default, max sti->sti_mem_request */333unsigned long sti_mem_addr[256 / sizeof(unsigned long)];334/* do not add something below here ! */335};336337/* internal generic STI struct */338339struct sti_struct {340spinlock_t lock;341342/* char **mon_strings; */343int sti_mem_request;344u32 graphics_id[2];345346struct sti_cooked_rom *rom;347348unsigned long font_unpmv;349unsigned long block_move;350unsigned long init_graph;351unsigned long inq_conf;352int do_call64; /* call 64-bit code */353354/* all following fields are initialized by the generic routines */355int text_planes;356region_t regions[STI_REGION_MAX];357unsigned long regions_phys[STI_REGION_MAX];358359struct sti_glob_cfg *glob_cfg; /* points into sti_all_data */360361int wordmode;362struct sti_cooked_font *font; /* ptr to selected font (cooked) */363364struct pci_dev *pd;365366/* PCI data structures (pg. 17ff from sti.pdf) */367u8 rm_entry[16]; /* pci region mapper array == pci config space offset */368369/* pointer to the parent device */370struct device *dev;371372/* pointer to all internal data */373struct sti_all_data *sti_data;374375/* pa_path of this device */376char pa_path[24];377};378379380/* sticore interface functions */381382struct sti_struct *sti_get_rom(unsigned int index); /* 0: default sti */383void sti_font_convert_bytemode(struct sti_struct *sti, struct sti_cooked_font *f);384385386/* sticore main function to call STI firmware */387388int sti_call(const struct sti_struct *sti, unsigned long func,389const void *flags, void *inptr, void *outptr,390struct sti_glob_cfg *glob_cfg);391392393/* functions to call the STI ROM directly */394395void sti_putc(struct sti_struct *sti, int c, int y, int x,396struct sti_cooked_font *font);397void sti_set(struct sti_struct *sti, int src_y, int src_x,398int height, int width, u8 color);399void sti_clear(struct sti_struct *sti, int src_y, int src_x,400int height, int width, int c, struct sti_cooked_font *font);401void sti_bmove(struct sti_struct *sti, int src_y, int src_x,402int dst_y, int dst_x, int height, int width,403struct sti_cooked_font *font);404405#endif /* STICORE_H */406407408