coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #define __SIMPLE_DEVICE__
4 
5 /* This file is derived from the flashrom project. */
6 
7 #include <string.h>
8 #include <bootstate.h>
9 #include <commonlib/helpers.h>
10 #include <delay.h>
11 #include <device/mmio.h>
12 #include <device/pci_ops.h>
13 #include <console/console.h>
14 #include <device/device.h>
15 #include <device/pci.h>
16 #include <spi_flash.h>
17 #include <spi-generic.h>
18 #include <timer.h>
19 #include <types.h>
20 
21 #include "spi.h"
22 
23 #define HSFC_FCYCLE_OFF 1 /* 1-2: FLASH Cycle */
24 #define HSFC_FCYCLE (0x3 << HSFC_FCYCLE_OFF)
25 #define HSFC_FDBC_OFF 8 /* 8-13: Flash Data Byte Count */
26 #define HSFC_FDBC (0x3f << HSFC_FDBC_OFF)
27 
28 static int spi_is_multichip(void);
29 
30 static void spi_set_smm_only_flashing(bool enable);
31 
32 struct ich7_spi_regs {
44 
45 struct ich9_spi_regs {
76 } __packed;
77 
79  int locked;
83 
84  union {
87  };
89  int menubytes;
94  unsigned int databytes;
100 };
101 
102 static struct ich_spi_controller cntlr;
103 
104 enum {
105  SPIS_SCIP = 0x0001,
106  SPIS_GRANT = 0x0002,
107  SPIS_CDS = 0x0004,
108  SPIS_FCERR = 0x0008,
109  SSFS_AEL = 0x0010,
110  SPIS_LOCK = 0x8000,
112  SSFS_RESERVED_MASK = 0x7fe2
113 };
114 
115 enum {
116  SPIC_SCGO = 0x000002,
117  SPIC_ACS = 0x000004,
118  SPIC_SPOP = 0x000008,
119  SPIC_DBC = 0x003f00,
120  SPIC_DS = 0x004000,
121  SPIC_SME = 0x008000,
122  SSFC_SCF_MASK = 0x070000,
123  SSFC_RESERVED = 0xf80000
124 };
125 
126 enum {
127  HSFS_FDONE = 0x0001,
128  HSFS_FCERR = 0x0002,
129  HSFS_AEL = 0x0004,
132  HSFS_SCIP = 0x0020,
133  HSFS_FDOPSS = 0x2000,
134  HSFS_FDV = 0x4000,
135  HSFS_FLOCKDN = 0x8000
136 };
137 
138 enum {
139  HSFC_FGO = 0x0001,
142  HSFC_FDBC_MASK = 0x3f00,
144  HSFC_FSMIE = 0x8000
145 };
146 
147 enum {
152 };
153 
154 #if CONFIG(DEBUG_SPI_FLASH)
155 
156 static u8 readb_(const void *addr)
157 {
158  u8 v = read8(addr);
159 
160  printk(BIOS_DEBUG, "read %2.2x from %4.4x\n",
161  v, ((unsigned int) addr & 0xffff) - 0xf020);
162  return v;
163 }
164 
165 static u16 readw_(const void *addr)
166 {
167  u16 v = read16(addr);
168 
169  printk(BIOS_DEBUG, "read %4.4x from %4.4x\n",
170  v, ((unsigned int) addr & 0xffff) - 0xf020);
171  return v;
172 }
173 
174 static u32 readl_(const void *addr)
175 {
176  u32 v = read32(addr);
177 
178  printk(BIOS_DEBUG, "read %8.8x from %4.4x\n",
179  v, ((unsigned int) addr & 0xffff) - 0xf020);
180  return v;
181 }
182 
183 static void writeb_(u8 b, void *addr)
184 {
185  write8(addr, b);
186  printk(BIOS_DEBUG, "wrote %2.2x to %4.4x\n",
187  b, ((unsigned int) addr & 0xffff) - 0xf020);
188 }
189 
190 static void writew_(u16 b, void *addr)
191 {
192  write16(addr, b);
193  printk(BIOS_DEBUG, "wrote %4.4x to %4.4x\n",
194  b, ((unsigned int) addr & 0xffff) - 0xf020);
195 }
196 
197 static void writel_(u32 b, void *addr)
198 {
199  write32(addr, b);
200  printk(BIOS_DEBUG, "wrote %8.8x to %4.4x\n",
201  b, ((unsigned int) addr & 0xffff) - 0xf020);
202 }
203 
204 #else /* CONFIG_DEBUG_SPI_FLASH ^^^ enabled vvv NOT enabled */
205 
206 #define readb_(a) read8(a)
207 #define readw_(a) read16(a)
208 #define readl_(a) read32(a)
209 #define writeb_(val, addr) write8(addr, val)
210 #define writew_(val, addr) write16(addr, val)
211 #define writel_(val, addr) write32(addr, val)
212 
213 #endif /* CONFIG_DEBUG_SPI_FLASH ^^^ NOT enabled */
214 
215 static void write_reg(const void *value, void *dest, uint32_t size)
216 {
217  const uint8_t *bvalue = value;
218  uint8_t *bdest = dest;
219 
220  while (size >= 4) {
221  writel_(*(const uint32_t *)bvalue, bdest);
222  bdest += 4; bvalue += 4; size -= 4;
223  }
224  while (size) {
225  writeb_(*bvalue, bdest);
226  bdest++; bvalue++; size--;
227  }
228 }
229 
230 static void read_reg(const void *src, void *value, uint32_t size)
231 {
232  const uint8_t *bsrc = src;
233  uint8_t *bvalue = value;
234 
235  while (size >= 4) {
236  *(uint32_t *)bvalue = readl_(bsrc);
237  bsrc += 4; bvalue += 4; size -= 4;
238  }
239  while (size) {
240  *bvalue = readb_(bsrc);
241  bsrc++; bvalue++; size--;
242  }
243 }
244 
245 static void ich_set_bbar(uint32_t minaddr)
246 {
247  const uint32_t bbar_mask = 0x00ffff00;
248  uint32_t ichspi_bbar;
249 
250  minaddr &= bbar_mask;
251  ichspi_bbar = readl_(cntlr.bbar) & ~bbar_mask;
252  ichspi_bbar |= minaddr;
253  writel_(ichspi_bbar, cntlr.bbar);
254 }
255 
256 #if CONFIG(SOUTHBRIDGE_INTEL_I82801GX)
257 #define MENU_BYTES member_size(struct ich7_spi_regs, opmenu)
258 #else
259 #define MENU_BYTES member_size(struct ich9_spi_regs, opmenu)
260 #endif
261 
262 #define RCBA 0xf0
263 #define SBASE 0x54
264 
265 static void *get_spi_bar(pci_devfn_t dev)
266 {
267  uintptr_t rcba; /* Root Complex Register Block */
268  uintptr_t sbase;
269 
270  if (CONFIG(SOUTHBRIDGE_INTEL_I82801GX)) {
271  rcba = pci_read_config32(dev, RCBA);
272  return (void *)((rcba & 0xffffc000) + 0x3020);
273  }
274  if (CONFIG(SOUTHBRIDGE_INTEL_COMMON_SPI_SILVERMONT)) {
275  sbase = pci_read_config32(dev, SBASE);
276  sbase &= ~0x1ff;
277  return (void *)sbase;
278  }
279  if (CONFIG(SOUTHBRIDGE_INTEL_COMMON_SPI_ICH9)) {
280  rcba = pci_read_config32(dev, RCBA);
281  return (void *)((rcba & 0xffffc000) + 0x3800);
282  }
283 }
284 
285 void spi_init(void)
286 {
287  struct ich9_spi_regs *ich9_spi;
288  struct ich7_spi_regs *ich7_spi;
289  uint16_t hsfs;
290 
291  pci_devfn_t dev = PCI_DEV(0, 31, 0);
292 
293  if (CONFIG(SOUTHBRIDGE_INTEL_I82801GX)) {
294  ich7_spi = get_spi_bar(dev);
295  cntlr.ich7_spi = ich7_spi;
296  cntlr.opmenu = ich7_spi->opmenu;
297  cntlr.menubytes = sizeof(ich7_spi->opmenu);
298  cntlr.optype = &ich7_spi->optype;
299  cntlr.addr = &ich7_spi->spia;
300  cntlr.data = (uint8_t *)ich7_spi->spid;
301  cntlr.databytes = sizeof(ich7_spi->spid);
302  cntlr.status = (uint8_t *)&ich7_spi->spis;
303  cntlr.control = &ich7_spi->spic;
304  cntlr.bbar = &ich7_spi->bbar;
305  cntlr.preop = &ich7_spi->preop;
306  cntlr.fpr = &ich7_spi->pbr[0];
307  cntlr.fpr_max = 3;
308  } else {
309  ich9_spi = get_spi_bar(dev);
310  cntlr.ich9_spi = ich9_spi;
311  hsfs = readw_(&ich9_spi->hsfs);
312  cntlr.hsfs = hsfs;
313  cntlr.opmenu = ich9_spi->opmenu;
314  cntlr.menubytes = sizeof(ich9_spi->opmenu);
315  cntlr.optype = &ich9_spi->optype;
316  cntlr.addr = &ich9_spi->faddr;
317  cntlr.data = (uint8_t *)ich9_spi->fdata;
318  cntlr.databytes = sizeof(ich9_spi->fdata);
319  cntlr.status = &ich9_spi->ssfs;
320  cntlr.control = (uint16_t *)ich9_spi->ssfc;
321  cntlr.bbar = &ich9_spi->bbar;
322  cntlr.preop = &ich9_spi->preop;
323  cntlr.fpr = &ich9_spi->pr[0];
324  cntlr.fpr_max = 5;
325 
326  if (cntlr.hsfs & HSFS_FDV) {
327  writel_(4, &ich9_spi->fdoc);
328  cntlr.flmap0 = readl_(&ich9_spi->fdod);
329  writel_(0x1000, &ich9_spi->fdoc);
330  cntlr.flcomp = readl_(&ich9_spi->fdod);
331  }
332  }
333 
334  ich_set_bbar(0);
335 
336  /* Disable the BIOS write protect so write commands are allowed. */
338 }
339 
340 static int spi_locked(void)
341 {
342  if (CONFIG(SOUTHBRIDGE_INTEL_I82801GX)) {
343  return !!(readw_(&cntlr.ich7_spi->spis) & HSFS_FLOCKDN);
344  } else {
345  return !!(readw_(&cntlr.ich9_spi->hsfs) & HSFS_FLOCKDN);
346  }
347 }
348 
349 static void spi_init_cb(void *unused)
350 {
351  spi_init();
352 }
353 
355 
356 typedef struct spi_transaction {
357  const uint8_t *out;
365 
366 static inline void spi_use_out(spi_transaction *trans, unsigned int bytes)
367 {
368  trans->out += bytes;
369  trans->bytesout -= bytes;
370 }
371 
372 static inline void spi_use_in(spi_transaction *trans, unsigned int bytes)
373 {
374  trans->in += bytes;
375  trans->bytesin -= bytes;
376 }
377 
378 static void spi_setup_type(spi_transaction *trans)
379 {
380  trans->type = 0xFF;
381 
382  /* Try to guess spi type from read/write sizes. */
383  if (trans->bytesin == 0) {
384  if (trans->bytesout > 4)
385  /*
386  * If bytesin = 0 and bytesout > 4, we presume this is
387  * a write data operation, which is accompanied by an
388  * address.
389  */
391  else
393  return;
394  }
395 
396  if (trans->bytesout == 1) { /* and bytesin is > 0 */
398  return;
399  }
400 
401  if (trans->bytesout == 4) { /* and bytesin is > 0 */
403  }
404 
405  /* Fast read command is called with 5 bytes instead of 4 */
406  if (trans->out[0] == SPI_OPCODE_FAST_READ && trans->bytesout == 5) {
408  --trans->bytesout;
409  }
410 }
411 
413 {
414  uint16_t optypes;
415  uint8_t opmenu[MENU_BYTES];
416 
417  trans->opcode = trans->out[0];
418  spi_use_out(trans, 1);
419  if (!spi_locked()) {
420  /* The lock is off, so just use index 0. */
421  writeb_(trans->opcode, cntlr.opmenu);
422  optypes = readw_(cntlr.optype);
423  optypes = (optypes & 0xfffc) | (trans->type & 0x3);
424  writew_(optypes, cntlr.optype);
425  return 0;
426  }
427 
428  /* The lock is on. See if what we need is on the menu. */
429  uint8_t optype;
430  uint16_t opcode_index;
431 
432  /* Write Enable is handled as atomic prefix */
433  if (trans->opcode == SPI_OPCODE_WREN)
434  return 0;
435 
436  read_reg(cntlr.opmenu, opmenu, sizeof(opmenu));
437  for (opcode_index = 0; opcode_index < ARRAY_SIZE(opmenu); opcode_index++) {
438  if (opmenu[opcode_index] == trans->opcode)
439  break;
440  }
441 
442  if (opcode_index == ARRAY_SIZE(opmenu)) {
443  printk(BIOS_DEBUG, "ICH SPI: Opcode %x not found\n",
444  trans->opcode);
445  return -1;
446  }
447 
448  optypes = readw_(cntlr.optype);
449  optype = (optypes >> (opcode_index * 2)) & 0x3;
450  if (trans->type == SPI_OPCODE_TYPE_WRITE_NO_ADDRESS &&
452  trans->bytesout >= 3) {
453  /* We guessed wrong earlier. Fix it up. */
454  trans->type = optype;
455  }
456  if (optype != trans->type) {
457  printk(BIOS_DEBUG, "ICH SPI: Transaction doesn't fit type %d\n",
458  optype);
459  return -1;
460  }
461  return opcode_index;
462 }
463 
465 {
466  /* Separate the SPI address and data. */
467  switch (trans->type) {
470  return 0;
473  trans->offset = ((uint32_t)trans->out[0] << 16) |
474  ((uint32_t)trans->out[1] << 8) |
475  ((uint32_t)trans->out[2] << 0);
476  spi_use_out(trans, 3);
477  return 1;
478  default:
479  printk(BIOS_DEBUG, "Unrecognized SPI transaction type %#x\n", trans->type);
480  return -1;
481  }
482 }
483 
484 /*
485  * Wait for up to 6s til status register bit(s) turn 1 (in case wait_til_set
486  * below is True) or 0. In case the wait was for the bit(s) to set - write
487  * those bits back, which would cause resetting them.
488  *
489  * Return the last read status value on success or -1 on failure.
490  */
491 static int ich_status_poll(u16 bitmask, int wait_til_set)
492 {
493  int timeout = 600000; /* This will result in 6 seconds */
494  u16 status = 0;
495 
496  while (timeout--) {
497  status = readw_(cntlr.status);
498  if (wait_til_set ^ ((status & bitmask) == 0)) {
499  if (wait_til_set)
500  writew_((status & bitmask), cntlr.status);
501  return status;
502  }
503  udelay(10);
504  }
505 
506  printk(BIOS_DEBUG, "ICH SPI: SCIP timeout, read %x, bitmask %x\n",
507  status, bitmask);
508  return -1;
509 }
510 
511 static int spi_is_multichip(void)
512 {
513  if (!(cntlr.hsfs & HSFS_FDV))
514  return 0;
515  return !!((cntlr.flmap0 >> 8) & 3);
516 }
517 
518 static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
519  size_t bytesout, void *din, size_t bytesin)
520 {
521  uint16_t control;
522  int16_t opcode_index;
523  int with_address;
524  int status;
525 
526  spi_transaction trans = {
527  dout, bytesout,
528  din, bytesin,
529  0xff, 0xff, 0
530  };
531 
532  /* There has to always at least be an opcode. */
533  if (!bytesout || !dout) {
534  printk(BIOS_DEBUG, "ICH SPI: No opcode for transfer\n");
535  return -1;
536  }
537  /* Make sure if we read something we have a place to put it. */
538  if (bytesin != 0 && !din) {
539  printk(BIOS_DEBUG, "ICH SPI: Read but no target buffer\n");
540  return -1;
541  }
542 
543  if (ich_status_poll(SPIS_SCIP, 0) == -1)
544  return -1;
545 
547 
548  spi_setup_type(&trans);
549  if ((opcode_index = spi_setup_opcode(&trans)) < 0)
550  return -1;
551  if ((with_address = spi_setup_offset(&trans)) < 0)
552  return -1;
553 
554  if (trans.opcode == SPI_OPCODE_WREN) {
555  /*
556  * Treat Write Enable as Atomic Pre-Op if possible
557  * in order to prevent the Management Engine from
558  * issuing a transaction between WREN and DATA.
559  */
560  if (!spi_locked())
561  writew_(trans.opcode, cntlr.preop);
562  return 0;
563  }
564 
565  /* Preset control fields */
566  control = SPIC_SCGO | ((opcode_index & 0x07) << 4);
567 
568  /* Issue atomic preop cycle if needed */
569  if (readw_(cntlr.preop))
570  control |= SPIC_ACS;
571 
572  if (!trans.bytesout && !trans.bytesin) {
573  /* SPI addresses are 24 bit only */
574  if (with_address)
575  writel_(trans.offset & 0x00FFFFFF, cntlr.addr);
576 
577  /*
578  * This is a 'no data' command (like Write Enable), its
579  * bitesout size was 1, decremented to zero while executing
580  * spi_setup_opcode() above. Tell the chip to send the
581  * command.
582  */
583  writew_(control, cntlr.control);
584 
585  /* wait for the result */
586  status = ich_status_poll(SPIS_CDS | SPIS_FCERR, 1);
587  if (status == -1)
588  return -1;
589 
590  if (status & SPIS_FCERR) {
591  printk(BIOS_DEBUG, "ICH SPI: Command transaction error\n");
592  return -1;
593  }
594 
595  goto spi_xfer_exit;
596  }
597 
598  /*
599  * Check if this is a write command attempting to transfer more bytes
600  * than the controller can handle. Iterations for writes are not
601  * supported here because each SPI write command needs to be preceded
602  * and followed by other SPI commands, and this sequence is controlled
603  * by the SPI chip driver.
604  */
605  if (trans.bytesout > cntlr.databytes) {
606  printk(BIOS_DEBUG, "ICH SPI: Too much to write. Does your SPI chip driver use"
607  " spi_crop_chunk()?\n");
608  return -1;
609  }
610 
611  /*
612  * Read or write up to databytes bytes at a time until everything has
613  * been sent.
614  */
615  while (trans.bytesout || trans.bytesin) {
616  uint32_t data_length;
617 
618  /* SPI addresses are 24 bit only */
619  writel_(trans.offset & 0x00FFFFFF, cntlr.addr);
620 
621  if (trans.bytesout)
622  data_length = MIN(trans.bytesout, cntlr.databytes);
623  else
624  data_length = MIN(trans.bytesin, cntlr.databytes);
625 
626  /* Program data into FDATA0 to N */
627  if (trans.bytesout) {
628  write_reg(trans.out, cntlr.data, data_length);
629  spi_use_out(&trans, data_length);
630  if (with_address)
631  trans.offset += data_length;
632  }
633 
634  /* Add proper control fields' values */
635  control &= ~((cntlr.databytes - 1) << 8);
636  control |= SPIC_DS;
637  control |= (data_length - 1) << 8;
638 
639  /* write it */
640  writew_(control, cntlr.control);
641 
642  /* Wait for Cycle Done Status or Flash Cycle Error. */
643  status = ich_status_poll(SPIS_CDS | SPIS_FCERR, 1);
644  if (status == -1)
645  return -1;
646 
647  if (status & SPIS_FCERR) {
648  printk(BIOS_DEBUG, "ICH SPI: Data transaction error\n");
649  return -1;
650  }
651 
652  if (trans.bytesin) {
653  read_reg(cntlr.data, trans.in, data_length);
654  spi_use_in(&trans, data_length);
655  if (with_address)
656  trans.offset += data_length;
657  }
658  }
659 
660 spi_xfer_exit:
661  /* Clear atomic preop now that xfer is done */
662  writew_(0, cntlr.preop);
663 
664  return 0;
665 }
666 
667 /* Sets FLA in FADDR to (addr & 0x01FFFFFF) without touching other bits. */
669 {
670  uint32_t addr_old = readl_(&cntlr.ich9_spi->faddr) & ~0x01FFFFFF;
671 
672  writel_((addr & 0x01FFFFFF) | addr_old, &cntlr.ich9_spi->faddr);
673 }
674 
675 /* Polls for Cycle Done Status, Flash Cycle Error or timeout in 8 us intervals.
676  Resets all error flags in HSFS.
677  Returns 0 if the cycle completes successfully without errors within
678  timeout us, 1 on errors. */
679 static int ich_hwseq_wait_for_cycle_complete(unsigned int timeout,
680  unsigned int len)
681 {
682  uint16_t hsfs;
683  uint32_t addr;
684 
685  timeout /= 8; /* scale timeout duration to counter */
686  while ((((hsfs = readw_(&cntlr.ich9_spi->hsfs)) &
687  (HSFS_FDONE | HSFS_FCERR)) == 0) &&
688  --timeout) {
689  udelay(8);
690  }
692 
693  if (!timeout) {
694  uint16_t hsfc;
695  addr = readl_(&cntlr.ich9_spi->faddr) & 0x01FFFFFF;
696  hsfc = readw_(&cntlr.ich9_spi->hsfc);
697  printk(BIOS_ERR, "Transaction timeout between offset 0x%08x and "
698  "0x%08x (= 0x%08x + %d) HSFC=%x HSFS=%x!\n",
699  addr, addr + len - 1, addr, len - 1,
700  hsfc, hsfs);
701  return 1;
702  }
703 
704  if (hsfs & HSFS_FCERR) {
705  uint16_t hsfc;
706  addr = readl_(&cntlr.ich9_spi->faddr) & 0x01FFFFFF;
707  hsfc = readw_(&cntlr.ich9_spi->hsfc);
708  printk(BIOS_ERR, "Transaction error between offset 0x%08x and "
709  "0x%08x (= 0x%08x + %d) HSFC=%x HSFS=%x!\n",
710  addr, addr + len - 1, addr, len - 1,
711  hsfc, hsfs);
712  return 1;
713  }
714  return 0;
715 }
716 
717 static int ich_hwseq_erase(const struct spi_flash *flash, u32 offset,
718  size_t len)
719 {
720  u32 start, end, erase_size;
721  int ret;
722  uint16_t hsfc;
723  unsigned int timeout = 1000 * USECS_PER_MSEC; /* 1 second timeout */
724 
725  erase_size = flash->sector_size;
726  if (offset % erase_size || len % erase_size) {
727  printk(BIOS_ERR, "SF: Erase offset/length not multiple of erase size\n");
728  return -1;
729  }
730 
731  ret = spi_claim_bus(&flash->spi);
732  if (ret) {
733  printk(BIOS_ERR, "SF: Unable to claim SPI bus\n");
734  return ret;
735  }
736 
737  start = offset;
738  end = start + len;
739 
740  while (offset < end) {
741  /* make sure FDONE, FCERR, AEL are cleared by writing 1 to them */
743 
745 
746  offset += erase_size;
747 
748  hsfc = readw_(&cntlr.ich9_spi->hsfc);
749  hsfc &= ~HSFC_FCYCLE; /* clear operation */
750  hsfc |= (0x3 << HSFC_FCYCLE_OFF); /* set erase operation */
751  hsfc |= HSFC_FGO; /* start */
752  writew_(hsfc, &cntlr.ich9_spi->hsfc);
753  if (ich_hwseq_wait_for_cycle_complete(timeout, len)) {
754  printk(BIOS_ERR, "SF: Erase failed at %x\n", offset - erase_size);
755  ret = -1;
756  goto out;
757  }
758  }
759 
760  printk(BIOS_DEBUG, "SF: Successfully erased %zu bytes @ %#x\n", len, start);
761 
762 out:
763  spi_release_bus(&flash->spi);
764  return ret;
765 }
766 
767 static void ich_read_data(uint8_t *data, int len)
768 {
769  int i;
770  uint32_t temp32 = 0;
771 
772  for (i = 0; i < len; i++) {
773  if ((i % 4) == 0)
774  temp32 = readl_(cntlr.data + i);
775 
776  data[i] = (temp32 >> ((i % 4) * 8)) & 0xff;
777  }
778 }
779 
780 static int ich_hwseq_read(const struct spi_flash *flash, u32 addr, size_t len,
781  void *buf)
782 {
783  uint16_t hsfc;
784  uint16_t timeout = 100 * 60;
785  uint8_t block_len;
786 
787  if (addr + len > flash->size) {
789  "Attempt to read %x-%x which is out of chip\n",
790  (unsigned int) addr,
791  (unsigned int) addr+(unsigned int) len);
792  return -1;
793  }
794 
795  /* clear FDONE, FCERR, AEL by writing 1 to them (if they are set) */
797 
798  while (len > 0) {
799  block_len = MIN(len, cntlr.databytes);
800  if (block_len > (~addr & 0xff))
801  block_len = (~addr & 0xff) + 1;
803  hsfc = readw_(&cntlr.ich9_spi->hsfc);
804  hsfc &= ~HSFC_FCYCLE; /* set read operation */
805  hsfc &= ~HSFC_FDBC; /* clear byte count */
806  /* set byte count */
807  hsfc |= (((block_len - 1) << HSFC_FDBC_OFF) & HSFC_FDBC);
808  hsfc |= HSFC_FGO; /* start */
809  writew_(hsfc, &cntlr.ich9_spi->hsfc);
810 
811  if (ich_hwseq_wait_for_cycle_complete(timeout, block_len))
812  return 1;
813  ich_read_data(buf, block_len);
814  addr += block_len;
815  buf += block_len;
816  len -= block_len;
817  }
818  return 0;
819 }
820 
821 /* Fill len bytes from the data array into the fdata/spid registers.
822  *
823  * Note that using len > flash->pgm->spi.max_data_write will trash the registers
824  * following the data registers.
825  */
826 static void ich_fill_data(const uint8_t *data, int len)
827 {
828  uint32_t temp32 = 0;
829  int i;
830 
831  if (len <= 0)
832  return;
833 
834  for (i = 0; i < len; i++) {
835  if ((i % 4) == 0)
836  temp32 = 0;
837 
838  temp32 |= ((uint32_t) data[i]) << ((i % 4) * 8);
839 
840  if ((i % 4) == 3) /* 32 bits are full, write them to regs. */
841  writel_(temp32, cntlr.data + (i - (i % 4)));
842  }
843  i--;
844  if ((i % 4) != 3) /* Write remaining data to regs. */
845  writel_(temp32, cntlr.data + (i - (i % 4)));
846 }
847 
848 static int ich_hwseq_write(const struct spi_flash *flash, u32 addr, size_t len,
849  const void *buf)
850 {
851  uint16_t hsfc;
852  uint16_t timeout = 100 * 60;
853  uint8_t block_len;
854  uint32_t start = addr;
855 
856  if (addr + len > flash->size) {
858  "Attempt to write 0x%x-0x%x which is out of chip\n",
859  (unsigned int)addr, (unsigned int) (addr+len));
860  return -1;
861  }
862 
863  /* clear FDONE, FCERR, AEL by writing 1 to them (if they are set) */
865 
866  while (len > 0) {
867  block_len = MIN(len, cntlr.databytes);
868  if (block_len > (~addr & 0xff))
869  block_len = (~addr & 0xff) + 1;
870 
872 
873  ich_fill_data(buf, block_len);
874  hsfc = readw_(&cntlr.ich9_spi->hsfc);
875  hsfc &= ~HSFC_FCYCLE; /* clear operation */
876  hsfc |= (0x2 << HSFC_FCYCLE_OFF); /* set write operation */
877  hsfc &= ~HSFC_FDBC; /* clear byte count */
878  /* set byte count */
879  hsfc |= (((block_len - 1) << HSFC_FDBC_OFF) & HSFC_FDBC);
880  hsfc |= HSFC_FGO; /* start */
881  writew_(hsfc, &cntlr.ich9_spi->hsfc);
882 
883  if (ich_hwseq_wait_for_cycle_complete(timeout, block_len)) {
884  printk(BIOS_ERR, "SF: write failure at %x\n",
885  addr);
886  return -1;
887  }
888  addr += block_len;
889  buf += block_len;
890  len -= block_len;
891  }
892  printk(BIOS_DEBUG, "SF: Successfully written %u bytes @ %#x\n",
893  (unsigned int) (addr - start), start);
894  return 0;
895 }
896 
897 static const struct spi_flash_ops spi_flash_ops = {
898  .read = ich_hwseq_read,
899  .write = ich_hwseq_write,
900  .erase = ich_hwseq_erase,
901 };
902 
903 static int spi_flash_programmer_probe(const struct spi_slave *spi,
904  struct spi_flash *flash)
905 {
906 
907  if (CONFIG(SOUTHBRIDGE_INTEL_I82801GX))
908  return spi_flash_generic_probe(spi, flash);
909 
910  /* Try generic probing first if spi_is_multichip returns 0. */
911  if (!spi_is_multichip() && !spi_flash_generic_probe(spi, flash))
912  return 0;
913 
914  memcpy(&flash->spi, spi, sizeof(*spi));
915 
917  switch ((cntlr.hsfs >> 3) & 3) {
918  case 0:
919  flash->sector_size = 256;
920  break;
921  case 1:
922  flash->sector_size = 4096;
923  break;
924  case 2:
925  flash->sector_size = 8192;
926  break;
927  case 3:
928  flash->sector_size = 65536;
929  break;
930  }
931 
932  flash->size = 1 << (19 + (cntlr.flcomp & 7));
933 
934  flash->ops = &spi_flash_ops;
935 
936  if ((cntlr.hsfs & HSFS_FDV) && ((cntlr.flmap0 >> 8) & 3))
937  flash->size += 1 << (19 + ((cntlr.flcomp >> 3) & 7));
938  printk(BIOS_DEBUG, "flash size 0x%x bytes\n", flash->size);
939 
940  return 0;
941 }
942 
943 static int xfer_vectors(const struct spi_slave *slave,
944  struct spi_op vectors[], size_t count)
945 {
947 }
948 
949 #define SPI_FPR_SHIFT 12
950 #define ICH7_SPI_FPR_MASK 0xfff
951 #define ICH9_SPI_FPR_MASK 0x1fff
952 #define SPI_FPR_BASE_SHIFT 0
953 #define ICH7_SPI_FPR_LIMIT_SHIFT 12
954 #define ICH9_SPI_FPR_LIMIT_SHIFT 16
955 #define ICH9_SPI_FPR_RPE (1 << 15) /* Read Protect */
956 #define SPI_FPR_WPE (1 << 31) /* Write Protect */
957 
958 static u32 spi_fpr(u32 base, u32 limit)
959 {
960  u32 ret;
961  u32 mask, limit_shift;
962 
963  if (CONFIG(SOUTHBRIDGE_INTEL_I82801GX)) {
965  limit_shift = ICH7_SPI_FPR_LIMIT_SHIFT;
966  } else {
968  limit_shift = ICH9_SPI_FPR_LIMIT_SHIFT;
969  }
970  ret = ((limit >> SPI_FPR_SHIFT) & mask) << limit_shift;
971  ret |= ((base >> SPI_FPR_SHIFT) & mask) << SPI_FPR_BASE_SHIFT;
972  return ret;
973 }
974 
975 /*
976  * Protect range of SPI flash defined by [start, start+size-1] using Flash
977  * Protected Range (FPR) register if available.
978  * Returns 0 on success, -1 on failure of programming fpr registers.
979  */
980 static int spi_flash_protect(const struct spi_flash *flash,
981  const struct region *region,
982  const enum ctrlr_prot_type type)
983 {
984  u32 start = region_offset(region);
985  u32 end = start + region_sz(region) - 1;
986  u32 reg;
987  u32 protect_mask = 0;
988  int fpr;
989  uint32_t *fpr_base;
990 
991  fpr_base = cntlr.fpr;
992 
993  /* Find first empty FPR */
994  for (fpr = 0; fpr < cntlr.fpr_max; fpr++) {
995  reg = read32(&fpr_base[fpr]);
996  if (reg == 0)
997  break;
998  }
999 
1000  if (fpr == cntlr.fpr_max) {
1001  printk(BIOS_ERR, "No SPI FPR free!\n");
1002  return -1;
1003  }
1004 
1005  switch (type) {
1006  case WRITE_PROTECT:
1007  protect_mask |= SPI_FPR_WPE;
1008  break;
1009  case READ_PROTECT:
1010  if (CONFIG(SOUTHBRIDGE_INTEL_I82801GX))
1011  return -1;
1012  protect_mask |= ICH9_SPI_FPR_RPE;
1013  break;
1014  case READ_WRITE_PROTECT:
1015  if (CONFIG(SOUTHBRIDGE_INTEL_I82801GX))
1016  return -1;
1017  protect_mask |= (ICH9_SPI_FPR_RPE | SPI_FPR_WPE);
1018  break;
1019  default:
1020  printk(BIOS_ERR, "Seeking invalid protection!\n");
1021  return -1;
1022  }
1023 
1024  /* Set protected range base and limit */
1025  reg = spi_fpr(start, end) | protect_mask;
1026 
1027  /* Set the FPR register and verify it is protected */
1028  write32(&fpr_base[fpr], reg);
1029  if (reg != read32(&fpr_base[fpr])) {
1030  printk(BIOS_ERR, "Unable to set SPI FPR %d\n", fpr);
1031  return -1;
1032  }
1033 
1034  printk(BIOS_INFO, "%s: FPR %d is enabled for range 0x%08x-0x%08x\n",
1035  __func__, fpr, start, end);
1036  return 0;
1037 }
1038 
1040 {
1041  u16 spi_opprefix;
1042  u16 optype = 0;
1043  struct intel_swseq_spi_config spi_config_default = {
1044  {0x06, 0x50}, /* OPPREFIXES: EWSR and WREN */
1045  { /* OPCODE and OPTYPE */
1046  {0x01, WRITE_NO_ADDR}, /* WRSR: Write Status Register */
1047  {0x02, WRITE_WITH_ADDR}, /* BYPR: Byte Program */
1048  {0x03, READ_WITH_ADDR}, /* READ: Read Data */
1049  {0x05, READ_NO_ADDR}, /* RDSR: Read Status Register */
1050  {0x20, WRITE_WITH_ADDR}, /* SE20: Sector Erase 0x20 */
1051  {0x9f, READ_NO_ADDR}, /* RDID: Read ID */
1052  {0xd8, WRITE_WITH_ADDR}, /* BED8: Block Erase 0xd8 */
1053  {0x0b, READ_WITH_ADDR}, /* FAST: Fast Read */
1054  }
1055  };
1056  struct intel_swseq_spi_config spi_config_aai_write = {
1057  {0x06, 0x50}, /* OPPREFIXES: EWSR and WREN */
1058  { /* OPCODE and OPTYPE */
1059  {0x01, WRITE_NO_ADDR}, /* WRSR: Write Status Register */
1060  {0x02, WRITE_WITH_ADDR}, /* BYPR: Byte Program */
1061  {0x03, READ_WITH_ADDR}, /* READ: Read Data */
1062  {0x05, READ_NO_ADDR}, /* RDSR: Read Status Register */
1063  {0x20, WRITE_WITH_ADDR}, /* SE20: Sector Erase 0x20 */
1064  {0x9f, READ_NO_ADDR}, /* RDID: Read ID */
1065  {0xad, WRITE_NO_ADDR}, /* Auto Address Increment Word Program */
1066  {0x04, WRITE_NO_ADDR} /* Write Disable */
1067  }
1068  };
1069  const struct spi_flash *flash = boot_device_spi_flash();
1070  struct intel_swseq_spi_config *spi_config = &spi_config_default;
1071  int i;
1072 
1073  /*
1074  * Some older SST SPI flashes support AAI write but use 0xaf opcde for
1075  * that. Flashrom uses the byte program opcode to write those flashes,
1076  * so this configuration is fine too. SST25VF064C (id = 0x4b) is an
1077  * exception.
1078  */
1079  if (flash && flash->vendor == VENDOR_ID_SST && (flash->model & 0x00ff) != 0x4b)
1080  spi_config = &spi_config_aai_write;
1081 
1082  if (spi_locked())
1083  return;
1084 
1086 
1087  spi_opprefix = spi_config->opprefixes[0]
1088  | (spi_config->opprefixes[1] << 8);
1089  writew_(spi_opprefix, cntlr.preop);
1090  for (i = 0; i < ARRAY_SIZE(spi_config->ops); i++) {
1091  optype |= (spi_config->ops[i].type & 3) << (i * 2);
1092  writeb_(spi_config->ops[i].op, &cntlr.opmenu[i]);
1093  }
1095 
1096  spi_set_smm_only_flashing(CONFIG(BOOTMEDIA_SMM_BWP));
1097 }
1098 
1100 {
1101 }
1102 
1103 #define BIOS_CNTL 0xdc
1104 #define BIOS_CNTL_BIOSWE (1 << 0)
1105 #define BIOS_CNTL_BLE (1 << 1)
1106 #define BIOS_CNTL_SMM_BWP (1 << 5)
1107 
1108 static void spi_set_smm_only_flashing(bool enable)
1109 {
1110  if (!(CONFIG(SOUTHBRIDGE_INTEL_I82801GX) || CONFIG(SOUTHBRIDGE_INTEL_COMMON_SPI_ICH9)))
1111  return;
1112 
1113  const pci_devfn_t dev = PCI_DEV(0, 31, 0);
1114 
1115  uint8_t bios_cntl = pci_read_config8(dev, BIOS_CNTL);
1116 
1117  if (enable) {
1118  bios_cntl &= ~BIOS_CNTL_BIOSWE;
1119  bios_cntl |= BIOS_CNTL_BLE | BIOS_CNTL_SMM_BWP;
1120  } else {
1121  bios_cntl &= ~(BIOS_CNTL_BLE | BIOS_CNTL_SMM_BWP);
1122  bios_cntl |= BIOS_CNTL_BIOSWE;
1123  }
1124 
1125  pci_write_config8(dev, BIOS_CNTL, bios_cntl);
1126 }
1127 
1128 static const struct spi_ctrlr spi_ctrlr = {
1130  .max_xfer_size = member_size(struct ich9_spi_regs, fdata),
1131  .flash_probe = spi_flash_programmer_probe,
1132  .flash_protect = spi_flash_protect,
1133 };
1134 
1135 const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
1136  {
1137  .ctrlr = &spi_ctrlr,
1138  .bus_start = 0,
1139  .bus_end = 0,
1140  },
1141 };
1142 
pte_t value
Definition: mmu.c:91
static void write8(void *addr, uint8_t val)
Definition: mmio.h:30
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint16_t read16(const void *addr)
Definition: mmio.h:17
static uint32_t read32(const void *addr)
Definition: mmio.h:22
static uint8_t read8(const void *addr)
Definition: mmio.h:12
static void write16(void *addr, uint16_t val)
Definition: mmio.h:35
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
const struct spi_flash * boot_device_spi_flash(void)
@ BS_DEV_INIT
Definition: bootstate.h:83
@ BS_ON_ENTRY
Definition: bootstate.h:95
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define MIN(a, b)
Definition: helpers.h:37
#define member_size(type, member)
Definition: helpers.h:92
static u32 addr
Definition: cirrus.c:14
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
static size_t offset
Definition: flashconsole.c:16
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
Definition: pci_ops.h:64
#define USECS_PER_MSEC
Definition: timer.h:10
unsigned int type
Definition: edid.c:57
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
static uint8_t * buf
Definition: uart.c:7
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
u32 pci_devfn_t
Definition: pci_type.h:8
static size_t region_sz(const struct region *r)
Definition: region.h:110
static size_t region_offset(const struct region *r)
Definition: region.h:105
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
uintptr_t base
Definition: uart.c:17
const struct spi_ctrlr_buses spi_ctrlr_bus_map[]
Definition: spi.c:401
void spi_init(void)
Init all SPI controllers with default values and enable all SPI controller.
Definition: spi.c:280
const size_t spi_ctrlr_bus_map_count
Definition: spi.c:408
static const int mask[4]
Definition: gpio.c:308
BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, spi_init_cb, NULL)
const struct spi_ctrlr spi_ctrlr
Definition: spi.c:261
#define SPI_FPR_BASE_SHIFT
Definition: spi.c:952
static void spi_use_in(spi_transaction *trans, unsigned int bytes)
Definition: spi.c:372
static const struct spi_flash_ops spi_flash_ops
Definition: spi.c:897
#define readb_(a)
Definition: spi.c:206
static int xfer_vectors(const struct spi_slave *slave, struct spi_op vectors[], size_t count)
Definition: spi.c:943
#define writel_(val, addr)
Definition: spi.c:211
static int ich_hwseq_wait_for_cycle_complete(unsigned int timeout, unsigned int len)
Definition: spi.c:679
static int spi_setup_offset(spi_transaction *trans)
Definition: spi.c:464
#define ICH9_SPI_FPR_RPE
Definition: spi.c:955
static int spi_is_multichip(void)
Definition: spi.c:511
static void spi_set_smm_only_flashing(bool enable)
Definition: spi.c:1108
static int spi_locked(void)
Definition: spi.c:340
#define BIOS_CNTL
Definition: spi.c:1103
#define ICH7_SPI_FPR_MASK
Definition: spi.c:950
#define SPI_FPR_WPE
Definition: spi.c:956
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin)
Definition: spi.c:518
#define readl_(a)
Definition: spi.c:208
static int ich_status_poll(u16 bitmask, int wait_til_set)
Definition: spi.c:491
static void spi_use_out(spi_transaction *trans, unsigned int bytes)
Definition: spi.c:366
static int spi_flash_programmer_probe(const struct spi_slave *spi, struct spi_flash *flash)
Definition: spi.c:903
#define BIOS_CNTL_BLE
Definition: spi.c:1105
static void ich_hwseq_set_addr(uint32_t addr)
Definition: spi.c:668
#define RCBA
Definition: spi.c:262
static int ich_hwseq_read(const struct spi_flash *flash, u32 addr, size_t len, void *buf)
Definition: spi.c:780
void spi_finalize_ops(void)
Definition: spi.c:1039
static int ich_hwseq_erase(const struct spi_flash *flash, u32 offset, size_t len)
Definition: spi.c:717
static void spi_init_cb(void *unused)
Definition: spi.c:349
struct ich7_spi_regs __packed
static u32 spi_fpr(u32 base, u32 limit)
Definition: spi.c:958
#define HSFC_FDBC_OFF
Definition: spi.c:25
#define HSFC_FCYCLE
Definition: spi.c:24
static void spi_setup_type(spi_transaction *trans)
Definition: spi.c:378
static struct ich_spi_controller cntlr
Definition: spi.c:102
@ SPIS_LOCK
Definition: spi.c:110
@ SPIS_GRANT
Definition: spi.c:106
@ SPIS_FCERR
Definition: spi.c:108
@ SSFS_AEL
Definition: spi.c:109
@ SPIS_CDS
Definition: spi.c:107
@ SSFS_RESERVED_MASK
Definition: spi.c:112
@ SPIS_SCIP
Definition: spi.c:105
@ SPIS_RESERVED_MASK
Definition: spi.c:111
static void write_reg(const void *value, void *dest, uint32_t size)
Definition: spi.c:215
static int spi_setup_opcode(spi_transaction *trans)
Definition: spi.c:412
@ SPI_OPCODE_TYPE_WRITE_NO_ADDRESS
Definition: spi.c:149
@ SPI_OPCODE_TYPE_READ_WITH_ADDRESS
Definition: spi.c:150
@ SPI_OPCODE_TYPE_READ_NO_ADDRESS
Definition: spi.c:148
@ SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS
Definition: spi.c:151
#define ICH9_SPI_FPR_LIMIT_SHIFT
Definition: spi.c:954
#define HSFC_FDBC
Definition: spi.c:26
@ SSFC_SCF_MASK
Definition: spi.c:122
@ SPIC_ACS
Definition: spi.c:117
@ SSFC_RESERVED
Definition: spi.c:123
@ SPIC_SPOP
Definition: spi.c:118
@ SPIC_SME
Definition: spi.c:121
@ SPIC_SCGO
Definition: spi.c:116
@ SPIC_DBC
Definition: spi.c:119
@ SPIC_DS
Definition: spi.c:120
static int spi_flash_protect(const struct spi_flash *flash, const struct region *region, const enum ctrlr_prot_type type)
Definition: spi.c:980
#define BIOS_CNTL_SMM_BWP
Definition: spi.c:1106
static void ich_read_data(uint8_t *data, int len)
Definition: spi.c:767
#define BIOS_CNTL_BIOSWE
Definition: spi.c:1104
#define SBASE
Definition: spi.c:263
@ HSFS_FDONE
Definition: spi.c:127
@ HSFS_BERASE_MASK
Definition: spi.c:130
@ HSFS_BERASE_SHIFT
Definition: spi.c:131
@ HSFS_AEL
Definition: spi.c:129
@ HSFS_FDOPSS
Definition: spi.c:133
@ HSFS_FLOCKDN
Definition: spi.c:135
@ HSFS_FCERR
Definition: spi.c:128
@ HSFS_FDV
Definition: spi.c:134
@ HSFS_SCIP
Definition: spi.c:132
@ HSFC_FSMIE
Definition: spi.c:144
@ HSFC_FDBC_MASK
Definition: spi.c:142
@ HSFC_FDBC_SHIFT
Definition: spi.c:143
@ HSFC_FCYCLE_MASK
Definition: spi.c:140
@ HSFC_FCYCLE_SHIFT
Definition: spi.c:141
@ HSFC_FGO
Definition: spi.c:139
#define readw_(a)
Definition: spi.c:207
static void * get_spi_bar(pci_devfn_t dev)
Definition: spi.c:265
#define writeb_(val, addr)
Definition: spi.c:209
static int ich_hwseq_write(const struct spi_flash *flash, u32 addr, size_t len, const void *buf)
Definition: spi.c:848
static void ich_set_bbar(uint32_t minaddr)
Definition: spi.c:245
static void read_reg(const void *src, void *value, uint32_t size)
Definition: spi.c:230
#define ICH7_SPI_FPR_LIMIT_SHIFT
Definition: spi.c:953
#define ICH9_SPI_FPR_MASK
Definition: spi.c:951
#define MENU_BYTES
Definition: spi.c:259
__weak void intel_southbridge_override_spi(struct intel_swseq_spi_config *spi_config)
Definition: spi.c:1099
#define writew_(val, addr)
Definition: spi.c:210
struct spi_transaction spi_transaction
static void ich_fill_data(const uint8_t *data, int len)
Definition: spi.c:826
#define HSFC_FCYCLE_OFF
Definition: spi.c:23
#define SPI_FPR_SHIFT
Definition: spi.c:949
optype
Definition: spi.h:7
@ WRITE_WITH_ADDR
Definition: spi.h:11
@ READ_WITH_ADDR
Definition: spi.h:10
@ READ_NO_ADDR
Definition: spi.h:8
@ WRITE_NO_ADDR
Definition: spi.h:9
int spi_claim_bus(const struct spi_slave *slave)
Definition: spi-generic.c:9
void spi_release_bus(const struct spi_slave *slave)
Definition: spi-generic.c:17
ctrlr_prot_type
Definition: spi-generic.h:106
@ WRITE_PROTECT
Definition: spi-generic.h:108
@ READ_WRITE_PROTECT
Definition: spi-generic.h:109
@ READ_PROTECT
Definition: spi-generic.h:107
#define VENDOR_ID_SST
Definition: spi-generic.h:25
int spi_flash_generic_probe(const struct spi_slave *spi, struct spi_flash *flash)
Definition: spi_flash.c:448
int spi_flash_vector_helper(const struct spi_slave *slave, struct spi_op vectors[], size_t count, int(*func)(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin))
Definition: spi_flash.c:745
#define SPI_OPCODE_FAST_READ
Definition: spi_flash.h:13
#define SPI_OPCODE_WREN
Definition: spi_flash.h:12
static struct spi_slave slave
Definition: spiconsole.c:7
#define NULL
Definition: stddef.h:19
signed short int16_t
Definition: stdint.h:10
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
uint16_t u16
Definition: stdint.h:48
unsigned long long uint64_t
Definition: stdint.h:17
uint8_t u8
Definition: stdint.h:45
unsigned char uint8_t
Definition: stdint.h:8
uint16_t optype
Definition: spi.c:40
uint64_t _pad
Definition: spi.c:37
uint32_t pbr[3]
Definition: spi.c:42
uint32_t bbar
Definition: spi.c:38
uint16_t preop
Definition: spi.c:39
uint16_t spis
Definition: spi.c:33
uint16_t spic
Definition: spi.c:34
uint32_t spia
Definition: spi.c:35
uint64_t spid[8]
Definition: spi.c:36
uint8_t opmenu[8]
Definition: spi.c:41
uint8_t _reserved4[8]
Definition: spi.c:66
uint32_t srd
Definition: spi.c:75
uint16_t hsfc
Definition: spi.c:48
uint8_t ssfc[3]
Definition: spi.c:58
uint32_t srdl
Definition: spi.c:73
uint32_t faddr
Definition: spi.c:49
uint16_t optype
Definition: spi.c:60
uint8_t ssfs
Definition: spi.c:57
uint32_t _reserved2[2]
Definition: spi.c:56
uint8_t _reserved5[4]
Definition: spi.c:70
uint32_t _reserved0
Definition: spi.c:50
uint8_t _reserved3[12]
Definition: spi.c:63
uint32_t bbar
Definition: spi.c:62
uint32_t afc
Definition: spi.c:67
uint32_t bfpr
Definition: spi.c:46
uint8_t opmenu[8]
Definition: spi.c:61
uint32_t _reserved1[3]
Definition: spi.c:54
uint32_t srdc
Definition: spi.c:74
uint32_t frap
Definition: spi.c:52
uint8_t _reserved6[28]
Definition: spi.c:72
uint32_t freg[5]
Definition: spi.c:53
uint32_t fpb
Definition: spi.c:71
uint16_t preop
Definition: spi.c:59
uint32_t lvscc
Definition: spi.c:68
uint32_t pr[5]
Definition: spi.c:55
uint32_t uvscc
Definition: spi.c:69
uint32_t fdod
Definition: spi.c:65
uint32_t fdata[16]
Definition: spi.c:51
uint32_t fdoc
Definition: spi.c:64
uint16_t hsfs
Definition: spi.c:47
uint8_t fpr_max
Definition: spi.c:99
uint32_t hsfs
Definition: spi.c:82
uint32_t * bbar
Definition: spi.c:97
int menubytes
Definition: spi.c:89
uint16_t * preop
Definition: spi.c:90
uint32_t flmap0
Definition: spi.c:80
uint16_t * optype
Definition: spi.c:91
uint8_t * opmenu
Definition: spi.c:88
uint8_t * data
Definition: spi.c:93
uint32_t flcomp
Definition: spi.c:81
struct ich7_spi_regs * ich7_spi
Definition: spi.c:86
uint8_t * status
Definition: spi.c:95
uint16_t * control
Definition: spi.c:96
uint32_t * fpr
Definition: spi.c:98
unsigned int databytes
Definition: spi.c:94
struct ich9_spi_regs * ich9_spi
Definition: spi.c:85
uint32_t * addr
Definition: spi.c:92
Definition: region.h:76
Definition: spi.h:77
const struct spi_ctrlr * ctrlr
Definition: spi-generic.h:175
int(* xfer_vector)(const struct spi_slave *slave, struct spi_op vectors[], size_t count)
Definition: spi-generic.h:154
int(* read)(const struct spi_flash *flash, u32 offset, size_t len, void *buf)
Definition: spi_flash.h:44
u8 vendor
Definition: spi_flash.h:85
u32 sector_size
Definition: spi_flash.h:96
const struct spi_flash_ops * ops
Definition: spi_flash.h:102
u16 model
Definition: spi_flash.h:94
u32 size
Definition: spi_flash.h:95
struct spi_slave spi
Definition: spi_flash.h:84
uint32_t bytesin
Definition: spi.c:360
uint8_t opcode
Definition: spi.c:362
const uint8_t * out
Definition: spi.c:357
uint32_t offset
Definition: spi.c:363
uint8_t type
Definition: spi.c:361
uint32_t bytesout
Definition: spi.c:358
uint8_t * in
Definition: spi.c:359
void udelay(uint32_t us)
Definition: udelay.c:15
#define count