sticore.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef STICORE_H
  3. #define STICORE_H
  4. /* generic STI structures & functions */
  5. #if 0
  6. #define DPRINTK(x) printk x
  7. #else
  8. #define DPRINTK(x)
  9. #endif
  10. #define MAX_STI_ROMS 4 /* max no. of ROMs which this driver handles */
  11. #define STI_REGION_MAX 8 /* hardcoded STI constants */
  12. #define STI_DEV_NAME_LENGTH 32
  13. #define STI_MONITOR_MAX 256
  14. #define STI_FONT_HPROMAN8 1
  15. #define STI_FONT_KANA8 2
  16. #define ALT_CODE_TYPE_UNKNOWN 0x00 /* alt code type values */
  17. #define ALT_CODE_TYPE_PA_RISC_64 0x01
  18. /* The latency of the STI functions cannot really be reduced by setting
  19. * this to 0; STI doesn't seem to be designed to allow calling a different
  20. * function (or the same function with different arguments) after a
  21. * function exited with 1 as return value.
  22. *
  23. * As all of the functions below could be called from interrupt context,
  24. * we have to spin_lock_irqsave around the do { ret = bla(); } while(ret==1)
  25. * block. Really bad latency there.
  26. *
  27. * Probably the best solution to all this is have the generic code manage
  28. * the screen buffer and a kernel thread to call STI occasionally.
  29. *
  30. * Luckily, the frame buffer guys have the same problem so we can just wait
  31. * for them to fix it and steal their solution. prumpf
  32. */
  33. #include <asm/io.h>
  34. #define STI_WAIT 1
  35. #define STI_PTR(p) ( virt_to_phys(p) )
  36. #define PTR_STI(p) ( phys_to_virt((unsigned long)p) )
  37. #define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x)
  38. #define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y)
  39. /* sti_font_xy() use the native font ROM ! */
  40. #define sti_font_x(sti) (PTR_STI(sti->font)->width)
  41. #define sti_font_y(sti) (PTR_STI(sti->font)->height)
  42. #ifdef CONFIG_64BIT
  43. #define STI_LOWMEM (GFP_KERNEL | GFP_DMA)
  44. #else
  45. #define STI_LOWMEM (GFP_KERNEL)
  46. #endif
  47. /* STI function configuration structs */
  48. typedef union region {
  49. struct {
  50. u32 offset : 14; /* offset in 4kbyte page */
  51. u32 sys_only : 1; /* don't map to user space */
  52. u32 cache : 1; /* map to data cache */
  53. u32 btlb : 1; /* map to block tlb */
  54. u32 last : 1; /* last region in list */
  55. u32 length : 14; /* length in 4kbyte page */
  56. } region_desc;
  57. u32 region; /* complete region value */
  58. } region_t;
  59. #define REGION_OFFSET_TO_PHYS( rt, hpa ) \
  60. (((rt).region_desc.offset << 12) + (hpa))
  61. struct sti_glob_cfg_ext {
  62. u8 curr_mon; /* current monitor configured */
  63. u8 friendly_boot; /* in friendly boot mode */
  64. s16 power; /* power calculation (in Watts) */
  65. s32 freq_ref; /* frequency reference */
  66. u32 sti_mem_addr; /* pointer to global sti memory (size=sti_mem_request) */
  67. u32 future_ptr; /* pointer to future data */
  68. };
  69. struct sti_glob_cfg {
  70. s32 text_planes; /* number of planes used for text */
  71. s16 onscreen_x; /* screen width in pixels */
  72. s16 onscreen_y; /* screen height in pixels */
  73. s16 offscreen_x; /* offset width in pixels */
  74. s16 offscreen_y; /* offset height in pixels */
  75. s16 total_x; /* frame buffer width in pixels */
  76. s16 total_y; /* frame buffer height in pixels */
  77. u32 region_ptrs[STI_REGION_MAX]; /* region pointers */
  78. s32 reent_lvl; /* storage for reentry level value */
  79. u32 save_addr; /* where to save or restore reentrant state */
  80. u32 ext_ptr; /* pointer to extended glob_cfg data structure */
  81. };
  82. /* STI init function structs */
  83. struct sti_init_flags {
  84. u32 wait : 1; /* should routine idle wait or not */
  85. u32 reset : 1; /* hard reset the device? */
  86. u32 text : 1; /* turn on text display planes? */
  87. u32 nontext : 1; /* turn on non-text display planes? */
  88. u32 clear : 1; /* clear text display planes? */
  89. u32 cmap_blk : 1; /* non-text planes cmap black? */
  90. u32 enable_be_timer : 1; /* enable bus error timer */
  91. u32 enable_be_int : 1; /* enable bus error timer interrupt */
  92. u32 no_chg_tx : 1; /* don't change text settings */
  93. u32 no_chg_ntx : 1; /* don't change non-text settings */
  94. u32 no_chg_bet : 1; /* don't change berr timer settings */
  95. u32 no_chg_bei : 1; /* don't change berr int settings */
  96. u32 init_cmap_tx : 1; /* initialize cmap for text planes */
  97. u32 cmt_chg : 1; /* change current monitor type */
  98. u32 retain_ie : 1; /* don't allow reset to clear int enables */
  99. u32 caller_bootrom : 1; /* set only by bootrom for each call */
  100. u32 caller_kernel : 1; /* set only by kernel for each call */
  101. u32 caller_other : 1; /* set only by non-[BR/K] caller */
  102. u32 pad : 14; /* pad to word boundary */
  103. u32 future_ptr; /* pointer to future data */
  104. };
  105. struct sti_init_inptr_ext {
  106. u8 config_mon_type; /* configure to monitor type */
  107. u8 pad[1]; /* pad to word boundary */
  108. u16 inflight_data; /* inflight data possible on PCI */
  109. u32 future_ptr; /* pointer to future data */
  110. };
  111. struct sti_init_inptr {
  112. s32 text_planes; /* number of planes to use for text */
  113. u32 ext_ptr; /* pointer to extended init_graph inptr data structure*/
  114. };
  115. struct sti_init_outptr {
  116. s32 errno; /* error number on failure */
  117. s32 text_planes; /* number of planes used for text */
  118. u32 future_ptr; /* pointer to future data */
  119. };
  120. /* STI configuration function structs */
  121. struct sti_conf_flags {
  122. u32 wait : 1; /* should routine idle wait or not */
  123. u32 pad : 31; /* pad to word boundary */
  124. u32 future_ptr; /* pointer to future data */
  125. };
  126. struct sti_conf_inptr {
  127. u32 future_ptr; /* pointer to future data */
  128. };
  129. struct sti_conf_outptr_ext {
  130. u32 crt_config[3]; /* hardware specific X11/OGL information */
  131. u32 crt_hdw[3];
  132. u32 future_ptr;
  133. };
  134. struct sti_conf_outptr {
  135. s32 errno; /* error number on failure */
  136. s16 onscreen_x; /* screen width in pixels */
  137. s16 onscreen_y; /* screen height in pixels */
  138. s16 offscreen_x; /* offscreen width in pixels */
  139. s16 offscreen_y; /* offscreen height in pixels */
  140. s16 total_x; /* frame buffer width in pixels */
  141. s16 total_y; /* frame buffer height in pixels */
  142. s32 bits_per_pixel; /* bits/pixel device has configured */
  143. s32 bits_used; /* bits which can be accessed */
  144. s32 planes; /* number of fb planes in system */
  145. u8 dev_name[STI_DEV_NAME_LENGTH]; /* null terminated product name */
  146. u32 attributes; /* flags denoting attributes */
  147. u32 ext_ptr; /* pointer to future data */
  148. };
  149. struct sti_rom {
  150. u8 type[4];
  151. u8 res004;
  152. u8 num_mons;
  153. u8 revno[2];
  154. u32 graphics_id[2];
  155. u32 font_start;
  156. u32 statesize;
  157. u32 last_addr;
  158. u32 region_list;
  159. u16 reentsize;
  160. u16 maxtime;
  161. u32 mon_tbl_addr;
  162. u32 user_data_addr;
  163. u32 sti_mem_req;
  164. u32 user_data_size;
  165. u16 power;
  166. u8 bus_support;
  167. u8 ext_bus_support;
  168. u8 alt_code_type;
  169. u8 ext_dd_struct[3];
  170. u32 cfb_addr;
  171. u32 init_graph;
  172. u32 state_mgmt;
  173. u32 font_unpmv;
  174. u32 block_move;
  175. u32 self_test;
  176. u32 excep_hdlr;
  177. u32 inq_conf;
  178. u32 set_cm_entry;
  179. u32 dma_ctrl;
  180. u8 res040[7 * 4];
  181. u32 init_graph_addr;
  182. u32 state_mgmt_addr;
  183. u32 font_unp_addr;
  184. u32 block_move_addr;
  185. u32 self_test_addr;
  186. u32 excep_hdlr_addr;
  187. u32 inq_conf_addr;
  188. u32 set_cm_entry_addr;
  189. u32 image_unpack_addr;
  190. u32 pa_risx_addrs[7];
  191. };
  192. struct sti_rom_font {
  193. u16 first_char;
  194. u16 last_char;
  195. u8 width;
  196. u8 height;
  197. u8 font_type; /* language type */
  198. u8 bytes_per_char;
  199. u32 next_font;
  200. u8 underline_height;
  201. u8 underline_pos;
  202. u8 res008[2];
  203. };
  204. /* sticore internal font handling */
  205. struct sti_cooked_font {
  206. struct sti_rom_font *raw;
  207. struct sti_cooked_font *next_font;
  208. };
  209. struct sti_cooked_rom {
  210. struct sti_rom *raw;
  211. struct sti_cooked_font *font_start;
  212. };
  213. /* STI font printing function structs */
  214. struct sti_font_inptr {
  215. u32 font_start_addr; /* address of font start */
  216. s16 index; /* index into font table of character */
  217. u8 fg_color; /* foreground color of character */
  218. u8 bg_color; /* background color of character */
  219. s16 dest_x; /* X location of character upper left */
  220. s16 dest_y; /* Y location of character upper left */
  221. u32 future_ptr; /* pointer to future data */
  222. };
  223. struct sti_font_flags {
  224. u32 wait : 1; /* should routine idle wait or not */
  225. u32 non_text : 1; /* font unpack/move in non_text planes =1, text =0 */
  226. u32 pad : 30; /* pad to word boundary */
  227. u32 future_ptr; /* pointer to future data */
  228. };
  229. struct sti_font_outptr {
  230. s32 errno; /* error number on failure */
  231. u32 future_ptr; /* pointer to future data */
  232. };
  233. /* STI blockmove structs */
  234. struct sti_blkmv_flags {
  235. u32 wait : 1; /* should routine idle wait or not */
  236. u32 color : 1; /* change color during move? */
  237. u32 clear : 1; /* clear during move? */
  238. u32 non_text : 1; /* block move in non_text planes =1, text =0 */
  239. u32 pad : 28; /* pad to word boundary */
  240. u32 future_ptr; /* pointer to future data */
  241. };
  242. struct sti_blkmv_inptr {
  243. u8 fg_color; /* foreground color after move */
  244. u8 bg_color; /* background color after move */
  245. s16 src_x; /* source upper left pixel x location */
  246. s16 src_y; /* source upper left pixel y location */
  247. s16 dest_x; /* dest upper left pixel x location */
  248. s16 dest_y; /* dest upper left pixel y location */
  249. s16 width; /* block width in pixels */
  250. s16 height; /* block height in pixels */
  251. u32 future_ptr; /* pointer to future data */
  252. };
  253. struct sti_blkmv_outptr {
  254. s32 errno; /* error number on failure */
  255. u32 future_ptr; /* pointer to future data */
  256. };
  257. /* sti_all_data is an internal struct which needs to be allocated in
  258. * low memory (< 4GB) if STI is used with 32bit STI on a 64bit kernel */
  259. struct sti_all_data {
  260. struct sti_glob_cfg glob_cfg;
  261. struct sti_glob_cfg_ext glob_cfg_ext;
  262. struct sti_conf_inptr inq_inptr;
  263. struct sti_conf_outptr inq_outptr; /* configuration */
  264. struct sti_conf_outptr_ext inq_outptr_ext;
  265. struct sti_init_inptr_ext init_inptr_ext;
  266. struct sti_init_inptr init_inptr;
  267. struct sti_init_outptr init_outptr;
  268. struct sti_blkmv_inptr blkmv_inptr;
  269. struct sti_blkmv_outptr blkmv_outptr;
  270. struct sti_font_inptr font_inptr;
  271. struct sti_font_outptr font_outptr;
  272. /* leave as last entries */
  273. unsigned long save_addr[1024 / sizeof(unsigned long)];
  274. /* min 256 bytes which is STI default, max sti->sti_mem_request */
  275. unsigned long sti_mem_addr[256 / sizeof(unsigned long)];
  276. /* do not add something below here ! */
  277. };
  278. /* internal generic STI struct */
  279. struct sti_struct {
  280. spinlock_t lock;
  281. /* the following fields needs to be filled in by the word/byte routines */
  282. int font_width;
  283. int font_height;
  284. /* char **mon_strings; */
  285. int sti_mem_request;
  286. u32 graphics_id[2];
  287. struct sti_cooked_rom *rom;
  288. unsigned long font_unpmv;
  289. unsigned long block_move;
  290. unsigned long init_graph;
  291. unsigned long inq_conf;
  292. /* all following fields are initialized by the generic routines */
  293. int text_planes;
  294. region_t regions[STI_REGION_MAX];
  295. unsigned long regions_phys[STI_REGION_MAX];
  296. struct sti_glob_cfg *glob_cfg; /* points into sti_all_data */
  297. struct sti_cooked_font *font; /* ptr to selected font (cooked) */
  298. struct pci_dev *pd;
  299. /* PCI data structures (pg. 17ff from sti.pdf) */
  300. u8 rm_entry[16]; /* pci region mapper array == pci config space offset */
  301. /* pointer to the fb_info where this STI device is used */
  302. struct fb_info *info;
  303. /* pointer to all internal data */
  304. struct sti_all_data *sti_data;
  305. };
  306. /* sticore interface functions */
  307. struct sti_struct *sti_get_rom(unsigned int index); /* 0: default sti */
  308. /* sticore main function to call STI firmware */
  309. int sti_call(const struct sti_struct *sti, unsigned long func,
  310. const void *flags, void *inptr, void *outptr,
  311. struct sti_glob_cfg *glob_cfg);
  312. /* functions to call the STI ROM directly */
  313. void sti_putc(struct sti_struct *sti, int c, int y, int x);
  314. void sti_set(struct sti_struct *sti, int src_y, int src_x,
  315. int height, int width, u8 color);
  316. void sti_clear(struct sti_struct *sti, int src_y, int src_x,
  317. int height, int width, int c);
  318. void sti_bmove(struct sti_struct *sti, int src_y, int src_x,
  319. int dst_y, int dst_x, int height, int width);
  320. #endif /* STICORE_H */